1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <dbus/dbus.h>
28 #include <sys/types.h>
37 #include "mount-setup.h"
38 #include "hostname-setup.h"
39 #include "loopback-setup.h"
40 #include "kmod-setup.h"
41 #include "modprobe-setup.h"
42 #include "load-fragment.h"
45 #include "conf-parser.h"
46 #include "bus-errors.h"
53 ACTION_DUMP_CONFIGURATION_ITEMS
,
55 } arg_action
= ACTION_RUN
;
57 static char *arg_default_unit
= NULL
;
58 static ManagerRunningAs arg_running_as
= _MANAGER_RUNNING_AS_INVALID
;
60 static bool arg_dump_core
= true;
61 static bool arg_crash_shell
= false;
62 static int arg_crash_chvt
= -1;
63 static bool arg_confirm_spawn
= false;
64 static bool arg_nomodules
= false;
65 static bool arg_show_status
= true;
67 static FILE* serialization
= NULL
;
69 _noreturn_
static void freeze(void) {
74 static void nop_handler(int sig
) {
77 _noreturn_
static void crash(int sig
) {
80 log_error("Caught <%s>, not dumping core.", signal_to_string(sig
));
85 /* We want to wait for the core process, hence let's enable SIGCHLD */
87 sa
.sa_handler
= nop_handler
;
88 sa
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
89 assert_se(sigaction(SIGCHLD
, &sa
, NULL
) == 0);
91 if ((pid
= fork()) < 0)
92 log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig
), strerror(errno
));
97 /* Enable default signal handler for core dump */
99 sa
.sa_handler
= SIG_DFL
;
100 assert_se(sigaction(sig
, &sa
, NULL
) == 0);
102 /* Don't limit the core dump size */
104 rl
.rlim_cur
= RLIM_INFINITY
;
105 rl
.rlim_max
= RLIM_INFINITY
;
106 setrlimit(RLIMIT_CORE
, &rl
);
108 /* Just to be sure... */
109 assert_se(chdir("/") == 0);
111 /* Raise the signal again */
114 assert_not_reached("We shouldn't be here...");
120 /* Order things nicely. */
121 if ((r
= waitpid(pid
, &status
, 0)) < 0)
122 log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig
), strerror(errno
));
123 else if (!WCOREDUMP(status
))
124 log_error("Caught <%s>, core dump failed.", signal_to_string(sig
));
126 log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig
), (unsigned long) pid
);
131 chvt(arg_crash_chvt
);
133 if (arg_crash_shell
) {
137 log_info("Executing crash shell in 10s...");
140 /* Let the kernel reap children for us */
142 sa
.sa_handler
= SIG_IGN
;
143 sa
.sa_flags
= SA_NOCLDSTOP
|SA_NOCLDWAIT
|SA_RESTART
;
144 assert_se(sigaction(SIGCHLD
, &sa
, NULL
) == 0);
146 if ((pid
= fork()) < 0)
147 log_error("Failed to fork off crash shell: %s", strerror(errno
));
151 if ((fd
= acquire_terminal("/dev/console", false, true, true)) < 0)
152 log_error("Failed to acquire terminal: %s", strerror(-fd
));
153 else if ((r
= make_stdio(fd
)) < 0)
154 log_error("Failed to duplicate terminal fd: %s", strerror(-r
));
156 execl("/bin/sh", "/bin/sh", NULL
);
158 log_error("execl() failed: %s", strerror(errno
));
162 log_info("Successfully spawned crash shall as pid %lu.", (unsigned long) pid
);
165 log_info("Freezing execution.");
169 static void install_crash_handler(void) {
174 sa
.sa_handler
= crash
;
175 sa
.sa_flags
= SA_NODEFER
;
177 sigaction_many(&sa
, SIGNALS_CRASH_HANDLER
, -1);
180 static int make_null_stdio(void) {
183 if ((null_fd
= open("/dev/null", O_RDWR
|O_NOCTTY
)) < 0) {
184 log_error("Failed to open /dev/null: %m");
188 if ((r
= make_stdio(null_fd
)) < 0)
189 log_warning("Failed to dup2() device: %s", strerror(-r
));
194 static int console_setup(bool do_reset
) {
197 /* If we are init, we connect stdin/stdout/stderr to /dev/null
198 * and make sure we don't have a controlling tty. */
205 if ((tty_fd
= open_terminal("/dev/console", O_WRONLY
|O_NOCTTY
|O_CLOEXEC
)) < 0) {
206 log_error("Failed to open /dev/console: %s", strerror(-tty_fd
));
210 if ((r
= reset_terminal(tty_fd
)) < 0)
211 log_error("Failed to reset /dev/console: %s", strerror(-r
));
213 close_nointr_nofail(tty_fd
);
217 static int set_default_unit(const char *u
) {
222 if (!(c
= strdup(u
)))
225 free(arg_default_unit
);
226 arg_default_unit
= c
;
230 static int parse_proc_cmdline_word(const char *word
) {
232 static const char * const rlmap
[] = {
233 "single", SPECIAL_RESCUE_TARGET
,
234 "-s", SPECIAL_RESCUE_TARGET
,
235 "s", SPECIAL_RESCUE_TARGET
,
236 "S", SPECIAL_RESCUE_TARGET
,
237 "1", SPECIAL_RESCUE_TARGET
,
238 "2", SPECIAL_RUNLEVEL2_TARGET
,
239 "3", SPECIAL_RUNLEVEL3_TARGET
,
240 "4", SPECIAL_RUNLEVEL4_TARGET
,
241 "5", SPECIAL_RUNLEVEL5_TARGET
243 bool ignore_quiet
= false;
245 if (startswith(word
, "systemd.unit="))
246 return set_default_unit(word
+ 13);
248 else if (startswith(word
, "systemd.log_target=")) {
250 if (log_set_target_from_string(word
+ 19) < 0)
251 log_warning("Failed to parse log target %s. Ignoring.", word
+ 19);
253 } else if (startswith(word
, "systemd.log_level=")) {
255 if (log_set_max_level_from_string(word
+ 18) < 0)
256 log_warning("Failed to parse log level %s. Ignoring.", word
+ 18);
258 } else if (startswith(word
, "systemd.log_color=")) {
260 if (log_show_color_from_string(word
+ 18) < 0)
261 log_warning("Failed to parse log color setting %s. Ignoring.", word
+ 18);
263 } else if (startswith(word
, "systemd.log_location=")) {
265 if (log_show_location_from_string(word
+ 21) < 0)
266 log_warning("Failed to parse log location setting %s. Ignoring.", word
+ 21);
268 } else if (startswith(word
, "systemd.dump_core=")) {
271 if ((r
= parse_boolean(word
+ 18)) < 0)
272 log_warning("Failed to parse dump core switch %s, Ignoring.", word
+ 18);
276 } else if (startswith(word
, "systemd.crash_shell=")) {
279 if ((r
= parse_boolean(word
+ 20)) < 0)
280 log_warning("Failed to parse crash shell switch %s, Ignoring.", word
+ 20);
284 } else if (startswith(word
, "systemd.confirm_spawn=")) {
287 if ((r
= parse_boolean(word
+ 22)) < 0)
288 log_warning("Failed to parse confirm spawn switch %s, Ignoring.", word
+ 22);
290 arg_confirm_spawn
= r
;
292 } else if (startswith(word
, "systemd.crash_chvt=")) {
295 if (safe_atoi(word
+ 19, &k
) < 0)
296 log_warning("Failed to parse crash chvt switch %s, Ignoring.", word
+ 19);
300 } else if (startswith(word
, "systemd.show_status=")) {
303 if ((r
= parse_boolean(word
+ 20)) < 0)
304 log_warning("Failed to parse show status switch %s, Ignoring.", word
+ 20);
310 } else if (startswith(word
, "systemd.")) {
312 log_warning("Unknown kernel switch %s. Ignoring.", word
);
314 log_info("Supported kernel switches:\n"
315 "systemd.unit=UNIT Default unit to start\n"
316 "systemd.log_target=console|kmsg|syslog| Log target\n"
317 " syslog-org-kmsg|null\n"
318 "systemd.log_level=LEVEL Log level\n"
319 "systemd.log_color=0|1 Highlight important log messages\n"
320 "systemd.log_location=0|1 Include code location in log messages\n"
321 "systemd.dump_core=0|1 Dump core on crash\n"
322 "systemd.crash_shell=0|1 Run shell on crash\n"
323 "systemd.crash_chvt=N Change to VT #N on crash\n"
324 "systemd.confirm_spawn=0|1 Confirm every process spawn\n"
325 "systemd.show_status=0|1 Show status updates on the console during bootup\n");
327 } else if (streq(word
, "nomodules"))
328 arg_nomodules
= true;
329 else if (streq(word
, "quiet")) {
331 arg_show_status
= false;
335 /* SysV compatibility */
336 for (i
= 0; i
< ELEMENTSOF(rlmap
); i
+= 2)
337 if (streq(word
, rlmap
[i
]))
338 return set_default_unit(rlmap
[i
+1]);
344 static int config_parse_level(
345 const char *filename
,
357 log_set_max_level_from_string(rvalue
);
361 static int config_parse_target(
362 const char *filename
,
374 log_set_target_from_string(rvalue
);
378 static int config_parse_color(
379 const char *filename
,
391 log_show_color_from_string(rvalue
);
395 static int config_parse_location(
396 const char *filename
,
408 log_show_location_from_string(rvalue
);
412 static int config_parse_cpu_affinity(
413 const char *filename
,
431 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
436 if (!(t
= strndup(w
, l
)))
439 r
= safe_atou(t
, &cpu
);
443 if (!(c
= cpu_set_malloc(&ncpus
)))
446 if (r
< 0 || cpu
>= ncpus
) {
447 log_error("[%s:%u] Failed to parse CPU affinity: %s", filename
, line
, rvalue
);
452 CPU_SET_S(cpu
, CPU_ALLOC_SIZE(ncpus
), c
);
456 if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus
), c
) < 0)
457 log_warning("Failed to set CPU affinity: %m");
465 static int parse_config_file(void) {
467 const ConfigItem items
[] = {
468 { "LogLevel", config_parse_level
, NULL
, "Manager" },
469 { "LogTarget", config_parse_target
, NULL
, "Manager" },
470 { "LogColor", config_parse_color
, NULL
, "Manager" },
471 { "LogLocation", config_parse_location
, NULL
, "Manager" },
472 { "DumpCore", config_parse_bool
, &arg_dump_core
, "Manager" },
473 { "CrashShell", config_parse_bool
, &arg_crash_shell
, "Manager" },
474 { "ShowStatus", config_parse_bool
, &arg_show_status
, "Manager" },
475 { "CrashChVT", config_parse_int
, &arg_crash_chvt
, "Manager" },
476 { "CPUAffinity", config_parse_cpu_affinity
, NULL
, "Manager" },
477 { NULL
, NULL
, NULL
, NULL
}
480 static const char * const sections
[] = {
489 fn
= arg_running_as
== MANAGER_SYSTEM
? SYSTEM_CONFIG_FILE
: SESSION_CONFIG_FILE
;
491 if (!(f
= fopen(fn
, "re"))) {
495 log_warning("Failed to open configuration file '%s': %m", fn
);
499 if ((r
= config_parse(fn
, f
, sections
, items
, false, NULL
)) < 0)
500 log_warning("Failed to parse configuration file: %s", strerror(-r
));
507 static int parse_proc_cmdline(void) {
514 if ((r
= read_one_line_file("/proc/cmdline", &line
)) < 0) {
515 log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(errno
));
519 FOREACH_WORD_QUOTED(w
, l
, line
, state
) {
522 if (!(word
= strndup(w
, l
))) {
527 r
= parse_proc_cmdline_word(word
);
541 static int parse_argv(int argc
, char *argv
[]) {
544 ARG_LOG_LEVEL
= 0x100,
552 ARG_DUMP_CONFIGURATION_ITEMS
,
561 static const struct option options
[] = {
562 { "log-level", required_argument
, NULL
, ARG_LOG_LEVEL
},
563 { "log-target", required_argument
, NULL
, ARG_LOG_TARGET
},
564 { "log-color", optional_argument
, NULL
, ARG_LOG_COLOR
},
565 { "log-location", optional_argument
, NULL
, ARG_LOG_LOCATION
},
566 { "unit", required_argument
, NULL
, ARG_UNIT
},
567 { "system", no_argument
, NULL
, ARG_SYSTEM
},
568 { "session", no_argument
, NULL
, ARG_SESSION
},
569 { "test", no_argument
, NULL
, ARG_TEST
},
570 { "help", no_argument
, NULL
, 'h' },
571 { "dump-configuration-items", no_argument
, NULL
, ARG_DUMP_CONFIGURATION_ITEMS
},
572 { "dump-core", no_argument
, NULL
, ARG_DUMP_CORE
},
573 { "crash-shell", no_argument
, NULL
, ARG_CRASH_SHELL
},
574 { "confirm-spawn", no_argument
, NULL
, ARG_CONFIRM_SPAWN
},
575 { "show-status", no_argument
, NULL
, ARG_SHOW_STATUS
},
576 { "deserialize", required_argument
, NULL
, ARG_DESERIALIZE
},
577 { "introspect", optional_argument
, NULL
, ARG_INTROSPECT
},
586 while ((c
= getopt_long(argc
, argv
, "hD", options
, NULL
)) >= 0)
591 if ((r
= log_set_max_level_from_string(optarg
)) < 0) {
592 log_error("Failed to parse log level %s.", optarg
);
600 if ((r
= log_set_target_from_string(optarg
)) < 0) {
601 log_error("Failed to parse log target %s.", optarg
);
610 if ((r
= log_show_color_from_string(optarg
)) < 0) {
611 log_error("Failed to parse log color setting %s.", optarg
);
615 log_show_color(true);
619 case ARG_LOG_LOCATION
:
622 if ((r
= log_show_location_from_string(optarg
)) < 0) {
623 log_error("Failed to parse log location setting %s.", optarg
);
627 log_show_location(true);
633 if ((r
= set_default_unit(optarg
)) < 0) {
634 log_error("Failed to set default unit %s: %s", optarg
, strerror(-r
));
641 arg_running_as
= MANAGER_SYSTEM
;
645 arg_running_as
= MANAGER_SESSION
;
649 arg_action
= ACTION_TEST
;
652 case ARG_DUMP_CONFIGURATION_ITEMS
:
653 arg_action
= ACTION_DUMP_CONFIGURATION_ITEMS
;
657 arg_dump_core
= true;
660 case ARG_CRASH_SHELL
:
661 arg_crash_shell
= true;
664 case ARG_CONFIRM_SPAWN
:
665 arg_confirm_spawn
= true;
668 case ARG_SHOW_STATUS
:
669 arg_show_status
= true;
672 case ARG_DESERIALIZE
: {
676 if ((r
= safe_atoi(optarg
, &fd
)) < 0 || fd
< 0) {
677 log_error("Failed to parse deserialize option %s.", optarg
);
681 if (!(f
= fdopen(fd
, "r"))) {
682 log_error("Failed to open serialization fd: %m");
687 fclose(serialization
);
694 case ARG_INTROSPECT
: {
695 const char * const * i
= NULL
;
697 for (i
= bus_interface_table
; *i
; i
+= 2)
698 if (!optarg
|| streq(i
[0], optarg
)) {
699 fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
702 fputs("</node>\n", stdout
);
709 log_error("Unknown interface %s.", optarg
);
711 arg_action
= ACTION_DONE
;
716 arg_action
= ACTION_HELP
;
720 log_set_max_level(LOG_DEBUG
);
727 log_error("Unknown option code %c", c
);
731 /* PID 1 will get the kernel arguments as parameters, which we
732 * ignore and unconditionally read from
733 * /proc/cmdline. However, we need to ignore those arguments
735 if (arg_running_as
!= MANAGER_SYSTEM
&& optind
< argc
) {
736 log_error("Excess arguments.");
743 static int help(void) {
745 printf("%s [OPTIONS...]\n\n"
746 "Starts up and maintains the system or a session.\n\n"
747 " -h --help Show this help\n"
748 " --test Determine startup sequence, dump it and exit\n"
749 " --dump-configuration-items Dump understood unit configuration items\n"
750 " --introspect[=INTERFACE] Extract D-Bus interface data\n"
751 " --unit=UNIT Set default unit\n"
752 " --system Run a system instance, even if PID != 1\n"
753 " --session Run a session instance\n"
754 " --dump-core Dump core on crash\n"
755 " --crash-shell Run shell on crash\n"
756 " --confirm-spawn Ask for confirmation when spawning processes\n"
757 " --show-status Show status updates on the console during bootup\n"
758 " --log-target=TARGET Set log target (console, syslog, kmsg, syslog-or-kmsg, null)\n"
759 " --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
760 " --log-color[=0|1] Highlight important log messages\n"
761 " --log-location[=0|1] Include code location in log messages\n",
762 program_invocation_short_name
);
767 static int prepare_reexecute(Manager
*m
, FILE **_f
, FDSet
**_fds
) {
776 if ((r
= manager_open_serialization(m
, &f
)) < 0) {
777 log_error("Failed to create serialization faile: %s", strerror(-r
));
781 if (!(fds
= fdset_new())) {
783 log_error("Failed to allocate fd set: %s", strerror(-r
));
787 if ((r
= manager_serialize(m
, f
, fds
)) < 0) {
788 log_error("Failed to serialize state: %s", strerror(-r
));
792 if (fseeko(f
, 0, SEEK_SET
) < 0) {
793 log_error("Failed to rewind serialization fd: %m");
797 if ((r
= fd_cloexec(fileno(f
), false)) < 0) {
798 log_error("Failed to disable O_CLOEXEC for serialization: %s", strerror(-r
));
802 if ((r
= fdset_cloexec(fds
, false)) < 0) {
803 log_error("Failed to disable O_CLOEXEC for serialization fds: %s", strerror(-r
));
821 int main(int argc
, char *argv
[]) {
827 bool reexecute
= false;
829 if (getpid() != 1 && strstr(program_invocation_short_name
, "init")) {
830 /* This is compatbility support for SysV, where
831 * calling init as a user is identical to telinit. */
834 execv(SYSTEMCTL_BINARY_PATH
, argv
);
835 log_error("Failed to exec " SYSTEMCTL_BINARY_PATH
": %m");
839 if (label_init() < 0)
842 log_show_color(isatty(STDERR_FILENO
) > 0);
843 log_show_location(false);
844 log_set_max_level(LOG_INFO
);
847 arg_running_as
= MANAGER_SYSTEM
;
848 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG
);
850 arg_running_as
= MANAGER_SESSION
;
851 log_set_target(LOG_TARGET_CONSOLE
);
854 if (set_default_unit(SPECIAL_DEFAULT_TARGET
) < 0)
857 /* Mount /proc, /sys and friends, so that /proc/cmdline and
858 * /proc/$PID/fd is available. */
859 if (geteuid() == 0 && !getenv("SYSTEMD_SKIP_API_MOUNTS"))
860 if (mount_setup() < 0)
863 /* Reset all signal handlers. */
864 assert_se(reset_all_signal_handlers() == 0);
866 /* If we are init, we can block sigkill. Yay. */
867 ignore_signals(SIGNALS_IGNORE
, -1);
869 if (parse_config_file() < 0)
872 if (arg_running_as
== MANAGER_SYSTEM
)
873 if (parse_proc_cmdline() < 0)
876 log_parse_environment();
878 if (parse_argv(argc
, argv
) < 0)
881 if (arg_action
== ACTION_HELP
) {
884 } else if (arg_action
== ACTION_DUMP_CONFIGURATION_ITEMS
) {
885 unit_dump_config_items(stdout
);
888 } else if (arg_action
== ACTION_DONE
) {
893 assert_se(arg_action
== ACTION_RUN
|| arg_action
== ACTION_TEST
);
895 /* Remember open file descriptors for later deserialization */
897 if ((r
= fdset_new_fill(&fds
)) < 0) {
898 log_error("Failed to allocate fd set: %s", strerror(-r
));
902 assert_se(fdset_remove(fds
, fileno(serialization
)) >= 0);
904 close_all_fds(NULL
, 0);
906 /* Set up PATH unless it is already set */
908 "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
909 arg_running_as
== MANAGER_SYSTEM
);
911 /* Move out of the way, so that we won't block unmounts */
912 assert_se(chdir("/") == 0);
914 if (arg_running_as
== MANAGER_SYSTEM
) {
915 /* Become a session leader if we aren't one yet. */
918 /* Disable the umask logic */
922 /* Make sure D-Bus doesn't fiddle with the SIGPIPE handlers */
923 dbus_connection_set_change_sigpipe(FALSE
);
925 /* Reset the console, but only if this is really init and we
926 * are freshly booted */
927 if (arg_running_as
== MANAGER_SYSTEM
&& arg_action
== ACTION_RUN
) {
928 console_setup(getpid() == 1 && !serialization
);
932 /* Open the logging devices, if possible and necessary */
935 /* Make sure we leave a core dump without panicing the
938 install_crash_handler();
940 log_info(PACKAGE_STRING
" running in %s mode.", manager_running_as_to_string(arg_running_as
));
942 if (arg_running_as
== MANAGER_SYSTEM
) {
944 /* Disable nscd, to avoid deadlocks when systemd uses
945 * NSS and the nscd socket is maintained by us. */
946 /* if (nss_disable_nscd) { */
947 /* log_debug("Disabling nscd"); */
948 /* nss_disable_nscd(); */
950 /* log_debug("Hmm, can't disable nscd."); */
952 if (!serialization
) {
955 modprobe_setup(arg_nomodules
);
962 if ((r
= manager_new(arg_running_as
, &m
)) < 0) {
963 log_error("Failed to allocate manager object: %s", strerror(-r
));
967 m
->confirm_spawn
= arg_confirm_spawn
;
968 m
->show_status
= arg_show_status
;
970 if ((r
= manager_startup(m
, serialization
, fds
)) < 0)
971 log_error("Failed to fully start up daemon: %s", strerror(-r
));
974 /* This will close all file descriptors that were opened, but
975 * not claimed by any unit. */
982 fclose(serialization
);
983 serialization
= NULL
;
987 dbus_error_init(&error
);
989 log_debug("Activating default unit: %s", arg_default_unit
);
991 if ((r
= manager_load_unit(m
, arg_default_unit
, NULL
, &error
, &target
)) < 0) {
992 log_error("Failed to load default target: %s", bus_error(&error
, r
));
993 dbus_error_free(&error
);
995 log_info("Trying to load rescue target...");
996 if ((r
= manager_load_unit(m
, SPECIAL_RESCUE_TARGET
, NULL
, &error
, &target
)) < 0) {
997 log_error("Failed to load rescue target: %s", bus_error(&error
, r
));
998 dbus_error_free(&error
);
1003 if (arg_action
== ACTION_TEST
) {
1004 printf("-> By units:\n");
1005 manager_dump_units(m
, stdout
, "\t");
1008 if ((r
= manager_add_job(m
, JOB_START
, target
, JOB_REPLACE
, false, &error
, &job
)) < 0) {
1009 log_error("Failed to start default target: %s", bus_error(&error
, r
));
1010 dbus_error_free(&error
);
1014 if (arg_action
== ACTION_TEST
) {
1015 printf("-> By jobs:\n");
1016 manager_dump_jobs(m
, stdout
, "\t");
1023 if ((r
= manager_loop(m
)) < 0) {
1024 log_error("Failed to run mainloop: %s", strerror(-r
));
1028 switch (m
->exit_code
) {
1035 case MANAGER_RELOAD
:
1036 log_info("Reloading.");
1037 if ((r
= manager_reload(m
)) < 0)
1038 log_error("Failed to reload: %s", strerror(-r
));
1041 case MANAGER_REEXECUTE
:
1042 if (prepare_reexecute(m
, &serialization
, &fds
) < 0)
1046 log_notice("Reexecuting.");
1050 assert_not_reached("Unknown exit code.");
1058 free(arg_default_unit
);
1063 const char *args
[14];
1067 assert(serialization
);
1070 args
[i
++] = SYSTEMD_BINARY_PATH
;
1072 args
[i
++] = "--log-level";
1073 args
[i
++] = log_level_to_string(log_get_max_level());
1075 args
[i
++] = "--log-target";
1076 args
[i
++] = log_target_to_string(log_get_target());
1078 if (arg_running_as
== MANAGER_SYSTEM
)
1079 args
[i
++] = "--system";
1081 args
[i
++] = "--session";
1084 args
[i
++] = "--dump-core";
1086 if (arg_crash_shell
)
1087 args
[i
++] = "--crash-shell";
1089 if (arg_confirm_spawn
)
1090 args
[i
++] = "--confirm-spawn";
1092 if (arg_show_status
)
1093 args
[i
++] = "--show-status";
1095 snprintf(sfd
, sizeof(sfd
), "%i", fileno(serialization
));
1098 args
[i
++] = "--deserialize";
1103 assert(i
<= ELEMENTSOF(args
));
1105 execv(args
[0], (char* const*) args
);
1107 log_error("Failed to reexecute: %m");
1111 fclose(serialization
);