manager: skip reopening of console and signal reset when running as normal program
We want to reopen the console used for logging when running as PID1, but also when running a user manager (c.f.48a601fe5dand2a646b1d62). But this can cause problems when the binary is invoked directly, e.g. to print --help. E.g. if we ignore SIGPIPE, we'd remain running briefly after '/usr/lib/systemd/systemd --help | head -n1'. Previusly, the getopt machinery would print to stderr unconditionally. But after the rework of option parsing, which means that we use the log_* functions to repor errors, the test that checks if we print errors to stderr started failing. So let's skip some more of the setup if !invoked_by_systemd().
This commit is contained in:
+10
-4
@@ -3273,15 +3273,19 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/* The efivarfs is now mounted, let's lock down the system token. */
|
||||
lock_down_efi_variables();
|
||||
|
||||
} else {
|
||||
/* Running as user instance */
|
||||
arg_runtime_scope = RUNTIME_SCOPE_USER;
|
||||
log_set_always_reopen_console(true);
|
||||
log_set_target_and_open(LOG_TARGET_AUTO);
|
||||
|
||||
/* clear the kernel timestamp, because we are not PID 1 */
|
||||
kernel_timestamp = DUAL_TIMESTAMP_NULL;
|
||||
|
||||
if (invoked_by_systemd()) {
|
||||
log_set_always_reopen_console(true);
|
||||
log_set_target_and_open(LOG_TARGET_AUTO);
|
||||
}
|
||||
|
||||
r = mac_init();
|
||||
if (r < 0) {
|
||||
error_message = "Failed to initialize MAC support";
|
||||
@@ -3293,9 +3297,11 @@ int main(int argc, char *argv[]) {
|
||||
* transitioning from the initrd to the main systemd or suchlike. */
|
||||
save_rlimits(&saved_rlimit_nofile, &saved_rlimit_memlock);
|
||||
|
||||
/* Reset all signal handlers. */
|
||||
/* Reset all signal handlers to clean up after reexec. */
|
||||
(void) reset_all_signal_handlers();
|
||||
(void) ignore_signals(SIGNALS_IGNORE);
|
||||
|
||||
if (getpid_cached() == 1 || invoked_by_systemd())
|
||||
(void) ignore_signals(SIGNALS_IGNORE);
|
||||
|
||||
(void) parse_configuration(&saved_rlimit_nofile, &saved_rlimit_memlock);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user