From c792a2e5db633b44aa63231232db7afbea0842a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Feb 2023 10:15:35 +0100 Subject: [PATCH 1/2] manager: be more careful with env var clean-up Let's add some more env vars we nowadays set for activated services to the list of env vars we strip from the environment block we pass on. --- src/core/manager.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index 380a4e30d7..5c8c417dae 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -635,8 +635,14 @@ static char** sanitize_environment(char **l) { "LISTEN_FDS", "LISTEN_PID", "LOGS_DIRECTORY", + "LOG_NAMESPACE", "MAINPID", "MANAGERPID", + "MONITOR_EXIT_CODE", + "MONITOR_EXIT_STATUS", + "MONITOR_INVOCATION_ID", + "MONITOR_SERVICE_RESULT", + "MONITOR_UNIT", "NOTIFY_SOCKET", "PIDFILE", "REMOTE_ADDR", @@ -644,6 +650,11 @@ static char** sanitize_environment(char **l) { "RUNTIME_DIRECTORY", "SERVICE_RESULT", "STATE_DIRECTORY", + "SYSTEMD_EXEC_PID", + "TRIGGER_PATH", + "TRIGGER_TIMER_MONOTONIC_USEC", + "TRIGGER_TIMER_REALTIME_USEC", + "TRIGGER_UNIT", "WATCHDOG_PID", "WATCHDOG_USEC", NULL); @@ -660,13 +671,11 @@ int manager_default_environment(Manager *m) { m->transient_environment = strv_free(m->transient_environment); if (MANAGER_IS_SYSTEM(m)) { - /* The system manager always starts with a clean - * environment for its children. It does not import - * the kernel's or the parents' exported variables. + /* The system manager always starts with a clean environment for its children. It does not + * import the kernel's or the parents' exported variables. * - * The initial passed environment is untouched to keep - * /proc/self/environ valid; it is used for tagging - * the init process inside containers. */ + * The initial passed environment is untouched to keep /proc/self/environ valid; it is used + * for tagging the init process inside containers. */ m->transient_environment = strv_new("PATH=" DEFAULT_PATH); if (!m->transient_environment) return log_oom(); @@ -685,7 +694,6 @@ int manager_default_environment(Manager *m) { } sanitize_environment(m->transient_environment); - return 0; } From e7a2594219a6aaa47cee850f6f1b86e7280713eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Feb 2023 10:21:49 +0100 Subject: [PATCH 2/2] man: document REMOTE_ADDR/REMOTE_PORT along with the other env vars --- man/systemd.exec.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index daa2a595f0..e696941682 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -3755,6 +3755,15 @@ StandardInputData=V2XigLJyZSBubyBzdHJhbmdlcnMgdG8gbG92ZQpZb3Uga25vdyB0aGUgcnVsZX system. + + $REMOTE_ADDR + $REMOTE_PORT + + If this is a unit started via per-connection socket activation (i.e. via a socket + unit with Accept=yes), these environment variables contain the IP address and + port number of the remote peer of the socket connection. + + $TRIGGER_UNIT $TRIGGER_PATH