Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ private static void AddSystemdLifetime(IServiceCollection services)
// systemd-style integration (for example, when NOTIFY_SOCKET is set or the process
// is detected as a systemd service).
#pragma warning disable CA1416 // Validate platform compatibility
services.AddSingleton<ISystemdNotifier, SystemdNotifier>();
services.AddSingleton<ISystemdNotifier>(_ =>
{
// Construct the notifier first so it reads (and normalizes) NOTIFY_SOCKET, then
// clear the env var so child processes don't inherit it and accidentally notify
// the parent's service manager. Done inside the DI factory so SystemdNotifier
// construction stays lazy and the env var is only mutated when hosting is
// actually wired up.
var notifier = new SystemdNotifier();
Environment.SetEnvironmentVariable(SystemdConstants.NotifySocket, null);
return notifier;
});
services.AddSingleton<IHostLifetime, SystemdLifetime>();
#pragma warning restore CA1416 // Validate platform compatibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public void Notify(ServiceState state)
return null;
}

// Because this method is called on Notifier construction, the envvar is cleared when the Host is built
// (IHostLifetime depends on ISystemdNotifier). This prevents child processes from inheriting the socket
// and interfering with service manager notifications.
Environment.SetEnvironmentVariable(SystemdConstants.NotifySocket, null);

// Support abstract socket paths.
if (socketPath[0] == '@')
{
Expand Down
Loading