main: initialize default unit little later (#4321)

systemd fills arg_default_unit during startup with default.target
value. But arg_default_unit may be overwritten in parse_argv() or
parse_proc_cmdline_item().

Let's check value of arg_default_unit after calls of parse_argv()
and parse_proc_cmdline_item() and fill it with default.target if
it wasn't filled before. In this way we will not spend unnecessary
time to for filling arg_default_unit with default.target.
This commit is contained in:
0xAX
2016-10-09 22:57:03 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent 9fc932bff1
commit 10c961b9c9
+10 -8
View File
@@ -1536,14 +1536,6 @@ int main(int argc, char *argv[]) {
log_warning_errno(errno, "Failed to redirect standard streams to /dev/null: %m");
}
/* Initialize default unit */
r = free_and_strdup(&arg_default_unit, SPECIAL_DEFAULT_TARGET);
if (r < 0) {
log_emergency_errno(r, "Failed to set default unit %s: %m", SPECIAL_DEFAULT_TARGET);
error_message = "Failed to set default unit";
goto finish;
}
r = initialize_join_controllers();
if (r < 0) {
error_message = "Failed to initialize cgroup controllers";
@@ -1591,6 +1583,16 @@ int main(int argc, char *argv[]) {
goto finish;
}
/* Initialize default unit */
if (!arg_default_unit) {
r = free_and_strdup(&arg_default_unit, SPECIAL_DEFAULT_TARGET);
if (r < 0) {
log_emergency_errno(r, "Failed to set default unit %s: %m", SPECIAL_DEFAULT_TARGET);
error_message = "Failed to set default unit";
goto finish;
}
}
if (arg_action == ACTION_TEST &&
geteuid() == 0) {
log_error("Don't run test mode as root.");