main.c revision 9f28b98ec6461b4e06edd1e149c1ee5e9dcc4be0
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering This file is part of systemd.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering Copyright 2010 Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering (at your option) any later version.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering systemd is distributed in the hope that it will be useful, but
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering Lesser General Public License for more details.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic bool arg_dump_core = true;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic bool arg_crash_shell = false;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic bool arg_confirm_spawn = false;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic bool arg_show_status = true;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic bool arg_sysv_console = true;
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poetteringstatic bool arg_mount_auto = true;
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poetteringstatic bool arg_swap_auto = true;
ee530d8b73246f29781bd54a707ca75c7ef5a6cbLennart Poetteringstatic char **arg_default_controllers = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic char ***arg_join_controllers = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering /* We want to wait for the core process, hence let's enable SIGCHLD */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering else if (pid == 0) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Enable default signal handler for core dump */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert_se(sigaction(sig, &sa, NULL) == 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Don't limit the core dump size */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Just to be sure... */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Raise the signal again */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert_not_reached("We shouldn't be here...");
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Order things nicely. */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if ((r = wait_for_terminate(pid, &status)) < 0)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_info("Executing crash shell in 10s...");
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Let the kernel reap children for us */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to fork off crash shell: %s", strerror(errno));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering else if (pid == 0) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if ((fd = acquire_terminal("/dev/console", false, true, true)) < 0)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to acquire terminal: %s", strerror(-fd));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to duplicate terminal fd: %s", strerror(-r));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("execl() failed: %s", strerror(errno));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_info("Successfully spawned crash shell as pid %lu.", (unsigned long) pid);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic void install_crash_handler(void) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* If we are init, we connect stdin/stdout/stderr to /dev/null
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering * and make sure we don't have a controlling tty. */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to open /dev/console: %s", strerror(-tty_fd));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* We don't want to force text mode.
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering * plymouth may be showing pictures already from initrd. */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to reset /dev/console: %s", strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int set_default_unit(const char *u) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering if (!(c = strdup(u)))
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic int parse_proc_cmdline_word(const char *word) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering static const char * const rlmap[] = {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering else if (startswith(word, "systemd.log_target=")) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (log_set_target_from_string(word + 19) < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_warning("Failed to parse log target %s. Ignoring.", word + 19);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering } else if (startswith(word, "systemd.log_level=")) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (log_set_max_level_from_string(word + 18) < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_warning("Failed to parse log level %s. Ignoring.", word + 18);
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering } else if (startswith(word, "systemd.log_color=")) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if (log_show_color_from_string(word + 18) < 0)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering log_warning("Failed to parse log color setting %s. Ignoring.", word + 18);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering } else if (startswith(word, "systemd.log_location=")) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if (log_show_location_from_string(word + 21) < 0)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering log_warning("Failed to parse log location setting %s. Ignoring.", word + 21);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering } else if (startswith(word, "systemd.dump_core=")) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_warning("Failed to parse dump core switch %s. Ignoring.", word + 18);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering } else if (startswith(word, "systemd.crash_shell=")) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_warning("Failed to parse crash shell switch %s. Ignoring.", word + 20);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering } else if (startswith(word, "systemd.confirm_spawn=")) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_warning("Failed to parse confirm spawn switch %s. Ignoring.", word + 22);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering } else if (startswith(word, "systemd.crash_chvt=")) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_warning("Failed to parse crash chvt switch %s. Ignoring.", word + 19);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering } else if (startswith(word, "systemd.show_status=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse show status switch %s. Ignoring.", word + 20);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.default_standard_output=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if ((r = exec_output_from_string(word + 32)) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse default standard output switch %s. Ignoring.", word + 32);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.default_standard_error=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if ((r = exec_output_from_string(word + 31)) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse default standard error switch %s. Ignoring.", word + 31);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.setenv=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("unsetenv failed %s. Ignoring.", strerror(errno));
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("setenv failed %s. Ignoring.", strerror(errno));
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.sysv_console=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse SysV console switch %s. Ignoring.", word + 20);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Unknown kernel switch %s. Ignoring.", word);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.unit=UNIT Default unit to start\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.dump_core=0|1 Dump core on crash\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.crash_shell=0|1 Run shell on crash\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.crash_chvt=N Change to VT #N on crash\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.confirm_spawn=0|1 Confirm every process spawn\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.show_status=0|1 Show status updates on the console during bootup\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.sysv_console=0|1 Connect output of SysV scripts to console\n"
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek "systemd.log_target=console|kmsg|journal|journal-or-kmsg|syslog|syslog-or-kmsg|null\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.log_level=LEVEL Log level\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.log_color=0|1 Highlight important log messages\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.log_location=0|1 Include code location in log messages\n"
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering "systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering " Set default log output for services\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering " Set default log error output for services\n");
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek /* SysV compatibility */
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmekstatic int config_parse_cpu_affinity2(
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!(t = strndup(w, l)))
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to set CPU affinity: %m");
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic void strv_free_free(char ***l) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering for (i = l; *i; i++)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poetteringstatic void free_join_controllers(void) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering unsigned n = 0;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering FOREACH_WORD_QUOTED(w, length, rvalue, state) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering for (a = arg_join_controllers; *a; a++) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic int parse_config_file(void) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "LogLevel", config_parse_level2, 0, NULL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "LogTarget", config_parse_target, 0, NULL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "LogColor", config_parse_color, 0, NULL },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "LogLocation", config_parse_location, 0, NULL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "ShowStatus", config_parse_bool, 0, &arg_show_status },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "SysVConsole", config_parse_bool, 0, &arg_sysv_console },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "CrashChVT", config_parse_int, 0, &arg_crash_chvt },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, NULL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "MountAuto", config_parse_bool, 0, &arg_mount_auto },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "SwapAuto", config_parse_bool, 0, &arg_swap_auto },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "DefaultControllers", config_parse_strv, 0, &arg_default_controllers },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "RuntimeWatchdogSec", config_parse_usec, 0, &arg_runtime_watchdog },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "Manager", "ShutdownWatchdogSec", config_parse_usec, 0, &arg_shutdown_watchdog },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering fn = arg_running_as == MANAGER_SYSTEM ? SYSTEM_CONFIG_FILE : USER_CONFIG_FILE;
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_warning("Failed to open configuration file '%s': %m", fn);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering r = config_parse(fn, f, "Manager\0", config_item_table_lookup, (void*) items, false, NULL);
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek log_warning("Failed to parse configuration file: %s", strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int parse_proc_cmdline(void) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering /* Don't read /proc/cmdline if we are in a container, since
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering * that is only relevant for the host system */
98b2f766b24c84fc49a4df954717b1f96bbce00dLennart Poettering if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "log-level", required_argument, NULL, ARG_LOG_LEVEL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "log-target", required_argument, NULL, ARG_LOG_TARGET },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "log-color", optional_argument, NULL, ARG_LOG_COLOR },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "unit", required_argument, NULL, ARG_UNIT },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "system", no_argument, NULL, ARG_SYSTEM },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "dump-core", no_argument, NULL, ARG_DUMP_CORE },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "crash-shell", no_argument, NULL, ARG_CRASH_SHELL },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "confirm-spawn", no_argument, NULL, ARG_CONFIRM_SPAWN },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "sysv-console", optional_argument, NULL, ARG_SYSV_CONSOLE },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "deserialize", required_argument, NULL, ARG_DESERIALIZE },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "introspect", optional_argument, NULL, ARG_INTROSPECT },
opterr = 0;
case ARG_LOG_LEVEL:
case ARG_LOG_TARGET:
case ARG_LOG_COLOR:
if (optarg) {
log_show_color(true);
case ARG_LOG_LOCATION:
if (optarg) {
log_show_location(true);
case ARG_DEFAULT_STD_OUTPUT:
case ARG_DEFAULT_STD_ERROR:
case ARG_UNIT:
case ARG_SYSTEM:
case ARG_USER:
case ARG_TEST:
case ARG_DUMP_CORE:
arg_dump_core = true;
case ARG_CRASH_SHELL:
arg_crash_shell = true;
case ARG_CONFIRM_SPAWN:
arg_confirm_spawn = true;
case ARG_SHOW_STATUS:
if (optarg) {
arg_show_status = r;
arg_show_status = true;
#ifdef HAVE_SYSV_COMPAT
case ARG_SYSV_CONSOLE:
if (optarg) {
arg_sysv_console = r;
arg_sysv_console = true;
case ARG_DESERIALIZE: {
int fd;
FILE *f;
if (serialization)
serialization = f;
case ARG_INTROSPECT: {
const char * const * i = NULL;
if (optarg)
if (!i[0] && optarg)
return -EINVAL;
return -EINVAL;
if ((r = parse_proc_cmdline_word(*a)) < 0)
static int help(void) {
#ifdef HAVE_SYSV_COMPAT
" --log-target=TARGET Set log target (console, journal, syslog, kmsg, journal-or-kmsg, syslog-or-kmsg, null)\n"
assert(m);
m->n_reloading ++;
if ((r = manager_open_serialization(m, &f)) < 0) {
goto fail;
r = -ENOMEM;
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
*_f = f;
fail:
fclose(f);
assert(t);
return NULL;
return NULL;
static void test_mtab(void) {
free(p);
"Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
static void test_usr(void) {
log_warning("/usr appears to be on its own filesytem and is not already mounted. This is not a supported setup. "
"Consult http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken for more information.");
static void test_cgroups(void) {
"Consult http://0pointer.de/blog/projects/cgroups-vs-cgroups.html for more information.");
bool reexecute = false;
bool is_reexec = false;
bool loaded_policy = false;
bool arm_reboot_watchdog = false;
#ifdef HAVE_SYSV_COMPAT
is_reexec = true;
log_show_location(false);
if (!is_reexec) {
goto finish;
if (ima_setup() < 0)
goto finish;
log_open();
if (label_init() < 0)
goto finish;
if (!is_reexec)
if (hwclock_is_localtime() > 0) {
int min;
log_open();
goto finish;
if (!arg_join_controllers)
goto finish;
if (!arg_join_controllers[0])
goto finish;
goto finish;
if (parse_config_file() < 0)
goto finish;
if (parse_proc_cmdline() < 0)
goto finish;
goto finish;
goto finish;
running_in_chroot() > 0) {
goto finish;
goto finish;
goto finish;
goto finish;
log_close();
if (serialization) {
goto finish;
#ifdef HAVE_SPLIT_USR
setsid();
umask(0);
log_open();
goto finish;
PACKAGE_STRING " running in %s mode. (" SYSTEMD_FEATURES "; " DISTRIBUTION ")", manager_running_as_to_string(arg_running_as));
locale_setup();
kmod_setup();
test_mtab();
test_usr();
test_cgroups();
goto finish;
#ifdef HAVE_SYSV_COMPAT
if (fds) {
if (serialization) {
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
r = manager_loop(m);
goto finish;
switch (m->exit_code) {
case MANAGER_EXIT:
goto finish;
case MANAGER_RELOAD:
r = manager_reload(m);
case MANAGER_REEXECUTE:
goto finish;
reexecute = true;
goto finish;
case MANAGER_REBOOT:
case MANAGER_POWEROFF:
case MANAGER_HALT:
case MANAGER_KEXEC: {
goto finish;
manager_free(m);
label_finish();
if (reexecute) {
if (arg_dump_core)
if (arg_crash_shell)
if (arg_confirm_spawn)
if (arg_show_status)
#ifdef HAVE_SYSV_COMPAT
if (arg_sysv_console)
watchdog_close(true);
if (serialization)
if (fds)
if (shutdown_verb) {
const char * command_line[] = {
char **env_block;
watchdog_close(false);
char_array_0(e);
watchdog_close(true);
freeze();
return retval;