From 3196e423931666511b24c701fb382416af5dc709 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Aug 2020 17:45:33 +0200 Subject: [PATCH 1/2] core: merge a few if blocks arg_system == true and getpid() == 1 hold under the very same condition this early in the main() function (this only changes later when we start parsing command lines, where arg_system = true is set if users invoke us in test mode even when getpid() != 1. Hence, let's simplify things, and merge a couple of if branches and not pretend they were orthogonal. --- src/core/main.c | 56 ++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 4a376976e9..8d53c0bf85 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2653,6 +2653,31 @@ int main(int argc, char *argv[]) { goto finish; } + /* Try to figure out if we can use colors with the console. No need to do that for user instances since + * they never log into the console. */ + log_show_color(colors_enabled()); + + r = make_null_stdio(); + if (r < 0) + log_warning_errno(r, "Failed to redirect standard streams to /dev/null, ignoring: %m"); + + /* Load the kernel modules early. */ + if (!skip_setup) + kmod_setup(); + + /* Mount /proc, /sys and friends, so that /proc/cmdline and /proc/$PID/fd is available. */ + r = mount_setup(loaded_policy, skip_setup); + if (r < 0) { + error_message = "Failed to mount API filesystems"; + goto finish; + } + + /* The efivarfs is now mounted, let's read the random seed off it */ + (void) efi_take_random_seed(); + + /* Cache command-line options passed from EFI variables */ + if (!skip_setup) + (void) cache_efi_options_variable(); } else { /* Running as user instance */ arg_system = false; @@ -2668,37 +2693,6 @@ int main(int argc, char *argv[]) { } } - if (arg_system) { - /* Try to figure out if we can use colors with the console. No need to do that for user instances since - * they never log into the console. */ - log_show_color(colors_enabled()); - - r = make_null_stdio(); - if (r < 0) - log_warning_errno(r, "Failed to redirect standard streams to /dev/null, ignoring: %m"); - } - - /* Mount /proc, /sys and friends, so that /proc/cmdline and /proc/$PID/fd is available. */ - if (getpid_cached() == 1) { - - /* Load the kernel modules early. */ - if (!skip_setup) - kmod_setup(); - - r = mount_setup(loaded_policy, skip_setup); - if (r < 0) { - error_message = "Failed to mount API filesystems"; - goto finish; - } - - /* The efivarfs is now mounted, let's read the random seed off it */ - (void) efi_take_random_seed(); - - /* Cache command-line options passed from EFI variables */ - if (!skip_setup) - (void) cache_efi_options_variable(); - } - /* Save the original RLIMIT_NOFILE/RLIMIT_MEMLOCK so that we can reset it later when * transitioning from the initrd to the main systemd or suchlike. */ save_rlimits(&saved_rlimit_nofile, &saved_rlimit_memlock); From 4428c49db9399f003f0677590531d6a84c0f51ca Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Aug 2020 17:47:32 +0200 Subject: [PATCH 2/2] mount-setup: drop pointless zero initialization --- src/core/mount-setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index feb88f3e6e..7df1562c8a 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -480,7 +480,7 @@ static int relabel_extra(void) { #endif int mount_setup(bool loaded_policy, bool leave_propagation) { - int r = 0; + int r; r = mount_points_setup(ELEMENTSOF(mount_table), loaded_policy); if (r < 0)