main.c revision 89fffa2735ea975b3716ee47820d194bd86cce5f
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/>.
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidtstatic SystemdRunningAs arg_running_as = _SYSTEMD_RUNNING_AS_INVALID;
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidtstatic bool arg_dump_core = true;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic bool arg_crash_shell = false;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic bool arg_confirm_spawn = false;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic ShowStatus arg_show_status = SHOW_STATUS_UNSET;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic bool arg_switched_root = false;
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poetteringstatic char ***arg_join_controllers = NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic usec_t arg_default_restart_usec = DEFAULT_RESTART_USEC;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic usec_t arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic usec_t arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic usec_t arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic unsigned arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic char **arg_default_environment = NULL;
cca1dfddd4ce4357113663532696488427cc54e4Lennart Poetteringstatic struct rlimit *arg_default_rlimit[RLIMIT_NLIMITS] = {};
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic uint64_t arg_capability_bounding_set_drop = 0;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringstatic nsec_t arg_timer_slack_nsec = (nsec_t) -1;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Pass this on immediately, if this is not PID 1 */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* We want to wait for the core process, hence let's enable SIGCHLD */
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt log_error("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering else if (pid == 0) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Enable default signal handler for core dump */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Don't limit the core dump size */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Just to be sure... */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Raise the signal again */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering /* Order things nicely. */
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_error("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_info("Executing crash shell in 10s...");
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering /* Let the kernel reap children for us */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering log_error("Failed to fork off crash shell: %m");
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering else if (pid == 0) {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering log_info("Successfully spawned crash shell as pid "PID_FMT".", pid);
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidtstatic void install_crash_handler(void) {
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering /* If we are init, we connect stdin/stdout/stderr to /dev/null
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering * and make sure we don't have a controlling tty. */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart 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));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering /* We don't want to force text mode.
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers * plymouth may be showing pictures already from initrd. */
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_error("Failed to reset /dev/console: %s", strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int set_default_unit(const char *u) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sieversstatic int parse_proc_cmdline_word(const char *word) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers static const char * const rlmap[] = {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "rd.systemd.unit=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.log_target=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (log_set_target_from_string(word + 19) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse log target %s. Ignoring.", word + 19);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.log_level=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (log_set_max_level_from_string(word + 18) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse log level %s. Ignoring.", word + 18);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.log_color=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (log_show_color_from_string(word + 18) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse log color setting %s. Ignoring.", word + 18);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.log_location=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (log_show_location_from_string(word + 21) < 0)
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse log location setting %s. Ignoring.", word + 21);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.dump_core=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse dump core switch %s. Ignoring.", word + 18);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering } else if (startswith(word, "systemd.crash_shell=")) {
a0b1209c4a59754f428894e0485413542da50014Zbigniew Jędrzejewski-Szmek log_warning("Failed to parse crash shell switch %s. Ignoring.", word + 20);
a0b1209c4a59754f428894e0485413542da50014Zbigniew Jędrzejewski-Szmek } else if (startswith(word, "systemd.confirm_spawn=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse confirm spawn switch %s. Ignoring.", word + 22);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers } else if (startswith(word, "systemd.crash_chvt=")) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse crash chvt switch %s. Ignoring.", word + 19);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers } else if (startswith(word, "systemd.show_status=")) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers r = parse_show_status(word + 20, &arg_show_status);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning("Failed to parse show status switch %s. Ignoring.", word + 20);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers } else if (startswith(word, "systemd.default_standard_output=")) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers if ((r = exec_output_from_string(word + 32)) < 0)
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning("Failed to parse default standard output switch %s. Ignoring.", word + 32);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers } else if (startswith(word, "systemd.default_standard_error=")) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers if ((r = exec_output_from_string(word + 31)) < 0)
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning("Failed to parse default standard error switch %s. Ignoring.", word + 31);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers } else if (startswith(word, "systemd.setenv=")) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers env = strv_env_set(arg_default_environment, cenv);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning("Setting environment variable '%s' failed, ignoring: %m", cenv);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning("Environment variable name '%s' is not valid. Ignoring.", cenv);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers (in_initrd() && startswith(word, "rd.systemd."))) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers const char *c;
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen /* Ignore systemd.journald.xyz and friends */
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen log_warning("Unknown kernel switch %s. Ignoring.", word);
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.unit=UNIT Default unit to start\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "rd.systemd.unit=UNIT Default unit to start when run in initrd\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.dump_core=0|1 Dump core on crash\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.crash_shell=0|1 Run shell on crash\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.crash_chvt=N Change to VT #N on crash\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.confirm_spawn=0|1 Confirm every process spawn\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.show_status=0|1|auto Show status updates on the console during bootup\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.log_target=console|kmsg|journal|journal-or-kmsg|syslog|syslog-or-kmsg|null\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen " Log target\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.log_level=LEVEL Log level\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.log_color=0|1 Highlight important log messages\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.log_location=0|1 Include code location in log messages\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen " Set default log output for services\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen " Set default log error output for services\n"
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen "systemd.setenv=ASSIGNMENT Set an environment variable for all spawned processes\n");
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen /* Log to kmsg, the journal socket will fill up before the
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen * journal is started and tools running during that time
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen * will block with every log message for for 60 seconds,
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen * before they give up. */
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen log_set_target(detect_container(NULL) > 0 ? LOG_TARGET_CONSOLE : LOG_TARGET_KMSG);
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen } else if (!in_initrd()) {
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen /* SysV compatibility */
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen const char *filename, \
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen const char *section, \
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen const char *lvalue, \
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen const char *rvalue, \
7a1494aa4e4a131d73e866cf1e7eb7b6e47dbab8Tom Gundersen log_syntax(unit, LOG_ERR, filename, line, -r, \
59512f21d77d984cf1363fb0d1770218c5e17020Kay SieversDEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level")
59512f21d77d984cf1363fb0d1770218c5e17020Kay SieversDEFINE_SETTER(config_parse_target, log_set_target_from_string, "target")
59512f21d77d984cf1363fb0d1770218c5e17020Kay SieversDEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" )
59512f21d77d984cf1363fb0d1770218c5e17020Kay SieversDEFINE_SETTER(config_parse_location, log_show_location_from_string, "location")
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sieversstatic int config_parse_cpu_affinity2(const char *unit,
0b6b6787e3f0ae8906ce0212bd629edbe931b73dKay Sievers unsigned ncpus = 0;
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers if (!(t = strndup(w, l)))
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers log_warning_unit(unit, "Failed to set CPU affinity: %m");
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sieversstatic void strv_free_free(char ***l) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers for (i = l; *i; i++)
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sieversstatic void free_join_controllers(void) {
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sieversstatic int config_parse_join_controllers(const char *unit,
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers unsigned n = 0;
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering FOREACH_WORD_QUOTED(w, length, rvalue, state) {
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek arg_join_controllers = new(char**, 2);
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek arg_join_controllers[1] = NULL;
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering for (a = arg_join_controllers; *a; a++) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering if (strv_extend_strv(&l, *a) < 0) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poetteringstatic int parse_config_file(void) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "LogLevel", config_parse_level2, 0, NULL },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "LogTarget", config_parse_target, 0, NULL },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "LogColor", config_parse_color, 0, NULL },
458a2f85e8ae08c534bf8d030fbeeb791893422bTom Gundersen { "Manager", "LogLocation", config_parse_location, 0, NULL },
458a2f85e8ae08c534bf8d030fbeeb791893422bTom Gundersen { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
458a2f85e8ae08c534bf8d030fbeeb791893422bTom Gundersen { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell },
458a2f85e8ae08c534bf8d030fbeeb791893422bTom Gundersen { "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "CrashChVT", config_parse_int, 0, &arg_crash_chvt },
458a2f85e8ae08c534bf8d030fbeeb791893422bTom Gundersen { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, NULL },
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "ShutdownWatchdogSec", config_parse_sec, 0, &arg_shutdown_watchdog },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "CapabilityBoundingSet", config_parse_bounding_set, 0, &arg_capability_bounding_set_drop },
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek { "Manager", "SystemCallArchitectures", config_parse_syscall_archs, 0, &arg_syscall_archs },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output },
fa041593fe04b12ffd7e81d8b3598a7a6f313fb3Lennart Poettering { "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error },
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek { "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultTimeoutStopSec", config_parse_sec, 0, &arg_default_timeout_stop_usec },
fa041593fe04b12ffd7e81d8b3598a7a6f313fb3Lennart Poettering { "Manager", "DefaultRestartSec", config_parse_sec, 0, &arg_default_restart_usec },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitCPU", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_CPU] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitFSIZE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_FSIZE] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitDATA", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_DATA] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitSTACK", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_STACK] },
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek { "Manager", "DefaultLimitCORE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_CORE] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitRSS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RSS] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitNOFILE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NOFILE] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitAS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_AS] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitNPROC", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NPROC] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitMEMLOCK", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_MEMLOCK] },
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering { "Manager", "DefaultLimitLOCKS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_LOCKS] },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "DefaultLimitSIGPENDING", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_SIGPENDING] },
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultLimitMSGQUEUE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_MSGQUEUE] },
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultLimitNICE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NICE] },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "DefaultLimitRTPRIO", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTPRIO] },
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering { "Manager", "DefaultLimitRTTIME", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTTIME] },
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt const char *fn;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering fn = arg_running_as == SYSTEMD_SYSTEM ? PKGSYSCONFDIR "/system.conf" : PKGSYSCONFDIR "/user.conf";
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to open configuration file '%s': %m", fn);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = config_parse(NULL, fn, f, "Manager\0", config_item_table_lookup, (void*) items, false, false, NULL);
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to parse configuration file: %s", strerror(-r));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic int parse_proc_cmdline(void) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_error("Failed on cmdline argument %s: %s", word, strerror(-r));
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers { "log-level", required_argument, NULL, ARG_LOG_LEVEL },
2fc09a9cdd1ad25bc7c53a23d5301eb952e1ce3dDaniel Mack { "log-target", required_argument, NULL, ARG_LOG_TARGET },
2fc09a9cdd1ad25bc7c53a23d5301eb952e1ce3dDaniel Mack { "log-color", optional_argument, NULL, ARG_LOG_COLOR },
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers { "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering { "system", no_argument, NULL, ARG_SYSTEM },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "version", no_argument, NULL, ARG_VERSION },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "dump-core", optional_argument, NULL, ARG_DUMP_CORE },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "crash-shell", optional_argument, NULL, ARG_CRASH_SHELL },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "confirm-spawn", optional_argument, NULL, ARG_CONFIRM_SPAWN },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
cca1dfddd4ce4357113663532696488427cc54e4Lennart Poettering { "deserialize", required_argument, NULL, ARG_DESERIALIZE },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering { "switched-root", no_argument, NULL, ARG_SWITCHED_ROOT },
2fc09a9cdd1ad25bc7c53a23d5301eb952e1ce3dDaniel Mack { "default-standard-output", required_argument, NULL, ARG_DEFAULT_STD_OUTPUT, },
2fc09a9cdd1ad25bc7c53a23d5301eb952e1ce3dDaniel Mack { "default-standard-error", required_argument, NULL, ARG_DEFAULT_STD_ERROR, },
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering while ((c = getopt_long(argc, argv, "hDbsz:", options, NULL)) >= 0)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if ((r = log_set_max_level_from_string(optarg)) < 0) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_error("Failed to parse log level %s.", optarg);
59512f21d77d984cf1363fb0d1770218c5e17020Kay Sievers if ((r = log_set_target_from_string(optarg)) < 0) {
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_error("Failed to parse log target %s.", optarg);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering if ((r = log_show_color_from_string(optarg)) < 0) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_error("Failed to parse log color setting %s.", optarg);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if ((r = log_show_location_from_string(optarg)) < 0) {
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to parse log location setting %s.", optarg);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if ((r = exec_output_from_string(optarg)) < 0) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_error("Failed to parse default standard output setting %s.", optarg);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if ((r = exec_output_from_string(optarg)) < 0) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering log_error("Failed to parse default standard error output setting %s.", optarg);
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering if ((r = set_default_unit(optarg)) < 0) {
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to set default unit %s: %s", optarg, strerror(-r));
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering arg_action = ACTION_DUMP_CONFIGURATION_ITEMS;
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to parse dump core boolean %s.", optarg);
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to parse crash shell boolean %s.", optarg);
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to parse confirm spawn boolean %s.", optarg);
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering r = parse_show_status(optarg, &arg_show_status);
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering log_error("Failed to parse show status boolean %s.", optarg);
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering if (r < 0 || fd < 0) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_error("Failed to parse deserialize option %s.", optarg);
d2a623823f8d83c97c35fcd28f90e8cd59066f8aZbigniew Jędrzejewski-Szmek return r < 0 ? r : -EINVAL;
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering log_error("Failed to open serialization fd: %m");
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt /* Just to eat away the sysvinit kernel
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering * cmdline args without getopt() error
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering * messages that we'll parse in
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering * parse_proc_cmdline_word() or ignore. */
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering /* Hmm, when we aren't run as init system
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering * let's complain about excess arguments */
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt /* All /proc/cmdline arguments the kernel didn't
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt * understand it passed to us. We're not really
c6ba0c184d297a454baf387663668db77f79c1b5Lennart Poettering * interested in that usually since /proc/cmdline is
eafe88e34a0698d2f4ebb747ab4911e35d0dfe4cTobias Hunger * more interesting and complete. With one exception:
eafe88e34a0698d2f4ebb747ab4911e35d0dfe4cTobias Hunger * if we are run in a container /proc/cmdline is not
eafe88e34a0698d2f4ebb747ab4911e35d0dfe4cTobias Hunger * relevant for the container, hence we rely on argv[]
eafe88e34a0698d2f4ebb747ab4911e35d0dfe4cTobias Hunger * instead. */
61331eab0a53cd9b8446eab6d1ebf1a046d8efc1Lennart Poettering log_error("Failed on cmdline argument %s: %s", *a, strerror(-r));
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int help(void) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering "Starts up and maintains the system or user services.\n\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " -h --help Show this help\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --test Determine startup sequence, dump it and exit\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --dump-configuration-items Dump understood unit configuration items\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --unit=UNIT Set default unit\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --system Run a system instance, even if PID != 1\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --user Run a user instance\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --dump-core[=0|1] Dump core on crash\n"
75f86906c52735c98dc0aa7e24b773edb42ee814Lennart Poettering " --crash-shell[=0|1] Run shell on crash\n"
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poettering " --confirm-spawn[=0|1] Ask for confirmation when spawning processes\n"
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering " --show-status[=0|1] Show status updates on the console during bootup\n"
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering " --log-target=TARGET Set log target (console, journal, syslog, kmsg, journal-or-kmsg, syslog-or-kmsg, null)\n"
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering " --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering " --log-color[=0|1] Highlight important log messages\n"
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering " --log-location[=0|1] Include code location in log messages\n"
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt " --default-standard-output= Set default standard output for services\n"
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering " --default-standard-error= Set default standard error output for services\n",
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int version(void) {
73b80ec2d999c45ce13f3e034704249d80829f7eLennart Poetteringstatic int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) {
r = manager_open_serialization(m, &f);
goto fail;
m->n_reloading ++;
bus_manager_send_reloading(m, true);
if (!fds) {
r = -ENOMEM;
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
*_f = f;
fail:
fclose(f);
return -errno;
if (!rl)
return log_oom();
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.");
static int initialize_join_controllers(void) {
if (!arg_join_controllers)
return -ENOMEM;
return -ENOMEM;
#ifdef HAVE_SECCOMP
Iterator i;
void *id;
if (!seccomp)
return log_oom();
if (r == -EEXIST)
goto finish;
bool reexecute = false;
bool skip_setup = false;
bool loaded_policy = false;
bool arm_reboot_watchdog = false;
bool queue_default_job = false;
#ifdef HAVE_SYSV_COMPAT
skip_setup = true;
skip_setup = false;
umask(0);
log_open();
if (in_initrd())
if (!skip_setup) {
goto finish;
if (ima_setup() < 0)
goto finish;
if (smack_setup() < 0)
goto finish;
goto finish;
if (!skip_setup) {
if (hwclock_is_localtime() > 0) {
int min;
} else if (!in_initrd()) {
log_open();
log_open();
goto finish;
r = initialize_join_controllers();
goto finish;
goto finish;
if (parse_config_file() < 0)
goto finish;
if (parse_proc_cmdline() < 0)
goto finish;
goto finish;
geteuid() == 0) {
goto finish;
sd_booted() <= 0) {
goto finish;
running_in_chroot() > 0) {
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
log_close();
goto finish;
if (arg_serialization)
setsid();
log_open();
goto finish;
if (virtualization)
if (in_initrd())
getuid(), t);
#ifdef HAVE_KMOD
kmod_setup();
test_mtab();
test_usr();
test_cgroups();
goto finish;
goto finish;
if (arg_syscall_archs) {
goto finish;
goto finish;
if (arg_serialization) {
if (queue_default_job) {
goto finish;
goto finish;
goto finish;
if (r == -EPERM) {
log_debug("Default target could not be isolated, starting instead: %s", bus_error_message(&error, r));
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_SWITCH_ROOT:
if (!switch_root_init)
goto finish;
reexecute = true;
goto finish;
case MANAGER_REBOOT:
case MANAGER_POWEROFF:
case MANAGER_HALT:
case MANAGER_KEXEC: {
goto finish;
manager_free(m);
m = NULL;
label_finish();
if (reexecute) {
const char **args;
unsigned i, args_size;
watchdog_close(true);
if (switch_root_dir) {
if (!switch_root_init) {
if (switch_root_dir)
if (switch_root_dir)
clearenv();
if (arg_serialization) {
if (fds) {
if (switch_root_init) {
if (arg_serialization) {
if (fds) {
#ifdef HAVE_VALGRIND_VALGRIND_H
if (shutdown_verb) {
const char * command_line[] = {
watchdog_close(false);
watchdog_close(true);
freeze();
return retval;