main.c revision 1de1c9c37bb58d99c3f9d86f50212e641a2948b4
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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 SystemdRunningAs arg_running_as = _SYSTEMD_RUNNING_AS_INVALID;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_dump_core = true;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic bool arg_crash_shell = 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_drop = 0;
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 void pager_open_if_enabled(void) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* Pass this on immediately, if this is not PID 1 */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* We want to wait for the core process, hence let's enable SIGCHLD */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen else if (pid == 0) {
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen /* Enable default signal handler for core dump */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Don't limit the core dump size */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Just to be sure... */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Raise the signal again */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert_not_reached("We shouldn't be here...");
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Order things nicely. */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt log_error("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_info("Executing crash shell in 10s...");
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Let the kernel reap children for us */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_error("Failed to fork off crash shell: %m");
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering else if (pid == 0) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info("Successfully spawned crash shell as pid "PID_FMT".", pid);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void install_crash_handler(void) {
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poetteringstatic int console_setup(void) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to open /dev/console: %s", strerror(-tty_fd));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* We don't want to force text mode. plymouth may be showing
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * pictures already from initrd. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to reset /dev/console: %s", strerror(-r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int set_default_unit(const char *u) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmekstatic int parse_proc_cmdline_item(const char *key, const char *value) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek static const char * const rlmap[] = {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek "single", SPECIAL_RESCUE_TARGET,
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (streq(key, "systemd.unit") && value) {
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen } else if (streq(key, "rd.systemd.unit") && value) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek } else if (streq(key, "systemd.dump_core") && value) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek log_warning("Failed to parse dump core switch %s. Ignoring.", value);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek } else if (streq(key, "systemd.crash_shell") && value) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen log_warning("Failed to parse crash shell switch %s. Ignoring.", value);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen } else if (streq(key, "systemd.crash_chvt") && value) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_warning("Failed to parse crash chvt switch %s. Ignoring.", value);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek } else if (streq(key, "systemd.confirm_spawn") && value) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek log_warning("Failed to parse confirm spawn switch %s. Ignoring.", value);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering } else if (streq(key, "systemd.show_status") && value) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering r = parse_show_status(value, &arg_show_status);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering log_warning("Failed to parse show status switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.default_standard_output") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse default standard output switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.default_standard_error") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Failed to parse default standard error switch %s. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "systemd.setenv") && value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering env = strv_env_set(arg_default_environment, value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Setting environment variable '%s' failed, ignoring: %s", value, strerror(ENOMEM));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering log_warning("Environment variable name '%s' is not valid. Ignoring.", value);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (streq(key, "quiet") && !value) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (arg_show_status == _SHOW_STATUS_UNSET)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering } else if (streq(key, "debug") && !value) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering /* Note that log_parse_environment() handles 'debug'
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering * too, and sets the log level to LOG_DEBUG. */
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering /* SysV compatibility */
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering#define DEFINE_SETTER(name, func, descr) \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering const char *lvalue, \
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const char *rvalue, \
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, -r, \
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart PoetteringDEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level")
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart PoetteringDEFINE_SETTER(config_parse_target, log_set_target_from_string, "target")
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart PoetteringDEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" )
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart PoetteringDEFINE_SETTER(config_parse_location, log_show_location_from_string, "location")
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering FOREACH_WORD_QUOTED(word, l, rvalue, state) {
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, -r,
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek "Failed to parse CPU affinity '%s'", rvalue);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, EINVAL,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "Trailing garbage, ignoring.");
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen log_warning_unit(unit, "Failed to set CPU affinity: %m");
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek k = parse_show_status(rvalue, b);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, -k,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "Failed to parse show status setting, ignoring: %s", rvalue);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersenstatic void strv_free_free(char ***l) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen for (i = l; *i; i++)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic void free_join_controllers(void) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekstatic int config_parse_join_controllers(const char *unit,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek FOREACH_WORD_QUOTED(word, length, rvalue, state) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen for (a = arg_join_controllers; *a; a++) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (strv_extend_strv(&l, *a) < 0) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering "Trailing garbage, ignoring.");
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic int parse_config_file(void) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "LogLevel", config_parse_level2, 0, NULL },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "LogTarget", config_parse_target, 0, NULL },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "LogColor", config_parse_color, 0, NULL },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "LogLocation", config_parse_location, 0, NULL },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "CrashChVT", config_parse_int, 0, &arg_crash_chvt },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, NULL },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "ShutdownWatchdogSec", config_parse_sec, 0, &arg_shutdown_watchdog },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Manager", "CapabilityBoundingSet", config_parse_bounding_set, 0, &arg_capability_bounding_set_drop },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek { "Manager", "SystemCallArchitectures", config_parse_syscall_archs, 0, &arg_syscall_archs },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "Manager", "DefaultTimerAccuracySec", config_parse_sec, 0, &arg_default_timer_accuracy_usec },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultTimeoutStopSec", config_parse_sec, 0, &arg_default_timeout_stop_usec },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultRestartSec", config_parse_sec, 0, &arg_default_restart_usec },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "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 },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitCPU", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_CPU] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitFSIZE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_FSIZE] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitDATA", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_DATA] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitSTACK", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_STACK] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitCORE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_CORE] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitRSS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RSS] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitNOFILE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NOFILE] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitAS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_AS] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitNPROC", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NPROC] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitMEMLOCK", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_MEMLOCK] },
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { "Manager", "DefaultLimitLOCKS", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_LOCKS] },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultLimitSIGPENDING", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_SIGPENDING] },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultLimitMSGQUEUE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_MSGQUEUE] },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultLimitNICE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NICE] },
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering { "Manager", "DefaultLimitRTPRIO", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTPRIO] },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultLimitRTTIME", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTTIME] },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_default_cpu_accounting },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering fn = arg_running_as == SYSTEMD_SYSTEM ? PKGSYSCONFDIR "/system.conf" : PKGSYSCONFDIR "/user.conf";
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek config_item_table_lookup, items,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek false, false, true, NULL);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmekstatic int parse_argv(int argc, char *argv[]) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "log-level", required_argument, NULL, ARG_LOG_LEVEL },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "log-target", required_argument, NULL, ARG_LOG_TARGET },
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering { "log-color", optional_argument, NULL, ARG_LOG_COLOR },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "unit", required_argument, NULL, ARG_UNIT },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "system", no_argument, NULL, ARG_SYSTEM },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "no-pager", no_argument, NULL, ARG_NO_PAGER },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "version", no_argument, NULL, ARG_VERSION },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "dump-core", optional_argument, NULL, ARG_DUMP_CORE },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "crash-shell", optional_argument, NULL, ARG_CRASH_SHELL },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "confirm-spawn", optional_argument, NULL, ARG_CONFIRM_SPAWN },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "deserialize", required_argument, NULL, ARG_DESERIALIZE },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "switched-root", no_argument, NULL, ARG_SWITCHED_ROOT },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "default-standard-output", required_argument, NULL, ARG_DEFAULT_STD_OUTPUT, },
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek { "default-standard-error", required_argument, NULL, ARG_DEFAULT_STD_ERROR, },
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek while ((c = getopt_long(argc, argv, "hDbsz:", options, NULL)) >= 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = log_set_max_level_from_string(optarg);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek log_error("Failed to parse log level %s.", optarg);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen log_error("Failed to parse log target %s.", optarg);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek log_error("Failed to parse log color setting %s.", optarg);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = log_show_location_from_string(optarg);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering log_error("Failed to parse log location setting %s.", optarg);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = exec_output_from_string(optarg);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek log_error("Failed to parse default standard output setting %s.", optarg);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek log_error("Failed to parse default standard error output setting %s.", optarg);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek log_error("Failed to set default unit %s: %s", optarg, strerror(-r));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek case ARG_DUMP_CONFIGURATION_ITEMS:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek arg_action = ACTION_DUMP_CONFIGURATION_ITEMS;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen log_error("Failed to parse dump core boolean %s.", optarg);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen log_error("Failed to parse crash shell boolean %s.", optarg);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_error("Failed to parse confirm spawn boolean %s.", optarg);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = parse_show_status(optarg, &arg_show_status);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_error("Failed to parse show status boolean %s.", optarg);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (r < 0 || fd < 0) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek log_error("Failed to parse deserialize option %s.", optarg);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return r < 0 ? r : -EINVAL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering log_error("Failed to open serialization fd: %m");
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Just to eat away the sysvinit kernel
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * cmdline args without getopt() error
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * messages that we'll parse in
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * parse_proc_cmdline_word() or ignore. */
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering assert_not_reached("Unhandled option code.");
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering /* Hmm, when we aren't run as init system
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering * let's complain about excess arguments */
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic int help(void) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering "Starts up and maintains the system or user services.\n\n"
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering " -h --help Show this help\n"
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering " --test Determine startup sequence, dump it and exit\n"
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering " --no-pager Do not pipe output into a pager\n"
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering " --dump-configuration-items Dump understood unit configuration items\n"
static int version(void) {
assert(m);
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) {
static const char ok[] =
if (r == -ENOENT)
"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 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;
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))
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) {
goto finish;
if (ima_setup() < 0)
goto finish;
goto finish;
goto finish;
if (!skip_setup) {
if (clock_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;
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;
if (virtualization)
if (in_initrd())
* /etc/machine-id as flag file. This allows container
if (empty_etc)
_cleanup_free_ char *t;
#ifdef HAVE_KMOD
kmod_setup();
test_mtab();
test_usr();
goto finish;
goto finish;
if (arg_syscall_archs) {
goto finish;
if (empty_etc) {
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;
pager_close();
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) {
switch (log_get_target()) {
case LOG_TARGET_KMSG:
case LOG_TARGET_CONSOLE:
if (log_get_show_color())
if (log_get_show_location())
watchdog_close(false);
watchdog_close(true);
freeze();
return retval;