main.c revision 35b8ca3aaf8cb044ad76675dfcad89e000dd4a5c
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
c343be283b7152554bac0c02493a4e1759c163f7Kay Sievers
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek/***
b3ae710c251d0ce5cf2cef63208e325497b5e323Zbigniew Jędrzejewski-Szmek This file is part of systemd.
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers Copyright 2010 Lennart Poettering
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers systemd is free software; you can redistribute it and/or modify it
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering under the terms of the GNU General Public License as published by
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2 of the License, or
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek (at your option) any later version.
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
d19e85f0d474ed1882561b458d528cbae49f640eZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
3f85ef0f05ffc51e19f86fb83a1c51e8e3cd6817Harald Hoyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering General Public License for more details.
afe3ab588a6b2992efe5a9b22ed038545ba3cdbfLennart Poettering
afea8d3853d0f76b3845729ff00e75d281f43a1bZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU General Public License
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f85857df75cfedbc0d10b8ca2400188dc8f4c22eLennart Poettering***/
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
bafb15bab99887d1b6b8a35136531bac6c3876a6Lennart Poettering#include <dbus/dbus.h>
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers
e7b4d43ec3d5eb0099a3978f98a46f3c15443b23Lennart Poettering#include <stdio.h>
58f55364fa00a6a4706df2c4a01c6967f432e531Lennart Poettering#include <errno.h>
58f55364fa00a6a4706df2c4a01c6967f432e531Lennart Poettering#include <string.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <unistd.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <sys/types.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <sys/stat.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <getopt.h>
83a1ff25e5228b0a5b2cc942fd4f964d10bb73b0Zbigniew Jędrzejewski-Szmek#include <signal.h>
6ce02c2a3a2aa888c3e074ae235d94808a165f9aLennart Poettering#include <sys/wait.h>
6ce02c2a3a2aa888c3e074ae235d94808a165f9aLennart Poettering#include <fcntl.h>
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include <sys/prctl.h>
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "manager.h"
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "log.h"
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "mount-setup.h"
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "hostname-setup.h"
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "loopback-setup.h"
477e75ef9ea6bb2e7e8cc76278c442942110f227Lennart Poettering#include "kmod-setup.h"
7dfb0404b3b6882d582a571f61a52b2f56961675Lennart Poettering#include "locale-setup.h"
7dfb0404b3b6882d582a571f61a52b2f56961675Lennart Poettering#include "selinux-setup.h"
7dfb0404b3b6882d582a571f61a52b2f56961675Lennart Poettering#include "load-fragment.h"
7dfb0404b3b6882d582a571f61a52b2f56961675Lennart Poettering#include "fdset.h"
7dfb0404b3b6882d582a571f61a52b2f56961675Lennart Poettering#include "special.h"
2bc39683c0cada86c9dc39e5f3d0ea475cf12e57Lennart Poettering#include "conf-parser.h"
2bc39683c0cada86c9dc39e5f3d0ea475cf12e57Lennart Poettering#include "bus-errors.h"
2bc39683c0cada86c9dc39e5f3d0ea475cf12e57Lennart Poettering#include "missing.h"
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering#include "label.h"
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering#include "build.h"
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering#include "strv.h"
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poetteringstatic enum {
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering ACTION_RUN,
2bc39683c0cada86c9dc39e5f3d0ea475cf12e57Lennart Poettering ACTION_HELP,
2bc39683c0cada86c9dc39e5f3d0ea475cf12e57Lennart Poettering ACTION_TEST,
687f6a0ba77872299b9fb1f2f04d31c977088a63Lennart Poettering ACTION_DUMP_CONFIGURATION_ITEMS,
31a11e8f30449a81867e8fd081e3e76cf6664bb4Lennart Poettering ACTION_DONE
31a11e8f30449a81867e8fd081e3e76cf6664bb4Lennart Poettering} arg_action = ACTION_RUN;
dbdee28bfadd6d8bd93cb34c85ce1fc325dd8120Lennart Poettering
dbdee28bfadd6d8bd93cb34c85ce1fc325dd8120Lennart Poetteringstatic char *arg_default_unit = NULL;
17fe56148c44dfa5583a8643c1918fd6eccf2aeeLennart Poetteringstatic ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
17fe56148c44dfa5583a8643c1918fd6eccf2aeeLennart Poettering
17fe56148c44dfa5583a8643c1918fd6eccf2aeeLennart Poetteringstatic bool arg_dump_core = true;
17fe56148c44dfa5583a8643c1918fd6eccf2aeeLennart Poetteringstatic bool arg_crash_shell = false;
7687f85ea6bab434324bb985e2898bf6373891bfLennart Poetteringstatic int arg_crash_chvt = -1;
7687f85ea6bab434324bb985e2898bf6373891bfLennart Poetteringstatic bool arg_confirm_spawn = false;
7687f85ea6bab434324bb985e2898bf6373891bfLennart Poetteringstatic bool arg_show_status = true;
7687f85ea6bab434324bb985e2898bf6373891bfLennart Poettering#ifdef HAVE_SYSV_COMPAT
02c74033ed65e7825d1b87ee051820c9fbfa0f50Lennart Poetteringstatic bool arg_sysv_console = true;
02c74033ed65e7825d1b87ee051820c9fbfa0f50Lennart Poettering#endif
c14db9b32ab90738973071d31f259d1a457d7b4aLennart Poetteringstatic bool arg_mount_auto = true;
c14db9b32ab90738973071d31f259d1a457d7b4aLennart Poetteringstatic bool arg_swap_auto = true;
fa607802f332e06f4044c3eb38dbea41076c803dLennart Poetteringstatic char **arg_default_controllers = NULL;
fa607802f332e06f4044c3eb38dbea41076c803dLennart Poetteringstatic ExecOutput arg_default_std_output = EXEC_OUTPUT_INHERIT;
cc98b3025eeb89addb76a27390cb2baca4eab8b9Torstein Husebøstatic ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
a47e6701bfc45519a4e038daa52e9236e932f59aLennart Poettering
fa607802f332e06f4044c3eb38dbea41076c803dLennart Poetteringstatic FILE* serialization = NULL;
a47e6701bfc45519a4e038daa52e9236e932f59aLennart Poettering
92ff080be100aff15f292e2631921131c610afe7Lennart Poetteringstatic void nop_handler(int sig) {
b80c66ba9836456de5260e4a1b696ba25561f613Lennart Poettering}
bd69054b0987b40a0df87d40772893f6f8a078daLennart Poettering
bd69054b0987b40a0df87d40772893f6f8a078daLennart Poettering_noreturn_ static void crash(int sig) {
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering if (!arg_dump_core)
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering else {
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering struct sigaction sa;
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering pid_t pid;
de146bb2aac13361ade3050d37696499ac4ca9aeLennart Poettering
de146bb2aac13361ade3050d37696499ac4ca9aeLennart Poettering /* We want to wait for the core process, hence let's enable SIGCHLD */
358ba19e5e18304258f053e30e6120a3b6adf322Lennart Poettering zero(sa);
358ba19e5e18304258f053e30e6120a3b6adf322Lennart Poettering sa.sa_handler = nop_handler;
91f4347ef7bde17418b365ed3a97a752fe65bd50Lennart Poettering sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
358ba19e5e18304258f053e30e6120a3b6adf322Lennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
de146bb2aac13361ade3050d37696499ac4ca9aeLennart Poettering
de146bb2aac13361ade3050d37696499ac4ca9aeLennart Poettering if ((pid = fork()) < 0)
5b728e6ba17c39e0787ad81b96a5582f4390f091Lennart Poettering log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
5b728e6ba17c39e0787ad81b96a5582f4390f091Lennart Poettering
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering else if (pid == 0) {
c3a0d00d6dd6f5997d673e133ef6f9f856550b0aLennart Poettering struct rlimit rl;
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering
82e6c50c473f4be8df77c7a510577f1975eedddbLennart Poettering /* Enable default signal handler for core dump */
d2f81fb00cc3c49e21b31000ba7d37b81a260257Lennart Poettering zero(sa);
d2f81fb00cc3c49e21b31000ba7d37b81a260257Lennart Poettering sa.sa_handler = SIG_DFL;
98cd2651988619bf606f0b27825440c4638a7e0bLennart Poettering assert_se(sigaction(sig, &sa, NULL) == 0);
b7307642391c8ebb9724c99e6b33239e2c0ff944Lennart Poettering
b7307642391c8ebb9724c99e6b33239e2c0ff944Lennart Poettering /* Don't limit the core dump size */
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering zero(rl);
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering rl.rlim_cur = RLIM_INFINITY;
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering rl.rlim_max = RLIM_INFINITY;
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering setrlimit(RLIMIT_CORE, &rl);
2a441c8afe7c81f74cc2ceccdf9a71301cd39d4dLennart Poettering
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering /* Just to be sure... */
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering assert_se(chdir("/") == 0);
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering
40ff4a4abd76d71408e598ed02d7860b8465fa9aLennart Poettering /* Raise the signal again */
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering raise(sig);
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering
f131770b1465fbf423881f16ba85523a05f846feVeres Lajos assert_not_reached("We shouldn't be here...");
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering _exit(1);
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering } else {
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering siginfo_t status;
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering int r;
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering /* Order things nicely. */
0a86c1a9d8066267b878dfeddc5e0087dda6a37bLennart Poettering if ((r = wait_for_terminate(pid, &status)) < 0)
41114e81b562bcee52be1ef94c684ace2362ca54Lennart Poettering log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
41114e81b562bcee52be1ef94c684ace2362ca54Lennart Poettering else if (status.si_code != CLD_DUMPED)
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering else
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid);
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering }
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering }
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering
e3286870fdf20c3c93e944b24fd9af53620f7dbaLennart Poettering if (arg_crash_chvt)
a195cbad3796dfda3d1016e4819c612c859e3c7bLennart Poettering chvt(arg_crash_chvt);
a195cbad3796dfda3d1016e4819c612c859e3c7bLennart Poettering
8514b67754c5ff7fa628929b3d27131010c21842Lennart Poettering if (arg_crash_shell) {
8514b67754c5ff7fa628929b3d27131010c21842Lennart Poettering struct sigaction sa;
6c78f43c7b0e54e695af49917fda79b584f46830Lennart Poettering pid_t pid;
6c78f43c7b0e54e695af49917fda79b584f46830Lennart Poettering
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering log_info("Executing crash shell in 10s...");
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering sleep(10);
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering /* Let the kernel reap children for us */
7b0fce617c48eda32b2d4e04b5f0e4376e8c0106Lennart Poettering zero(sa);
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering sa.sa_handler = SIG_IGN;
c2d5b3c94d0c082ef29597fb230f8b88b124bab8Lennart Poettering sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART;
264b8070715d2d19344c4991ace21147d998f56dLennart Poettering assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
264b8070715d2d19344c4991ace21147d998f56dLennart Poettering
4ecd22142543aac55ddac1da3b7d6882c009d637Lennart Poettering if ((pid = fork()) < 0)
4ecd22142543aac55ddac1da3b7d6882c009d637Lennart Poettering log_error("Failed to fork off crash shell: %s", strerror(errno));
7e27f3121e5a10629302b5221eb21345f832724aLennart Poettering else if (pid == 0) {
7e27f3121e5a10629302b5221eb21345f832724aLennart Poettering int fd, r;
f81e67f79fa856aa2ecffad4d014772ce981745cLennart Poettering
f81e67f79fa856aa2ecffad4d014772ce981745cLennart Poettering if ((fd = acquire_terminal("/dev/console", false, true, true)) < 0)
d48b7bd271b1e70924c8485d2f95c2f5a1ae77cbLennart Poettering log_error("Failed to acquire terminal: %s", strerror(-fd));
d48b7bd271b1e70924c8485d2f95c2f5a1ae77cbLennart Poettering else if ((r = make_stdio(fd)) < 0)
25e14499c4c5b02229d05a5bc26c3693ade5f987Lennart Poettering log_error("Failed to duplicate terminal fd: %s", strerror(-r));
25e14499c4c5b02229d05a5bc26c3693ade5f987Lennart Poettering
758c4d7a391c0e024737053c815bf3924653b8c5Lennart Poettering execl("/bin/sh", "/bin/sh", NULL);
758c4d7a391c0e024737053c815bf3924653b8c5Lennart Poettering
821cc13ddae40fb7608458b44aaa7a3fd33d56d9Lennart Poettering log_error("execl() failed: %s", strerror(errno));
821cc13ddae40fb7608458b44aaa7a3fd33d56d9Lennart Poettering _exit(1);
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering }
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering log_info("Successfully spawned crash shall as pid %lu.", (unsigned long) pid);
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering }
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering log_info("Freezing execution.");
8483d73ff158ee0d51ccbba09a470cc6ae9b071aLennart Poettering freeze();
25e773eeb4f853804e1bf0dbd9a184f23e9b2a97Kay Sievers}
b857e042d621ffb98a652f33850b431fafbece43Lennart Poettering
6dab5bb18151c80fc39bd51f03dcff40b920de3eLennart Poetteringstatic void install_crash_handler(void) {
6dab5bb18151c80fc39bd51f03dcff40b920de3eLennart Poettering struct sigaction sa;
384a4be2b00cb95ce215dd343cc9aa77adc9b1ecLennart Poettering
384a4be2b00cb95ce215dd343cc9aa77adc9b1ecLennart Poettering zero(sa);
706d97503df83d141d241b645d2c920d691b3d62Lennart Poettering
706d97503df83d141d241b645d2c920d691b3d62Lennart Poettering sa.sa_handler = crash;
3bcde97e8502c48b53f7420e2433ca68e601662dLennart Poettering sa.sa_flags = SA_NODEFER;
3bcde97e8502c48b53f7420e2433ca68e601662dLennart Poettering
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poettering sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poettering}
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
533bb267f13e2f7b4d7b78de30e821dc81c82335Lennart Poetteringstatic int console_setup(bool do_reset) {
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek int tty_fd, r;
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek /* If we are init, we connect stdin/stdout/stderr to /dev/null
b42de08aa4c97636e42c28c7bce08f0d7c2a719aZbigniew Jędrzejewski-Szmek * and make sure we don't have a controlling tty. */
202aea456dfb279cd34da7bfd1880f6ac0fd849fLennart Poettering
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering release_terminal();
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering if (!do_reset)
42aeb14a4a0fa7d43da96a8ed0fb0e180a2dd5c8Lennart Poettering return 0;
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering if ((tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0) {
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering log_error("Failed to open /dev/console: %s", strerror(-tty_fd));
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering return -tty_fd;
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering }
14a32924c9b46817c92ae11c1147a59dcb62012bLennart Poettering
563b1bdc09efe0cf94dd3f514f30376ca854c1ceLennart Poettering if ((r = reset_terminal(tty_fd)) < 0)
563b1bdc09efe0cf94dd3f514f30376ca854c1ceLennart Poettering log_error("Failed to reset /dev/console: %s", strerror(-r));
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poettering
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poettering close_nointr_nofail(tty_fd);
5dcf983854c2e8314dbee239180255490ec8ae1cLennart Poettering return r;
b873d33ec9583c92a0c2bc6807d010720fa31595Lennart Poettering}
d61bb44a89fde3042c7c15ea4975239f7dcb0cb0Lennart Poettering
ed220efd6657822332b9563ec53c5ab9f3c33220Lennart Poetteringstatic int set_default_unit(const char *u) {
ed220efd6657822332b9563ec53c5ab9f3c33220Lennart Poettering char *c;
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering assert(u);
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering if (!(c = strdup(u)))
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering return -ENOMEM;
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering free(arg_default_unit);
41488fe9024a8955d19811620fd55dcc56a5b2baLennart Poettering arg_default_unit = c;
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering return 0;
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering}
ca70bec9261977336c94f44d5fcf37e1c495326aLennart Poettering
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poetteringstatic int parse_proc_cmdline_word(const char *word) {
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering
157a180e4fc827606833a6724834ba7b0246d650Tom Gundersen static const char * const rlmap[] = {
157a180e4fc827606833a6724834ba7b0246d650Tom Gundersen "emergency", SPECIAL_EMERGENCY_TARGET,
b873d33ec9583c92a0c2bc6807d010720fa31595Lennart Poettering "single", SPECIAL_RESCUE_TARGET,
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering "-s", SPECIAL_RESCUE_TARGET,
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering "s", SPECIAL_RESCUE_TARGET,
1dbe0a6efda7b1d35957eab7e1d56a2c69d806d9Lennart Poettering "S", SPECIAL_RESCUE_TARGET,
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering "1", SPECIAL_RESCUE_TARGET,
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "2", SPECIAL_RUNLEVEL2_TARGET,
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "3", SPECIAL_RUNLEVEL3_TARGET,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "4", SPECIAL_RUNLEVEL4_TARGET,
23c4091dc2b85d117512e89233fdeb47d1ff3d92Lennart Poettering "5", SPECIAL_RUNLEVEL5_TARGET,
23c4091dc2b85d117512e89233fdeb47d1ff3d92Lennart Poettering };
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering
0f47ed0a052c0da743404f23ac3532aaabd23655Lennart Poettering assert(word);
9d6db739ce1eaa3eace21801fd606d523b73c8f4Lennart Poettering
bc07548926ec5ed7b13df8d3656654f238e0b9a7Lennart Poettering if (startswith(word, "systemd.unit="))
bc07548926ec5ed7b13df8d3656654f238e0b9a7Lennart Poettering return set_default_unit(word + 13);
b6b63571ae3eca1741d54172922961af972b8f20Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering else if (startswith(word, "systemd.log_target=")) {
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
3f77a1b19f5a8ce33566f7f6e28e94c08ea30841Kay Sievers if (log_set_target_from_string(word + 19) < 0)
e2a69298819b58f008be61d314f8ab95ccaec427Lennart Poettering log_warning("Failed to parse log target %s. Ignoring.", word + 19);
e2a69298819b58f008be61d314f8ab95ccaec427Lennart Poettering
2834ffe78d7fd8be118429aa1449ac72641638c2Lennart Poettering } else if (startswith(word, "systemd.log_level=")) {
2834ffe78d7fd8be118429aa1449ac72641638c2Lennart Poettering
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering if (log_set_max_level_from_string(word + 18) < 0)
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering log_warning("Failed to parse log level %s. Ignoring.", word + 18);
a01647e53727107d82382bc5c9d98c894e8f386cLennart Poettering
3c779fa59d1825d7db2a9516669d34ded7916913Lennart Poettering } else if (startswith(word, "systemd.log_color=")) {
a940778fb1dd16479f455bab3ac6cbdbc5b06165Lennart Poettering
a01647e53727107d82382bc5c9d98c894e8f386cLennart Poettering if (log_show_color_from_string(word + 18) < 0)
3de03738fc970496d2d3da668c72767a48ccc41bLennart Poettering log_warning("Failed to parse log color setting %s. Ignoring.", word + 18);
3de03738fc970496d2d3da668c72767a48ccc41bLennart Poettering
2b1c3767515672dfd0f5e0a9c9d7ac3a16a6a361Lennart Poettering } else if (startswith(word, "systemd.log_location=")) {
2b1c3767515672dfd0f5e0a9c9d7ac3a16a6a361Lennart Poettering
37efac5ddb21fd91ed420c070ed07f375e78b3b9Lennart Poettering if (log_show_location_from_string(word + 21) < 0)
37efac5ddb21fd91ed420c070ed07f375e78b3b9Lennart Poettering log_warning("Failed to parse log location setting %s. Ignoring.", word + 21);
7348b3adb324614132cf376f478e883bd7de28f1Lennart Poettering
7348b3adb324614132cf376f478e883bd7de28f1Lennart Poettering } else if (startswith(word, "systemd.dump_core=")) {
e107ed185ef08945102834234a05ec51bb438685Lennart Poettering int r;
e107ed185ef08945102834234a05ec51bb438685Lennart Poettering
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers if ((r = parse_boolean(word + 18)) < 0)
81429136905a6204875174b60a179333b7f3c9e4Kay Sievers log_warning("Failed to parse dump core switch %s, Ignoring.", word + 18);
e107ed185ef08945102834234a05ec51bb438685Lennart Poettering else
f598ac3e28b729dd0b1d0a881df3e16465687a2bLennart Poettering arg_dump_core = r;
11fb37f16ed99c1603c9d770b60ce4953b96a58dLennart Poettering
01083ad094664e5c685060f4fb35a05ea2f212edLennart Poettering } else if (startswith(word, "systemd.crash_shell=")) {
01083ad094664e5c685060f4fb35a05ea2f212edLennart Poettering int r;
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering
edb2935c5c5b95c42b8679086f60da5eafad74cbLennart Poettering if ((r = parse_boolean(word + 20)) < 0)
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering log_warning("Failed to parse crash shell switch %s, Ignoring.", word + 20);
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering else
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering arg_crash_shell = r;
769918ecd30c0f7ee6e87b9aa6226d956bd2f530Lennart Poettering
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering } else if (startswith(word, "systemd.confirm_spawn=")) {
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poettering int r;
2a781fc9bd33982c81e5ff75974a442a33d4f167Lennart Poettering
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering if ((r = parse_boolean(word + 22)) < 0)
6a3f892a23db71544d0439355f96c44350dafa8fLennart Poettering log_warning("Failed to parse confirm spawn switch %s, Ignoring.", word + 22);
650264033f2f98f6319513958d94d59078654af8Lennart Poettering else
650264033f2f98f6319513958d94d59078654af8Lennart Poettering arg_confirm_spawn = r;
650264033f2f98f6319513958d94d59078654af8Lennart Poettering
f8901862b2b030921b3d5aba4157044ceab16451Lennart Poettering } else if (startswith(word, "systemd.crash_chvt=")) {
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering int k;
eda8f06755bd98c4639293c26b856c225f0d1fe1Lennart Poettering
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering if (safe_atoi(word + 19, &k) < 0)
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering log_warning("Failed to parse crash chvt switch %s, Ignoring.", word + 19);
d4fdc205a4610965cee46408dbd046c922e7620cLennart Poettering else
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering arg_crash_chvt = k;
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering } else if (startswith(word, "systemd.show_status=")) {
af1082b04a3d45a9b1d796b4271f44e87e307026Lennart Poettering int r;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering if ((r = parse_boolean(word + 20)) < 0)
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering log_warning("Failed to parse show status switch %s, Ignoring.", word + 20);
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering else
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering arg_show_status = r;
488ad3b32a7e2b5b1380abf4a15e5f65fa65f3feLennart Poettering } else if (startswith(word, "systemd.default_standard_output=")) {
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering int r;
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering if ((r = exec_output_from_string(word + 32)) < 0)
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering log_warning("Failed to parse default standard output switch %s, Ignoring.", word + 32);
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering else
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering arg_default_std_output = r;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering } else if (startswith(word, "systemd.default_standard_error=")) {
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering int r;
09ecd746c9d6581664873674c2188f8c93ed7780Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if ((r = exec_output_from_string(word + 31)) < 0)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_warning("Failed to parse default standard error switch %s, Ignoring.", word + 31);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering else
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering arg_default_std_error = r;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#ifdef HAVE_SYSV_COMPAT
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering } else if (startswith(word, "systemd.sysv_console=")) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering int r;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
0bee65f0622c4faa8ac8ae771cc0c8a936dfa284Lennart Poettering if ((r = parse_boolean(word + 21)) < 0)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_warning("Failed to parse SysV console switch %s, Ignoring.", word + 20);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering else
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering arg_sysv_console = r;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering#endif
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering } else if (startswith(word, "systemd.")) {
47c94a96df29080f8b3a97e7362df4e9c6ba3265Lennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poettering log_warning("Unknown kernel switch %s. Ignoring.", word);
718db96199eb307751264e4163555662c9a389faLennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_info("Supported kernel switches:\n"
718db96199eb307751264e4163555662c9a389faLennart Poettering "systemd.unit=UNIT Default unit to start\n"
718db96199eb307751264e4163555662c9a389faLennart Poettering "systemd.dump_core=0|1 Dump core on crash\n"
718db96199eb307751264e4163555662c9a389faLennart Poettering "systemd.crash_shell=0|1 Run shell on crash\n"
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering "systemd.crash_chvt=N Change to VT #N on crash\n"
966204e010ed432a1d7a0481d41a326d8ec7b0c8Lennart Poettering "systemd.confirm_spawn=0|1 Confirm every process spawn\n"
94676f3e9352cbf1f72e0a512ee0d2ed83ff676dLennart Poettering "systemd.show_status=0|1 Show status updates on the console during bootup\n"
6fd4d0209827e5c3e52fa8c7144852f550f8f95cLennart Poettering#ifdef HAVE_SYSV_COMPAT
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poettering "systemd.sysv_console=0|1 Connect output of SysV scripts to console\n"
416446221d905b6815175dc4d525d27f8ae43d1bLennart Poettering#endif
7f79cd7109a60810140a045cc725291fc5515264Lennart Poettering "systemd.log_target=console|kmsg|syslog|syslog-or-kmsg|null\n"
0aafd43d235982510d1c40564079f7bcec0c7c19Lennart Poettering " Log target\n"
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardt "systemd.log_level=LEVEL Log level\n"
19aadacf92ad86967ffb678e37b2ff9e83cb9480Jan Engelhardt "systemd.log_color=0|1 Highlight important log messages\n"
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering "systemd.log_location=0|1 Include code location in log messages\n"
df5f6971e6e15b4632884916c71daa076c8bae96Lennart Poettering "systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poettering " Set default log output for services\n"
fcba531ed4c6e6f8f21d8ca4e3a56e3162b1c578Lennart Poettering "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
6aaa8c2f783cd1b3ac27c5ce40625d032e7e3d71Zbigniew Jędrzejewski-Szmek " Set default log error output for services\n");
c3bb87dbab8b79bb9253407cb5b7f3e6fe8db395Lennart Poettering
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt } else if (streq(word, "quiet")) {
18d4e7c26e7806ac363d19989df7144d5058ce41Lennart Poettering arg_show_status = false;
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering#ifdef HAVE_SYSV_COMPAT
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering arg_sysv_console = false;
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering#endif
bdeeb6b543a2a2d0a494f17b85f1498859cdfc2fLennart Poettering } else {
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering unsigned i;
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering
4e09014daf8f98584b3f15e64e93bed232e70a6bLennart Poettering /* SysV compatibility */
6bb648a16ae4a682ad4784412af706d2e6a3e4daTom Gundersen for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
fa607802f332e06f4044c3eb38dbea41076c803dLennart Poettering if (streq(word, rlmap[i]))
d0928791499734e202460d5c027b5d3e0d28e7abLennart Poettering return set_default_unit(rlmap[i+1]);
7212c6083a5577eabc96c35c9db4c19c113cae93Lennart Poettering }
1f140dd8b048c5f5599a886b8c4d20f3f1065774David Herrmann
57f2a947270faf65e1876797b930e3f6d60ebd06Lennart Poettering return 0;
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt}
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringstatic int config_parse_level(
dc17bcef197a0d5ee798cce59c40e4f5e85c24f6Lennart Poettering const char *filename,
80caea6cc72ebd311a311b1527cc6b87201c13bfLennart Poettering unsigned line,
ab9716c2489f9141ed13ec22dbb216b3e6fbd6b5Lennart Poettering const char *section,
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering const char *lvalue,
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering const char *rvalue,
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering void *data,
df98a87ba389bdfc0359beedf47557411f3af434Lennart Poettering void *userdata) {
2ecfc64e59b5e4e96bed6f68bd36b612ef77a146Lennart Poettering
6a8b5fa4635ed858788fb10099ec9b62b3359a0aLennart Poettering assert(filename);
69727e6dc69ae5d9b5ae3681723778a3faa354e9Lennart Poettering assert(lvalue);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering assert(rvalue);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering log_set_max_level_from_string(rvalue);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return 0;
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering}
0ad68f8743f3baaa7cd8ac7a2275459ae0f7b96aLennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringstatic int config_parse_target(
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering const char *filename,
12179984a38fe74581333fbcdc11c822d81f505fLennart Poettering unsigned line,
0536ce5d0ceaf87f3e81faaff41d69ffeed2186fZbigniew Jędrzejewski-Szmek const char *section,
eb01ba5de14859d7a94835ab9299de40132d549aLennart Poettering const char *lvalue,
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering const char *rvalue,
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering void *data,
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering void *userdata) {
154ff088d371bee5651eaa2bc9bde8a34c185656Lennart Poettering
69af45035913e7119cffd94c542bd3039600e45dZbigniew Jędrzejewski-Szmek assert(filename);
e8a7a315391a6a07897122725cd707f4e9ce63d7Lennart Poettering assert(lvalue);
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering assert(rvalue);
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering log_set_target_from_string(rvalue);
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering return 0;
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering}
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poetteringstatic int config_parse_color(
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering const char *filename,
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned line,
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering const char *section,
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering const char *lvalue,
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek const char *rvalue,
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek void *data,
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek void *userdata) {
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering assert(filename);
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt assert(lvalue);
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering assert(rvalue);
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering log_show_color_from_string(rvalue);
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering return 0;
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering}
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poetteringstatic int config_parse_location(
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering const char *filename,
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering unsigned line,
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering const char *section,
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering const char *lvalue,
c144692179098c1861f2aeafc67689a74439cf4cLennart Poettering const char *rvalue,
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering void *data,
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering void *userdata) {
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering assert(filename);
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering assert(lvalue);
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering assert(rvalue);
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering
54c31a79f72ff57ac8eba089acacc4ab482b745dLennart Poettering log_show_location_from_string(rvalue);
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering return 0;
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering}
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poetteringstatic int config_parse_cpu_affinity(
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering const char *filename,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned line,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering const char *section,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering const char *lvalue,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering const char *rvalue,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering void *data,
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering void *userdata) {
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering char *w;
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering size_t l;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering char *state;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering cpu_set_t *c = NULL;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering unsigned ncpus = 0;
466784c8710e5cb0e0b86a16506d992d7ec5b619Kay Sievers
e41814846c19a48f4490169d82e359e005c4db45Lennart Poettering assert(filename);
c0fe5db522b52f27e030655ce2c03e05cbbc1558Kay Sievers assert(lvalue);
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering assert(rvalue);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering FOREACH_WORD_QUOTED(w, l, rvalue, state) {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering char *t;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering int r;
3040728b6691ea2e9df3a2060e2d49a792bbaedaLennart Poettering unsigned cpu;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
8ed206517c2be381324ac5832bf34cc14024270eLennart Poettering if (!(t = strndup(w, l)))
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return -ENOMEM;
e6c6e7afffa80ad74efdb1ddfa815294624f1608Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering r = safe_atou(t, &cpu);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering free(t);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering if (!c)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering if (!(c = cpu_set_malloc(&ncpus)))
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return -ENOMEM;
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if (r < 0 || cpu >= ncpus) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering CPU_FREE(c);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering return -EBADMSG;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering }
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering }
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering if (c) {
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering log_warning("Failed to set CPU affinity: %m");
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering CPU_FREE(c);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering }
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return 0;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering}
b568ef14a75dffb7182e0acbdec743b31df2a597Lennart Poettering
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poetteringstatic DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poetteringstatic int parse_config_file(void) {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering const ConfigItem items[] = {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "LogLevel", config_parse_level, NULL, "Manager" },
57f2a947270faf65e1876797b930e3f6d60ebd06Lennart Poettering { "LogTarget", config_parse_target, NULL, "Manager" },
c06bf414042cd1bf94e0af63e9e2a0c291bfc546Kay Sievers { "LogColor", config_parse_color, NULL, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "LogLocation", config_parse_location, NULL, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "DumpCore", config_parse_bool, &arg_dump_core, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" },
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt { "ShowStatus", config_parse_bool, &arg_show_status, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#ifdef HAVE_SYSV_COMPAT
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "SysVConsole", config_parse_bool, &arg_sysv_console, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#endif
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "DefaultControllers", config_parse_strv, &arg_default_controllers, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "DefaultStandardOutput", config_parse_output, &arg_default_std_output, "Manager" },
f47ec8ebb3858553dec870e1c596e39525f46360Lennart Poettering { "DefaultStandardError", config_parse_output, &arg_default_std_error, "Manager" },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { NULL, NULL, NULL, NULL }
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering };
038cf33420afa5f913fe5cbf3e7138574c33d97bZbigniew Jędrzejewski-Szmek
038cf33420afa5f913fe5cbf3e7138574c33d97bZbigniew Jędrzejewski-Szmek static const char * const sections[] = {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering "Manager",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering NULL
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering };
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering FILE *f;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering const char *fn;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering int r;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
601d9d6fb394a780765e80581daab850623e9698Josh Triplett fn = arg_running_as == MANAGER_SYSTEM ? SYSTEM_CONFIG_FILE : USER_CONFIG_FILE;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if (!(f = fopen(fn, "re"))) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if (errno == ENOENT)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering return 0;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_warning("Failed to open configuration file '%s': %m", fn);
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering return 0;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering }
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt if ((r = config_parse(fn, f, sections, items, false, NULL)) < 0)
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering log_warning("Failed to parse configuration file: %s", strerror(-r));
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering fclose(f);
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering return 0;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering}
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering
279f036675536d55c901562b49f9df146af1a0e3Lennart Poetteringstatic int parse_proc_cmdline(void) {
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering char *line, *w, *state;
279f036675536d55c901562b49f9df146af1a0e3Lennart Poettering int r;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering size_t l;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
8b8f259170e35b93e6c6d1757cb8b835bbdaa40cZbigniew Jędrzejewski-Szmek if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering }
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering FOREACH_WORD_QUOTED(w, l, line, state) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering char *word;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering if (!(word = strndup(w, l))) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering r = -ENOMEM;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering goto finish;
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering }
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering r = parse_proc_cmdline_word(word);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering free(word);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering if (r < 0)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering goto finish;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering }
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering r = 0;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringfinish:
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt free(line);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return r;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering enum {
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering ARG_LOG_LEVEL = 0x100,
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering ARG_LOG_TARGET,
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering ARG_LOG_COLOR,
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering ARG_LOG_LOCATION,
8b04b925e587ff56568c62ff5ad3f2ea2b34ca7aLennart Poettering ARG_UNIT,
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering ARG_SYSTEM,
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering ARG_USER,
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering ARG_TEST,
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering ARG_DUMP_CONFIGURATION_ITEMS,
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering ARG_DUMP_CORE,
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering ARG_CRASH_SHELL,
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt ARG_CONFIRM_SPAWN,
90e071d1d59be05fcba66561439c3ca67c80ee20Lennart Poettering ARG_SHOW_STATUS,
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers ARG_SYSV_CONSOLE,
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering ARG_DESERIALIZE,
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering ARG_INTROSPECT,
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering ARG_DEFAULT_STD_OUTPUT,
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering ARG_DEFAULT_STD_ERROR
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering };
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering static const struct option options[] = {
603cd8fe07cb03e8b11722d1a732e569e5a46347Lennart Poettering { "log-level", required_argument, NULL, ARG_LOG_LEVEL },
a7a3f28be404875eff20443a0fa8088bcc4c18dfLennart Poettering { "log-target", required_argument, NULL, ARG_LOG_TARGET },
a7a3f28be404875eff20443a0fa8088bcc4c18dfLennart Poettering { "log-color", optional_argument, NULL, ARG_LOG_COLOR },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
08f9588885c5d65694b324846b0ed19211d2c178Lennart Poettering { "unit", required_argument, NULL, ARG_UNIT },
9ee58bddeb6eb044753167e0047fe836479ca5dbKay Sievers { "system", no_argument, NULL, ARG_SYSTEM },
9ee58bddeb6eb044753167e0047fe836479ca5dbKay Sievers { "user", no_argument, NULL, ARG_USER },
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering { "test", no_argument, NULL, ARG_TEST },
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering { "help", no_argument, NULL, 'h' },
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering { "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt { "dump-core", no_argument, NULL, ARG_DUMP_CORE },
1b89884ba31cbe98f159ce2c7d6fac5f6a57698fLennart Poettering { "crash-shell", no_argument, NULL, ARG_CRASH_SHELL },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "confirm-spawn", no_argument, NULL, ARG_CONFIRM_SPAWN },
9cb74bcb23dde8488459ca233bf9caee642b8402Zbigniew Jędrzejewski-Szmek { "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#ifdef HAVE_SYSV_COMPAT
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "sysv-console", optional_argument, NULL, ARG_SYSV_CONSOLE },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#endif
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "deserialize", required_argument, NULL, ARG_DESERIALIZE },
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering { "introspect", optional_argument, NULL, ARG_INTROSPECT },
5f1dac6bf605871615b35891a3966fa474db5b20Lennart Poettering { "default-standard-output", required_argument, NULL, ARG_DEFAULT_STD_OUTPUT, },
f801968466fed39d50d410b30ac828c26722cc95Lennart Poettering { "default-standard-error", required_argument, NULL, ARG_DEFAULT_STD_ERROR, },
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering { NULL, 0, NULL, 0 }
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering };
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering int c, r;
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering assert(argc >= 1);
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering assert(argv);
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poettering
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poettering while ((c = getopt_long(argc, argv, "hD", options, NULL)) >= 0)
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering switch (c) {
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering case ARG_LOG_LEVEL:
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering if ((r = log_set_max_level_from_string(optarg)) < 0) {
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poettering log_error("Failed to parse log level %s.", optarg);
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering return r;
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering }
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering break;
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering case ARG_LOG_TARGET:
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poettering
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering if ((r = log_set_target_from_string(optarg)) < 0) {
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering log_error("Failed to parse log target %s.", optarg);
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering return r;
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering }
88a6c5894c9d3f85d63b87b040c130366b4006ceKay Sievers
8351ceaea9480d9c2979aa2ff0f4982cfdfef58dLennart Poettering break;
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt case ARG_LOG_COLOR:
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering if (optarg) {
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering if ((r = log_show_color_from_string(optarg)) < 0) {
59cea26a349cfa8db906b520dac72563dd773ff2Lennart Poettering log_error("Failed to parse log color setting %s.", optarg);
35eb6b124ebdf82bd77aad6e44962a9a039c4d33Lennart Poettering return r;
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering }
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering } else
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers log_show_color(true);
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers break;
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers case ARG_LOG_LOCATION:
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers if (optarg) {
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers if ((r = log_show_location_from_string(optarg)) < 0) {
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers log_error("Failed to parse log location setting %s.", optarg);
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers return r;
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering }
e01a15b71e18bf2008aec7e75041ffa42eb80b80Kay Sievers } else
a888b352eb53b07daa24fa859ceeb254336b293dLennart Poettering log_show_location(true);
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers break;
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers case ARG_DEFAULT_STD_OUTPUT:
e8d842a0d0b39f298e1e7f70d29759e50b2b16d4Tom Gundersen
b8217b7bd5fd171916a095b150fad4c3a37f5a41Kay Sievers if ((r = exec_output_from_string(optarg)) < 0) {
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering log_error("Failed to parse default standard output setting %s.", optarg);
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering return r;
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering } else
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering arg_default_std_output = r;
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering break;
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering case ARG_DEFAULT_STD_ERROR:
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering if ((r = exec_output_from_string(optarg)) < 0) {
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering log_error("Failed to parse default standard error output setting %s.", optarg);
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering return r;
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering } else
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering arg_default_std_error = r;
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering break;
70a44afee385c4afadaab9a002b3f9dd44aedf4aJan Engelhardt
65c0cf7108ae3537a357c74b4586a783baba82f9Lennart Poettering case ARG_UNIT:
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers if ((r = set_default_unit(optarg)) < 0) {
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers log_error("Failed to set default unit %s: %s", optarg, strerror(-r));
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering return r;
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering }
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering
f38afcd0c7f558ca5bf0854b42f8c6954f8ad7f3Lennart Poettering break;
614cc34f3a2a7c64a21c3f5256f2e2b2c1de1d51Zbigniew Jędrzejewski-Szmek
614cc34f3a2a7c64a21c3f5256f2e2b2c1de1d51Zbigniew Jędrzejewski-Szmek case ARG_SYSTEM:
7d441ddb5ca090b5a97f58ac4b4d97b3e84fa81eLennart Poettering arg_running_as = MANAGER_SYSTEM;
d28315e4aff91560ed4c2fc9f876ec8bfc559f2dJan Engelhardt break;
14e639ae7a1dbf156273ce697d30fbc6c6594209Lennart Poettering
7f8aa67131cfc03ddcbd31c0420754864fc122f0Lennart Poettering case ARG_USER:
ff01d048b4c1455241c894cf7982662c9d28fd34Lennart Poettering arg_running_as = MANAGER_USER;
d3c7d7dd77b2b72315164b672462825cef6c0f9aKay Sievers break;
72b9ed828bd22f3ddd74b6853c183eebf006d6d8Lennart Poettering
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering case ARG_TEST:
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering arg_action = ACTION_TEST;
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering break;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering case ARG_DUMP_CONFIGURATION_ITEMS:
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering arg_action = ACTION_DUMP_CONFIGURATION_ITEMS;
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering break;
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering case ARG_DUMP_CORE:
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering arg_dump_core = true;
55cdcbacf70f05a40a155af24f6d2da6b478cba6Lennart Poettering break;
8d0e38a2b966799af884e78a54fd6a2dffa44788Lennart Poettering
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering case ARG_CRASH_SHELL:
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering arg_crash_shell = true;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering break;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering case ARG_CONFIRM_SPAWN:
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering arg_confirm_spawn = true;
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering break;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering
916abb21d0a6653e0187b91591e492026886b0a4Lennart Poettering case ARG_SHOW_STATUS:
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering if (optarg) {
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering if ((r = parse_boolean(optarg)) < 0) {
796b06c21b62d13c9021e2fbd9c58a5c6edb2764Kay Sievers log_error("Failed to show status boolean %s.", optarg);
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering return r;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering }
7a2a0b907b5cc60f5d9a871997d7d6e7f62bf4d8Lennart Poettering arg_show_status = r;
253ee27a0c7a410d27d490bb79ea97caed6a2b68Lennart Poettering } else
5d0fcd7c8d29340ac9425c309e8ac436a9af699cLennart Poettering arg_show_status = true;
8bbabc447b1d913bd21faf97c7b17d20d315d2b4Lennart Poettering break;
f530371f1f85a070d7d0fb5112146a43533ae00bLennart Poettering#ifdef HAVE_SYSV_COMPAT
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case ARG_SYSV_CONSOLE:
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering
a73d88fa024b5668ed7dde681e99547d41e6a864Lennart Poettering if (optarg) {
a74a8793b04de9886b4f6987b9cb86fa02c73520Lennart Poettering if ((r = parse_boolean(optarg)) < 0) {
3040728b6691ea2e9df3a2060e2d49a792bbaedaLennart Poettering log_error("Failed to SysV console boolean %s.", optarg);
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering return r;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering }
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering arg_sysv_console = r;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering } else
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering arg_sysv_console = true;
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering break;
44143309dd0b37d61d7d842ca58f01a65646ec71Kay Sievers#endif
3d57c6ab801f4437f12948e29589e3d00c3ad9dbLennart Poettering
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering case ARG_DESERIALIZE: {
2791a8f8dc8764a9247cdba3562bd4c04010f144Lennart Poettering int fd;
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering FILE *f;
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering
Error!

 

There was an error!

null

java.lang.NullPointerException