Skip to content

Commit a7d15a2

Browse files
committed
nss: only read logging config from environment variables
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 systemd#22020.
1 parent 56a5f49 commit a7d15a2

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/basic/log.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,9 @@ static bool should_parse_proc_cmdline(void) {
11891189
return getpid_cached() == p;
11901190
}
11911191

1192-
void log_parse_environment(void) {
1192+
void log_parse_environment_variables(void) {
11931193
const char *e;
11941194

1195-
/* Do not call from library code. */
1196-
1197-
if (should_parse_proc_cmdline())
1198-
(void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
1199-
12001195
e = getenv("SYSTEMD_LOG_TARGET");
12011196
if (e && log_set_target_from_string(e) < 0)
12021197
log_warning("Failed to parse log target '%s'. Ignoring.", e);
@@ -1222,6 +1217,15 @@ void log_parse_environment(void) {
12221217
log_warning("Failed to parse log tid '%s'. Ignoring.", e);
12231218
}
12241219

1220+
void log_parse_environment(void) {
1221+
/* Do not call from library code. */
1222+
1223+
if (should_parse_proc_cmdline())
1224+
(void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
1225+
1226+
log_parse_environment_variables();
1227+
}
1228+
12251229
LogTarget log_get_target(void) {
12261230
return log_target;
12271231
}

src/basic/log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ int log_open(void);
8282
void log_close(void);
8383
void log_forget_fds(void);
8484

85+
void log_parse_environment_variables(void);
8586
void log_parse_environment(void);
8687

8788
int log_dispatch_internal(

src/nss-mymachines/nss-mymachines.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
static void setup_logging_once(void) {
2626
static pthread_once_t once = PTHREAD_ONCE_INIT;
27-
assert_se(pthread_once(&once, log_parse_environment) == 0);
27+
assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
2828
}
2929

3030
#define NSS_ENTRYPOINT_BEGIN \

src/nss-resolve/nss-resolve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
static JsonDispatchFlags json_dispatch_flags = 0;
2323

2424
static void setup_logging(void) {
25-
log_parse_environment();
25+
log_parse_environment_variables();
2626

2727
if (DEBUG_LOGGING)
2828
json_dispatch_flags = JSON_LOG;

src/nss-systemd/nss-systemd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static GetentData getsgent_data = {
118118

119119
static void setup_logging_once(void) {
120120
static pthread_once_t once = PTHREAD_ONCE_INIT;
121-
assert_se(pthread_once(&once, log_parse_environment) == 0);
121+
assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
122122
}
123123

124124
#define NSS_ENTRYPOINT_BEGIN \

0 commit comments

Comments
 (0)