]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nss: only read logging config from environment variables 22086/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 11 Jan 2022 12:36:39 +0000 (13:36 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 11 Jan 2022 12:39:52 +0000 (13:39 +0100)
log_parse_environment() uses should_parse_proc_cmdline() to determine whether
it should parse settings from the kernel command line. But the checks that
should_parse_proc_cmdline() apply to the whole process, and we could get a positive
answer also when log_parse_environment() was called from one of the nss modules.
In case of nss-modules, we don't want to look at the kernel command line.

log_parse_environment_variables() that only looks at the environment variables
is split out and used in the nss modules.

Fixes #22020.

src/basic/log.c
src/basic/log.h
src/nss-mymachines/nss-mymachines.c
src/nss-resolve/nss-resolve.c
src/nss-systemd/nss-systemd.c

index 7bc2f280073b0b64682c679f0ea73beefabba725..12071e2ebd3e6edc8639f00e32a4218163c940f9 100644 (file)
@@ -1189,14 +1189,9 @@ static bool should_parse_proc_cmdline(void) {
         return getpid_cached() == p;
 }
 
-void log_parse_environment(void) {
+void log_parse_environment_variables(void) {
         const char *e;
 
-        /* Do not call from library code. */
-
-        if (should_parse_proc_cmdline())
-                (void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
-
         e = getenv("SYSTEMD_LOG_TARGET");
         if (e && log_set_target_from_string(e) < 0)
                 log_warning("Failed to parse log target '%s'. Ignoring.", e);
@@ -1222,6 +1217,15 @@ void log_parse_environment(void) {
                 log_warning("Failed to parse log tid '%s'. Ignoring.", e);
 }
 
+void log_parse_environment(void) {
+        /* Do not call from library code. */
+
+        if (should_parse_proc_cmdline())
+                (void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
+
+        log_parse_environment_variables();
+}
+
 LogTarget log_get_target(void) {
         return log_target;
 }
index 7218b4bf718f6e9080ca2bbb4e4064ab4f03dea7..1e2bec16468cbc3614b9bb0955cfdeb7c903c293 100644 (file)
@@ -82,6 +82,7 @@ int log_open(void);
 void log_close(void);
 void log_forget_fds(void);
 
+void log_parse_environment_variables(void);
 void log_parse_environment(void);
 
 int log_dispatch_internal(
index 781fd48d72ed7f48c1b2661aa4baf8e7d0b113ee..c64e79bdff8983d732d0e89c0d368203f3506094 100644 (file)
@@ -24,7 +24,7 @@
 
 static void setup_logging_once(void) {
         static pthread_once_t once = PTHREAD_ONCE_INIT;
-        assert_se(pthread_once(&once, log_parse_environment) == 0);
+        assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
 }
 
 #define NSS_ENTRYPOINT_BEGIN                    \
index 6b0c762d0320d79eb1ec7e25b0b6b8fdb8e326ee..e857d42db68186d43917325c3859625a5243bff2 100644 (file)
@@ -22,7 +22,7 @@
 static JsonDispatchFlags json_dispatch_flags = 0;
 
 static void setup_logging(void) {
-        log_parse_environment();
+        log_parse_environment_variables();
 
         if (DEBUG_LOGGING)
                 json_dispatch_flags = JSON_LOG;
index c6c00c40e648d28ac213201be960e0f26458a4f2..e87f1d31b3401e94ab141bb5c9ffdb91a8ebe2fc 100644 (file)
@@ -118,7 +118,7 @@ static GetentData getsgent_data = {
 
 static void setup_logging_once(void) {
         static pthread_once_t once = PTHREAD_ONCE_INIT;
-        assert_se(pthread_once(&once, log_parse_environment) == 0);
+        assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
 }
 
 #define NSS_ENTRYPOINT_BEGIN                    \