core: delete redundant log_parse_environment()

Fixes https://github.com/systemd/systemd/issues/38895.

Fix the confusing behavior where when an incorrect configuration item such as
'ManagerEnvironment=SYSTEMD_LOG_LEVEL=' is set, the first daemon-reload uses
old environment variables while the second daemon-reload uses LogLevel=.

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>

The difference in behaviour is that the operations that were done between the
first log_parse_environment() and the second one might not be logged now, e.g.
if the environment enabled debug logging. That is unfortunate, but parsing the
environment twice and not having the explicit configuration take effect until a
second daemon-reload is confusing. We will always have some window where the
configuration for logging does not apply, in particular this must be true when
parsing the logging configuration. To make that window smaller, move operations
that could log after the call to log_parse_environment() as far as possible.
This commit is contained in:
huyubiao
2025-09-30 15:26:43 +08:00
committed by Zbigniew Jędrzejewski-Szmek
parent 938f7fea7c
commit 8f2c5dea63

View File

@@ -2810,26 +2810,24 @@ static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
}
/* Initialize some default rlimits for services if they haven't been configured */
fallback_rlimit_nofile(saved_rlimit_nofile);
fallback_rlimit_memlock(saved_rlimit_memlock);
/* Note that this also parses bits from the kernel command line, including "debug". */
log_parse_environment();
/* Initialize the show status setting if it hasn't been set explicitly yet */
/* Initialize the show status setting if it hasn't been explicitly set yet */
if (arg_show_status == _SHOW_STATUS_INVALID)
arg_show_status = SHOW_STATUS_YES;
/* Slightly raise the OOM score for our services if we are running for unprivileged users. */
determine_default_oom_score_adjust();
/* Push variables into the manager environment block */
setenv_manager_environment();
/* Parse log environment variables again to take into account any new environment variables. */
/* Parse log environment variables to take into account any new environment variables.
* Note that this also parses bits from the kernel command line, including "debug". */
log_parse_environment();
/* Initialize some default rlimits for services if they haven't been configured */
fallback_rlimit_nofile(saved_rlimit_nofile);
fallback_rlimit_memlock(saved_rlimit_memlock);
/* Slightly raise the OOM score for our services if we are running for unprivileged users. */
determine_default_oom_score_adjust();
return 0;
}