diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-01-17 06:52:22 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-01-31 17:13:44 +0100 |
commit | 74189020eb2ec05336d93bdeeffbda1724ba1e07 (patch) | |
tree | 03cabb071e5083b00299842bdc1562270ad4c3cc /src/basic/log.c | |
parent | network: drop one more link_dirty() (diff) | |
download | systemd-74189020eb2ec05336d93bdeeffbda1724ba1e07.tar.xz systemd-74189020eb2ec05336d93bdeeffbda1724ba1e07.zip |
log: make tools also read the kernel command line when run as a service
This effectively reverts 41d1f469cf10f5f3e9cb4f4853ace9b0cfe5beae.
Before this, e.g., `networkctl reload` invoked by `systemctl reload systemd-networkd.service`
does not produce debugging logs even if systemd.log-level=debug is set. This fixes
the issue.
Diffstat (limited to 'src/basic/log.c')
-rw-r--r-- | src/basic/log.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/basic/log.c b/src/basic/log.c index 59181910eb..4163f2e8d9 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -1158,20 +1158,16 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat } void log_parse_environment(void) { + const char *e; + + /* Do not call from library code. */ + if (getpid_cached() == 1 || get_ctty_devnr(0, NULL) < 0) /* Only try to read the command line in daemons. We assume that anything that has a * controlling tty is user stuff. For PID1 we do a special check in case it hasn't * closed the console yet. */ (void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX); - log_parse_environment_cli(); -} - -void log_parse_environment_cli(void) { - /* Do not call from library code. */ - - const char *e; - e = getenv("SYSTEMD_LOG_TARGET"); if (e && log_set_target_from_string(e) < 0) log_warning("Failed to parse log target '%s'. Ignoring.", e); @@ -1474,7 +1470,7 @@ void log_setup_cli(void) { /* Sets up logging the way it is most appropriate for running a program as a CLI utility. */ log_set_target(LOG_TARGET_AUTO); - log_parse_environment_cli(); + log_parse_environment(); (void) log_open(); if (log_on_console() && show_color < 0) log_show_color(true); |