main.c revision 15a900327aba7dc4dc886affe1ae22d3b759b193
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2010 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_dump_core = true;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_crash_shell = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_crash_reboot = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_confirm_spawn = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic ShowStatus arg_show_status = _SHOW_STATUS_UNSET;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_switched_root = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic char ***arg_join_controllers = NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_default_restart_usec = DEFAULT_RESTART_USEC;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic unsigned arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic char **arg_default_environment = NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic uint64_t arg_capability_bounding_set = CAP_ALL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic nsec_t arg_timer_slack_nsec = NSEC_INFINITY;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic usec_t arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_default_cpu_accounting = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_default_blockio_accounting = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_default_memory_accounting = false;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_default_tasks_accounting = true;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic uint64_t arg_default_tasks_max = UINT64_C(512);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic void pager_open_if_enabled(void) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringnoreturn static void freeze_or_reboot(void) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_emergency_errno(errno, "Failed to reboot: %m");
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Pass this on immediately, if this is not PID 1 */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_emergency("Caught <%s>, not dumping core.", signal_to_string(sig));
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt /* We want to wait for the core process, hence let's enable SIGCHLD */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_emergency_errno(errno, "Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen else if (pid == 0) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Enable default signal handler for core dump */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Don't limit the coredump size */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering (void) setrlimit(RLIMIT_CORE, &RLIMIT_MAKE_CONST(RLIM_INFINITY));
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Just to be sure... */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Raise the signal again */
23432a1c249b9c513e438bffe9778a7ce2ee74feZbigniew Jędrzejewski-Szmek (void) kill(pid, sig); /* raise() would kill the parent */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert_not_reached("We shouldn't be here...");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Order things nicely. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_emergency_errno(r, "Caught <%s>, waitpid() failed: %m", signal_to_string(sig));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_emergency("Caught <%s>, core dump failed (child "PID_FMT", code=%s, status=%i/%s).",
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering pid, sigchld_code_to_string(status.si_code),
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering ? exit_status_to_string(status.si_status, EXIT_STATUS_FULL)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering log_emergency("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Let the kernel reap children for us */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_notice("Executing crash shell in 10s...");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_emergency_errno(errno, "Failed to fork off crash shell: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering else if (pid == 0) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (void) execle("/bin/sh", "/bin/sh", NULL, environ);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_emergency_errno(errno, "execle() failed: %m");
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering log_info("Spawned crash shell as PID "PID_FMT".", pid);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek (void) wait_for_terminate(pid, NULL);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmekstatic void install_crash_handler(void) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek static const struct sigaction sa = {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering .sa_flags = SA_NODEFER, /* So that we can raise the signal again from the signal handler */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* We ignore the return value here, since, we don't mind if we
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * cannot set up a crash handler */
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek r = sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek log_debug_errno(r, "I had trouble setting up the crash handler, ignoring: %m");
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return log_error_errno(tty_fd, "Failed to open /dev/console: %m");
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek /* We don't want to force text mode. plymouth may be showing
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek * pictures already from initrd. */
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return log_error_errno(r, "Failed to reset /dev/console: %m");
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poetteringstatic int parse_crash_chvt(const char *value) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (safe_atoi(value, &arg_crash_chvt) >= 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen arg_crash_chvt = 0; /* switch to where kmsg goes */
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersenstatic int set_machine_id(const char *m) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (sd_id128_from_string(m, &arg_machine_id) < 0)
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (sd_id128_is_null(arg_machine_id))
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmekstatic int parse_proc_cmdline_item(const char *key, const char *value) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (streq(key, "systemd.unit") && value) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return free_and_strdup(&arg_default_unit, value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "rd.systemd.unit") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return free_and_strdup(&arg_default_unit, value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.dump_core") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse dump core switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.crash_chvt") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse crash chvt switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.crash_shell") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse crash shell switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.crash_reboot") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse crash reboot switch %s. Ignoring.", value);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering } else if (streq(key, "systemd.confirm_spawn") && value) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_warning("Failed to parse confirm spawn switch %s. Ignoring.", value);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering } else if (streq(key, "systemd.show_status") && value) {
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering r = parse_show_status(value, &arg_show_status);
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering log_warning("Failed to parse show status switch %s. Ignoring.", value);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering } else if (streq(key, "systemd.default_standard_output") && value) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering log_warning("Failed to parse default standard output switch %s. Ignoring.", value);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering } else if (streq(key, "systemd.default_standard_error") && value) {
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering log_warning("Failed to parse default standard error switch %s. Ignoring.", value);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else if (streq(key, "systemd.setenv") && value) {
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann env = strv_env_set(arg_default_environment, value);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_warning_errno(ENOMEM, "Setting environment variable '%s' failed, ignoring: %m", value);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_warning("Environment variable name '%s' is not valid. Ignoring.", value);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else if (streq(key, "systemd.machine_id") && value) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering log_warning("MachineID '%s' is not valid. Ignoring.", value);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } else if (streq(key, "quiet") && !value) {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (arg_show_status == _SHOW_STATUS_UNSET)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } else if (streq(key, "debug") && !value) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering /* Note that log_parse_environment() handles 'debug'
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek * too, and sets the log level to LOG_DEBUG. */
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek log_set_target(LOG_TARGET_CONSOLE);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek } else if (!in_initrd() && !value) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek /* SysV compatibility */
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek target = runlevel_to_target(key);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return free_and_strdup(&arg_default_unit, target);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen const char *filename, \
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen const char *section, \
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering const char *lvalue, \
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering const char *rvalue, \
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, r, \
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas NykrynDEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level")
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-SzmekDEFINE_SETTER(config_parse_target, log_set_target_from_string, "target")
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-SzmekDEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" )
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-SzmekDEFINE_SETTER(config_parse_location, log_show_location_from_string, "location")
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekstatic int config_parse_cpu_affinity2(
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering ncpus = parse_cpu_set_and_warn(rvalue, &c, unit, filename, line, lvalue);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_warning("Failed to set CPU affinity: %m");
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekstatic int config_parse_show_status(
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek k = parse_show_status(rvalue, b);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue);
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenstatic int config_parse_join_controllers(const char *unit,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen unsigned n = 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering arg_join_controllers = strv_free_free(arg_join_controllers);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek for (a = arg_join_controllers; *a; a++) {
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek if (strv_extend_strv(&l, *a, false) < 0) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring.");
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic int parse_config_file(void) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "LogLevel", config_parse_level2, 0, NULL },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "LogTarget", config_parse_target, 0, NULL },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "LogColor", config_parse_color, 0, NULL },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "LogLocation", config_parse_location, 0, NULL },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "CrashChVT", /* legacy */ config_parse_crash_chvt, 0, NULL },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, NULL },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "CrashReboot", config_parse_bool, 0, &arg_crash_reboot },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, NULL },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "ShutdownWatchdogSec", config_parse_sec, 0, &arg_shutdown_watchdog },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "CapabilityBoundingSet", config_parse_capability_set, 0, &arg_capability_bounding_set },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "SystemCallArchitectures", config_parse_syscall_archs, 0, &arg_syscall_archs },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultTimerAccuracySec", config_parse_sec, 0, &arg_default_timer_accuracy_usec },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultTimeoutStopSec", config_parse_sec, 0, &arg_default_timeout_stop_usec },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultRestartSec", config_parse_sec, 0, &arg_default_restart_usec },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment },
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultLimitCPU", config_parse_limit, RLIMIT_CPU, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitFSIZE", config_parse_limit, RLIMIT_FSIZE, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitDATA", config_parse_limit, RLIMIT_DATA, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitSTACK", config_parse_limit, RLIMIT_STACK, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitCORE", config_parse_limit, RLIMIT_CORE, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitRSS", config_parse_limit, RLIMIT_RSS, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitNOFILE", config_parse_limit, RLIMIT_NOFILE, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitAS", config_parse_limit, RLIMIT_AS, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitNPROC", config_parse_limit, RLIMIT_NPROC, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitMEMLOCK", config_parse_limit, RLIMIT_MEMLOCK, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitLOCKS", config_parse_limit, RLIMIT_LOCKS, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitSIGPENDING", config_parse_limit, RLIMIT_SIGPENDING, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitMSGQUEUE", config_parse_limit, RLIMIT_MSGQUEUE, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitNICE", config_parse_limit, RLIMIT_NICE, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitRTPRIO", config_parse_limit, RLIMIT_RTPRIO, arg_default_rlimit },
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen { "Manager", "DefaultLimitRTTIME", config_parse_limit, RLIMIT_RTTIME, arg_default_rlimit },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_default_cpu_accounting },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting },
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting },
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max },
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek conf_dirs_nulstr = arg_running_as == MANAGER_SYSTEM ?
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek CONF_PATHS_NULSTR("systemd/system.conf.d") :
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek CONF_PATHS_NULSTR("systemd/user.conf.d");
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek config_parse_many(fn, conf_dirs_nulstr, "Manager\0", config_item_table_lookup, items, false, NULL);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek /* Traditionally "0" was used to turn off the default unit timeouts. Fix this up so that we used USEC_INFINITY
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek * like everywhere else. */
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek arg_default_timeout_start_usec = USEC_INFINITY;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (arg_default_timeout_stop_usec <= 0)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek arg_default_timeout_stop_usec = USEC_INFINITY;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic void manager_set_defaults(Manager *m) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_timer_accuracy_usec = arg_default_timer_accuracy_usec;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_std_output = arg_default_std_output;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_timeout_start_usec = arg_default_timeout_start_usec;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_timeout_stop_usec = arg_default_timeout_stop_usec;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_restart_usec = arg_default_restart_usec;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_start_limit_interval = arg_default_start_limit_interval;
1bf968f36393666f2c57953b1748e6219c027deeTom Gundersen m->default_start_limit_burst = arg_default_start_limit_burst;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_cpu_accounting = arg_default_cpu_accounting;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_blockio_accounting = arg_default_blockio_accounting;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek m->default_memory_accounting = arg_default_memory_accounting;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen m->default_tasks_accounting = arg_default_tasks_accounting;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen manager_set_default_rlimits(m, arg_default_rlimit);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen manager_environment_add(m, NULL, arg_default_environment);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersenstatic int parse_argv(int argc, char *argv[]) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen { "log-level", required_argument, NULL, ARG_LOG_LEVEL },
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen { "log-target", required_argument, NULL, ARG_LOG_TARGET },
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen { "log-color", optional_argument, NULL, ARG_LOG_COLOR },
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen { "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen { "unit", required_argument, NULL, ARG_UNIT },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "no-pager", no_argument, NULL, ARG_NO_PAGER },
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering { "version", no_argument, NULL, ARG_VERSION },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "dump-core", optional_argument, NULL, ARG_DUMP_CORE },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "crash-chvt", required_argument, NULL, ARG_CRASH_CHVT },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "crash-shell", optional_argument, NULL, ARG_CRASH_SHELL },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "crash-reboot", optional_argument, NULL, ARG_CRASH_REBOOT },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "confirm-spawn", optional_argument, NULL, ARG_CONFIRM_SPAWN },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "deserialize", required_argument, NULL, ARG_DESERIALIZE },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "switched-root", no_argument, NULL, ARG_SWITCHED_ROOT },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "default-standard-output", required_argument, NULL, ARG_DEFAULT_STD_OUTPUT, },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "default-standard-error", required_argument, NULL, ARG_DEFAULT_STD_ERROR, },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen { "machine-id", required_argument, NULL, ARG_MACHINE_ID },
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen while ((c = getopt_long(argc, argv, "hDbsz:", options, NULL)) >= 0)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = log_set_max_level_from_string(optarg);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek log_error("Failed to parse log level %s.", optarg);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_error("Failed to parse log target %s.", optarg);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_error("Failed to parse log color setting %s.", optarg);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = log_show_location_from_string(optarg);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_error("Failed to parse log location setting %s.", optarg);
case ARG_DEFAULT_STD_OUTPUT:
case ARG_DEFAULT_STD_ERROR:
case ARG_UNIT:
case ARG_SYSTEM:
case ARG_USER:
case ARG_TEST:
if (arg_no_pager < 0)
arg_no_pager = true;
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_VERSION:
case ARG_DUMP_CORE:
if (!optarg)
arg_dump_core = true;
arg_dump_core = r;
case ARG_CRASH_CHVT:
case ARG_CRASH_SHELL:
if (!optarg)
arg_crash_shell = true;
arg_crash_shell = r;
case ARG_CRASH_REBOOT:
if (!optarg)
arg_crash_reboot = true;
arg_crash_reboot = r;
case ARG_CONFIRM_SPAWN:
arg_confirm_spawn = r;
case ARG_SHOW_STATUS:
if (optarg) {
case ARG_DESERIALIZE: {
int fd;
FILE *f;
if (r < 0 || fd < 0) {
return -EINVAL;
arg_serialization = f;
case ARG_SWITCHED_ROOT:
arg_switched_root = true;
case ARG_MACHINE_ID:
if (arg_no_pager < 0)
arg_no_pager = true;
return -EINVAL;
return -EINVAL;
static int help(void) {
assert(m);
r = manager_open_serialization(m, &f);
m->n_reloading ++;
bus_manager_send_reloading(m, true);
if (!fds)
return log_oom();
*_f = f;
f = NULL;
if (!rl)
return log_oom();
static void test_usr(void) {
log_warning("/usr appears to be on its own filesystem 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 int initialize_join_controllers(void) {
if (!arg_join_controllers)
return -ENOMEM;
if (!arg_join_controllers[0])
goto oom;
goto oom;
oom:
return -ENOMEM;
#ifdef HAVE_SECCOMP
Iterator i;
void *id;
if (!seccomp)
return log_oom();
if (r == -EEXIST)
goto finish;
goto finish;
static int status_welcome(void) {
NULL);
if (r == -ENOENT)
NULL);
if (r < 0 && r != -ENOENT)
static int write_container_id(void) {
if (isempty(c))
static int bump_unix_max_dgram_qlen(void) {
if (v >= DEFAULT_UNIX_MAX_DGRAM_QLEN)
return log_oom();
bool reexecute = false;
bool skip_setup = false;
bool loaded_policy = false;
bool arm_reboot_watchdog = false;
bool queue_default_job = false;
bool empty_etc = false;
#ifdef HAVE_SYSV_COMPAT
skip_setup = true;
skip_setup = false;
umask(0);
log_open();
if (in_initrd())
if (!skip_setup) {
r = mount_setup_early();
goto finish;
goto finish;
} else if (ima_setup() < 0) {
goto finish;
goto finish;
goto finish;
if (!skip_setup) {
if (clock_is_localtime() > 0) {
int min;
} else if (!in_initrd()) {
(void) clock_reset_timewarp();
r = clock_apply_epoch();
log_open();
log_open();
/* Don't limit the core dump size, so that coredump handlers such as systemd-coredump (which honour the limit)
/* But at the same time, turn off the core_pattern logic by default, so that no coredumps are stored
if (!skip_setup)
goto finish;
r = initialize_join_controllers();
goto finish;
if (!skip_setup)
kmod_setup();
goto finish;
(void) reset_all_signal_handlers();
if (parse_config_file() < 0) {
goto finish;
goto finish;
geteuid() == 0) {
goto finish;
sd_booted() <= 0) {
goto finish;
running_in_chroot() > 0) {
goto finish;
skip_setup = true;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
log_close();
goto finish;
if (arg_serialization)
setsid();
log_open();
goto finish;
v = detect_virtualization();
if (in_initrd())
* /etc/machine-id as flag file. This allows container
if (empty_etc)
_cleanup_free_ char *t;
if (arg_show_status > 0)
test_usr();
goto finish;
goto finish;
if (arg_syscall_archs) {
goto finish;
if (empty_etc) {
r = unit_file_preset_all(UNIT_FILE_SYSTEM, false, NULL, UNIT_FILE_PRESET_ENABLE_ONLY, false, NULL, 0);
log_full_errno(r == -EEXIST ? LOG_NOTICE : LOG_WARNING, r, "Failed to populate /etc with preset unit settings, ignoring: %m");
goto finish;
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_RELOAD:
r = parse_config_file();
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_EXIT:
goto finish;
case MANAGER_REBOOT:
case MANAGER_POWEROFF:
case MANAGER_HALT:
case MANAGER_KEXEC: {
goto finish;
pager_close();
m = manager_free(m);
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)
(void) clearenv();
* so that it prints the summary, and wait() for it in the parent, before proceeding into the exec().
(void) make_console_stdio();
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
if (switch_root_init) {
#ifdef HAVE_VALGRIND_VALGRIND_H
if (shutdown_verb) {
switch (log_get_target()) {
case LOG_TARGET_KMSG:
case LOG_TARGET_NULL:
case LOG_TARGET_CONSOLE:
if (log_get_show_color())
if (log_get_show_location())
watchdog_close(r < 0);
watchdog_close(true);
if (detect_container() <= 0)
if (error_message)
return retval;