File: | build-scan/../src/core/main.c |
Warning: | line 1598, column 9 Value stored to 'fds' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | |
3 | #include <errno(*__errno_location ()).h> |
4 | #include <fcntl.h> |
5 | #include <getopt.h> |
6 | #include <signal.h> |
7 | #include <stdio.h> |
8 | #include <string.h> |
9 | #include <sys/mount.h> |
10 | #include <sys/prctl.h> |
11 | #include <sys/reboot.h> |
12 | #include <sys/stat.h> |
13 | #include <unistd.h> |
14 | #if HAVE_SECCOMP1 |
15 | #include <seccomp.h> |
16 | #endif |
17 | #if HAVE_VALGRIND_VALGRIND_H1 |
18 | #include <valgrind/valgrind.h> |
19 | #endif |
20 | |
21 | #include "sd-bus.h" |
22 | #include "sd-daemon.h" |
23 | #include "sd-messages.h" |
24 | |
25 | #include "alloc-util.h" |
26 | #include "architecture.h" |
27 | #include "build.h" |
28 | #include "bus-error.h" |
29 | #include "bus-util.h" |
30 | #include "capability-util.h" |
31 | #include "clock-util.h" |
32 | #include "conf-parser.h" |
33 | #include "cpu-set-util.h" |
34 | #include "dbus.h" |
35 | #include "dbus-manager.h" |
36 | #include "def.h" |
37 | #include "emergency-action.h" |
38 | #include "env-util.h" |
39 | #include "exit-status.h" |
40 | #include "fd-util.h" |
41 | #include "fdset.h" |
42 | #include "fileio.h" |
43 | #include "format-util.h" |
44 | #include "fs-util.h" |
45 | #include "hostname-setup.h" |
46 | #include "ima-setup.h" |
47 | #include "killall.h" |
48 | #include "kmod-setup.h" |
49 | #include "load-fragment.h" |
50 | #include "log.h" |
51 | #include "loopback-setup.h" |
52 | #include "machine-id-setup.h" |
53 | #include "manager.h" |
54 | #include "missing.h" |
55 | #include "mount-setup.h" |
56 | #include "os-util.h" |
57 | #include "pager.h" |
58 | #include "parse-util.h" |
59 | #include "path-util.h" |
60 | #include "proc-cmdline.h" |
61 | #include "process-util.h" |
62 | #include "raw-clone.h" |
63 | #include "rlimit-util.h" |
64 | #if HAVE_SECCOMP1 |
65 | #include "seccomp-util.h" |
66 | #endif |
67 | #include "selinux-setup.h" |
68 | #include "selinux-util.h" |
69 | #include "signal-util.h" |
70 | #include "smack-setup.h" |
71 | #include "special.h" |
72 | #include "stat-util.h" |
73 | #include "stdio-util.h" |
74 | #include "strv.h" |
75 | #include "switch-root.h" |
76 | #include "terminal-util.h" |
77 | #include "umask-util.h" |
78 | #include "user-util.h" |
79 | #include "util.h" |
80 | #include "virt.h" |
81 | #include "watchdog.h" |
82 | |
83 | static enum { |
84 | ACTION_RUN, |
85 | ACTION_HELP, |
86 | ACTION_VERSION, |
87 | ACTION_TEST, |
88 | ACTION_DUMP_CONFIGURATION_ITEMS, |
89 | ACTION_DUMP_BUS_PROPERTIES, |
90 | } arg_action = ACTION_RUN; |
91 | |
92 | /* Those variables are initalized to 0 automatically, so we avoid uninitialized memory access. |
93 | * Real defaults are assigned in reset_arguments() below. */ |
94 | static char *arg_default_unit; |
95 | static bool_Bool arg_system; |
96 | static bool_Bool arg_dump_core; |
97 | static int arg_crash_chvt; |
98 | static bool_Bool arg_crash_shell; |
99 | static bool_Bool arg_crash_reboot; |
100 | static char *arg_confirm_spawn; |
101 | static ShowStatus arg_show_status; |
102 | static bool_Bool arg_switched_root; |
103 | static bool_Bool arg_no_pager; |
104 | static bool_Bool arg_service_watchdogs; |
105 | static char ***arg_join_controllers = NULL((void*)0); |
106 | static ExecOutput arg_default_std_output; |
107 | static ExecOutput arg_default_std_error; |
108 | static usec_t arg_default_restart_usec; |
109 | static usec_t arg_default_timeout_start_usec; |
110 | static usec_t arg_default_timeout_stop_usec; |
111 | static usec_t arg_default_timeout_abort_usec; |
112 | static bool_Bool arg_default_timeout_abort_set; |
113 | static usec_t arg_default_start_limit_interval; |
114 | static unsigned arg_default_start_limit_burst; |
115 | static usec_t arg_runtime_watchdog; |
116 | static usec_t arg_shutdown_watchdog; |
117 | static char *arg_early_core_pattern; |
118 | static char *arg_watchdog_device; |
119 | static char **arg_default_environment; |
120 | static struct rlimit *arg_default_rlimit[_RLIMIT_MAX(__RLIMIT_RTTIME+1 > __RLIMIT_NLIMITS ? __RLIMIT_RTTIME+1 : __RLIMIT_NLIMITS)]; |
121 | static uint64_t arg_capability_bounding_set; |
122 | static bool_Bool arg_no_new_privs; |
123 | static nsec_t arg_timer_slack_nsec; |
124 | static usec_t arg_default_timer_accuracy_usec; |
125 | static Set* arg_syscall_archs; |
126 | static FILE* arg_serialization; |
127 | static int arg_default_cpu_accounting; |
128 | static bool_Bool arg_default_io_accounting; |
129 | static bool_Bool arg_default_ip_accounting; |
130 | static bool_Bool arg_default_blockio_accounting; |
131 | static bool_Bool arg_default_memory_accounting; |
132 | static bool_Bool arg_default_tasks_accounting; |
133 | static uint64_t arg_default_tasks_max; |
134 | static sd_id128_t arg_machine_id; |
135 | static EmergencyAction arg_cad_burst_action; |
136 | static CPUSet arg_cpu_affinity; |
137 | static NUMAPolicy arg_numa_policy; |
138 | |
139 | static int parse_configuration(const struct rlimit *saved_rlimit_nofile, |
140 | const struct rlimit *saved_rlimit_memlock); |
141 | |
142 | _noreturn___attribute__((noreturn)) static void freeze_or_reboot(void) { |
143 | |
144 | if (arg_crash_reboot) { |
145 | log_notice("Rebooting in 10s...")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 145, __func__, "Rebooting in 10s...") : -abs(_e); }); |
146 | (void) sleep(10); |
147 | |
148 | log_notice("Rebooting now...")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 148, __func__, "Rebooting now...") : - abs(_e); }); |
149 | (void) reboot(RB_AUTOBOOT0x01234567); |
150 | log_emergency_errno(errno, "Failed to reboot: %m")({ int _level = ((log_emergency_level())), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 150 , __func__, "Failed to reboot: %m") : -abs(_e); }); |
151 | } |
152 | |
153 | log_emergency("Freezing execution.")({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 153, __func__, "Freezing execution." ) : -abs(_e); }); |
154 | freeze(); |
155 | } |
156 | |
157 | _noreturn___attribute__((noreturn)) static void crash(int sig) { |
158 | struct sigaction sa; |
159 | pid_t pid; |
160 | |
161 | if (getpid_cached() != 1) |
162 | /* Pass this on immediately, if this is not PID 1 */ |
163 | (void) raise(sig); |
164 | else if (!arg_dump_core) |
165 | log_emergency("Caught <%s>, not dumping core.", signal_to_string(sig))({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 165, __func__, "Caught <%s>, not dumping core." , signal_to_string(sig)) : -abs(_e); }); |
166 | else { |
167 | sa = (struct sigaction) { |
168 | .sa_handler__sigaction_handler.sa_handler = nop_signal_handler, |
169 | .sa_flags = SA_NOCLDSTOP1|SA_RESTART0x10000000, |
170 | }; |
171 | |
172 | /* We want to wait for the core process, hence let's enable SIGCHLD */ |
173 | (void) sigaction(SIGCHLD17, &sa, NULL((void*)0)); |
174 | |
175 | pid = raw_clone(SIGCHLD17); |
176 | if (pid < 0) |
177 | log_emergency_errno(errno, "Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig))({ int _level = ((log_emergency_level())), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 177 , __func__, "Caught <%s>, cannot fork for core dump: %m" , signal_to_string(sig)) : -abs(_e); }); |
178 | else if (pid == 0) { |
179 | /* Enable default signal handler for core dump */ |
180 | |
181 | sa = (struct sigaction) { |
182 | .sa_handler__sigaction_handler.sa_handler = SIG_DFL((__sighandler_t) 0), |
183 | }; |
184 | (void) sigaction(sig, &sa, NULL((void*)0)); |
185 | |
186 | /* Don't limit the coredump size */ |
187 | (void) setrlimit(RLIMIT_CORERLIMIT_CORE, &RLIMIT_MAKE_CONST(RLIM_INFINITY)((struct rlimit) { 0xffffffffffffffffuLL, 0xffffffffffffffffuLL })); |
188 | |
189 | /* Just to be sure... */ |
190 | (void) chdir("/"); |
191 | |
192 | /* Raise the signal again */ |
193 | pid = raw_getpid(); |
194 | (void) kill(pid, sig); /* raise() would kill the parent */ |
195 | |
196 | assert_not_reached("We shouldn't be here...")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "We shouldn't be here..."), "../src/core/main.c", 196, __PRETTY_FUNCTION__ ); } while (0); |
197 | _exit(EXIT_FAILURE1); |
198 | } else { |
199 | siginfo_t status; |
200 | int r; |
201 | |
202 | /* Order things nicely. */ |
203 | r = wait_for_terminate(pid, &status); |
204 | if (r < 0) |
205 | log_emergency_errno(r, "Caught <%s>, waitpid() failed: %m", signal_to_string(sig))({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 205, __func__, "Caught <%s>, waitpid() failed: %m" , signal_to_string(sig)) : -abs(_e); }); |
206 | else if (status.si_code != CLD_DUMPEDCLD_DUMPED) |
207 | log_emergency("Caught <%s>, core dump failed (child "PID_FMT", code=%s, status=%i/%s).",({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
208 | signal_to_string(sig),({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
209 | pid, sigchld_code_to_string(status.si_code),({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
210 | status.si_status,({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
211 | strna(status.si_code == CLD_EXITED({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
212 | ? exit_status_to_string(status.si_status, EXIT_STATUS_MINIMAL)({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }) |
213 | : signal_to_string(status.si_status)))({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 213, __func__, "Caught <%s>, core dump failed (child " "%" "i"", code=%s, status=%i/%s).", signal_to_string(sig), pid , sigchld_code_to_string(status.si_code), status._sifields._sigchld .si_status, strna(status.si_code == CLD_EXITED ? exit_status_to_string (status._sifields._sigchld.si_status, EXIT_STATUS_MINIMAL) : signal_to_string (status._sifields._sigchld.si_status))) : -abs(_e); }); |
214 | else |
215 | log_emergency("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid)({ int _level = (((log_emergency_level()))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 215, __func__, "Caught <%s>, dumped core as pid " "%" "i"".", signal_to_string(sig), pid) : -abs(_e); }); |
216 | } |
217 | } |
218 | |
219 | if (arg_crash_chvt >= 0) |
220 | (void) chvt(arg_crash_chvt); |
221 | |
222 | sa = (struct sigaction) { |
223 | .sa_handler__sigaction_handler.sa_handler = SIG_IGN((__sighandler_t) 1), |
224 | .sa_flags = SA_NOCLDSTOP1|SA_NOCLDWAIT2|SA_RESTART0x10000000, |
225 | }; |
226 | |
227 | /* Let the kernel reap children for us */ |
228 | (void) sigaction(SIGCHLD17, &sa, NULL((void*)0)); |
229 | |
230 | if (arg_crash_shell) { |
231 | log_notice("Executing crash shell in 10s...")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 231, __func__, "Executing crash shell in 10s..." ) : -abs(_e); }); |
232 | (void) sleep(10); |
233 | |
234 | pid = raw_clone(SIGCHLD17); |
235 | if (pid < 0) |
236 | log_emergency_errno(errno, "Failed to fork off crash shell: %m")({ int _level = ((log_emergency_level())), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 236 , __func__, "Failed to fork off crash shell: %m") : -abs(_e); }); |
237 | else if (pid == 0) { |
238 | (void) setsid(); |
239 | (void) make_console_stdio(); |
240 | (void) execle("/bin/sh", "/bin/sh", NULL((void*)0), environ); |
241 | |
242 | log_emergency_errno(errno, "execle() failed: %m")({ int _level = ((log_emergency_level())), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 242 , __func__, "execle() failed: %m") : -abs(_e); }); |
243 | _exit(EXIT_FAILURE1); |
244 | } else { |
245 | log_info("Spawned crash shell as PID "PID_FMT".", pid)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 245, __func__, "Spawned crash shell as PID " "%" "i"".", pid) : -abs(_e); }); |
246 | (void) wait_for_terminate(pid, NULL((void*)0)); |
247 | } |
248 | } |
249 | |
250 | freeze_or_reboot(); |
251 | } |
252 | |
253 | static void install_crash_handler(void) { |
254 | static const struct sigaction sa = { |
255 | .sa_handler__sigaction_handler.sa_handler = crash, |
256 | .sa_flags = SA_NODEFER0x40000000, /* So that we can raise the signal again from the signal handler */ |
257 | }; |
258 | int r; |
259 | |
260 | /* We ignore the return value here, since, we don't mind if we |
261 | * cannot set up a crash handler */ |
262 | r = sigaction_many(&sa, SIGNALS_CRASH_HANDLER11,4,8,7,3,6, -1); |
263 | if (r < 0) |
264 | log_debug_errno(r, "I had trouble setting up the crash handler, ignoring: %m")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 264, __func__, "I had trouble setting up the crash handler, ignoring: %m" ) : -abs(_e); }); |
265 | } |
266 | |
267 | static int console_setup(void) { |
268 | _cleanup_close___attribute__((cleanup(closep))) int tty_fd = -1; |
269 | int r; |
270 | |
271 | tty_fd = open_terminal("/dev/console", O_WRONLY01|O_NOCTTY0400|O_CLOEXEC02000000); |
272 | if (tty_fd < 0) |
273 | return log_error_errno(tty_fd, "Failed to open /dev/console: %m")({ int _level = ((3)), _e = ((tty_fd)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 273, __func__, "Failed to open /dev/console: %m" ) : -abs(_e); }); |
274 | |
275 | /* We don't want to force text mode. plymouth may be showing |
276 | * pictures already from initrd. */ |
277 | r = reset_terminal_fd(tty_fd, false0); |
278 | if (r < 0) |
279 | return log_error_errno(r, "Failed to reset /dev/console: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 279, __func__, "Failed to reset /dev/console: %m" ) : -abs(_e); }); |
280 | |
281 | return 0; |
282 | } |
283 | |
284 | static int parse_crash_chvt(const char *value) { |
285 | int b; |
286 | |
287 | if (safe_atoi(value, &arg_crash_chvt) >= 0) |
288 | return 0; |
289 | |
290 | b = parse_boolean(value); |
291 | if (b < 0) |
292 | return b; |
293 | |
294 | if (b > 0) |
295 | arg_crash_chvt = 0; /* switch to where kmsg goes */ |
296 | else |
297 | arg_crash_chvt = -1; /* turn off switching */ |
298 | |
299 | return 0; |
300 | } |
301 | |
302 | static int parse_confirm_spawn(const char *value, char **console) { |
303 | char *s; |
304 | int r; |
305 | |
306 | r = value ? parse_boolean(value) : 1; |
307 | if (r == 0) { |
308 | *console = NULL((void*)0); |
309 | return 0; |
310 | } |
311 | |
312 | if (r > 0) /* on with default tty */ |
313 | s = strdup("/dev/console"); |
314 | else if (is_path(value)) /* on with fully qualified path */ |
315 | s = strdup(value); |
316 | else /* on with only a tty file name, not a fully qualified path */ |
317 | s = strjoin("/dev/", value)strjoin_real(("/dev/"), value, ((void*)0)); |
318 | if (!s) |
319 | return -ENOMEM12; |
320 | |
321 | *console = s; |
322 | return 0; |
323 | } |
324 | |
325 | static int set_machine_id(const char *m) { |
326 | sd_id128_t t; |
327 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 327, __PRETTY_FUNCTION__ ); } while (0); |
328 | |
329 | if (sd_id128_from_string(m, &t) < 0) |
330 | return -EINVAL22; |
331 | |
332 | if (sd_id128_is_null(t)) |
333 | return -EINVAL22; |
334 | |
335 | arg_machine_id = t; |
336 | return 0; |
337 | } |
338 | |
339 | static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { |
340 | |
341 | int r; |
342 | |
343 | assert(key)do { if ((__builtin_expect(!!(!(key)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("key"), "../src/core/main.c", 343, __PRETTY_FUNCTION__ ); } while (0); |
344 | |
345 | if (STR_IN_SET(key, "systemd.unit", "rd.systemd.unit")(!!strv_find((((char**) ((const char*[]) { "systemd.unit", "rd.systemd.unit" , ((void*)0) }))), (key)))) { |
346 | |
347 | if (proc_cmdline_value_missing(key, value)) |
348 | return 0; |
349 | |
350 | if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) |
351 | log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 351, __func__, "Unit name specified on %s= is not valid, ignoring: %s" , key, value) : -abs(_e); }); |
352 | else if (in_initrd() == !!startswith(key, "rd.")) { |
353 | if (free_and_strdup(&arg_default_unit, value) < 0) |
354 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 354 , __func__); |
355 | } |
356 | |
357 | } else if (proc_cmdline_key_streq(key, "systemd.dump_core")) { |
358 | |
359 | r = value ? parse_boolean(value) : true1; |
360 | if (r < 0) |
361 | log_warning("Failed to parse dump core switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 361, __func__, "Failed to parse dump core switch %s. Ignoring." , value) : -abs(_e); }); |
362 | else |
363 | arg_dump_core = r; |
364 | |
365 | } else if (proc_cmdline_key_streq(key, "systemd.crash_chvt")) { |
366 | |
367 | if (!value) |
368 | arg_crash_chvt = 0; /* turn on */ |
369 | else if (parse_crash_chvt(value) < 0) |
370 | log_warning("Failed to parse crash chvt switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 370, __func__, "Failed to parse crash chvt switch %s. Ignoring." , value) : -abs(_e); }); |
371 | |
372 | } else if (proc_cmdline_key_streq(key, "systemd.crash_shell")) { |
373 | |
374 | r = value ? parse_boolean(value) : true1; |
375 | if (r < 0) |
376 | log_warning("Failed to parse crash shell switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 376, __func__, "Failed to parse crash shell switch %s. Ignoring." , value) : -abs(_e); }); |
377 | else |
378 | arg_crash_shell = r; |
379 | |
380 | } else if (proc_cmdline_key_streq(key, "systemd.crash_reboot")) { |
381 | |
382 | r = value ? parse_boolean(value) : true1; |
383 | if (r < 0) |
384 | log_warning("Failed to parse crash reboot switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 384, __func__, "Failed to parse crash reboot switch %s. Ignoring." , value) : -abs(_e); }); |
385 | else |
386 | arg_crash_reboot = r; |
387 | |
388 | } else if (proc_cmdline_key_streq(key, "systemd.confirm_spawn")) { |
389 | char *s; |
390 | |
391 | r = parse_confirm_spawn(value, &s); |
392 | if (r < 0) |
393 | log_warning_errno(r, "Failed to parse confirm_spawn switch %s. Ignoring.", value)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 393, __func__, "Failed to parse confirm_spawn switch %s. Ignoring." , value) : -abs(_e); }); |
394 | else { |
395 | free(arg_confirm_spawn); |
396 | arg_confirm_spawn = s; |
397 | } |
398 | |
399 | } else if (proc_cmdline_key_streq(key, "systemd.service_watchdogs")) { |
400 | |
401 | r = value ? parse_boolean(value) : true1; |
402 | if (r < 0) |
403 | log_warning("Failed to parse service watchdog switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 403, __func__, "Failed to parse service watchdog switch %s. Ignoring." , value) : -abs(_e); }); |
404 | else |
405 | arg_service_watchdogs = r; |
406 | |
407 | } else if (proc_cmdline_key_streq(key, "systemd.show_status")) { |
408 | |
409 | if (value) { |
410 | r = parse_show_status(value, &arg_show_status); |
411 | if (r < 0) |
412 | log_warning("Failed to parse show status switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 412, __func__, "Failed to parse show status switch %s. Ignoring." , value) : -abs(_e); }); |
413 | } else |
414 | arg_show_status = SHOW_STATUS_YES; |
415 | |
416 | } else if (proc_cmdline_key_streq(key, "systemd.default_standard_output")) { |
417 | |
418 | if (proc_cmdline_value_missing(key, value)) |
419 | return 0; |
420 | |
421 | r = exec_output_from_string(value); |
422 | if (r < 0) |
423 | log_warning("Failed to parse default standard output switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 423, __func__, "Failed to parse default standard output switch %s. Ignoring." , value) : -abs(_e); }); |
424 | else |
425 | arg_default_std_output = r; |
426 | |
427 | } else if (proc_cmdline_key_streq(key, "systemd.default_standard_error")) { |
428 | |
429 | if (proc_cmdline_value_missing(key, value)) |
430 | return 0; |
431 | |
432 | r = exec_output_from_string(value); |
433 | if (r < 0) |
434 | log_warning("Failed to parse default standard error switch %s. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 434, __func__, "Failed to parse default standard error switch %s. Ignoring." , value) : -abs(_e); }); |
435 | else |
436 | arg_default_std_error = r; |
437 | |
438 | } else if (streq(key, "systemd.setenv")(strcmp((key),("systemd.setenv")) == 0)) { |
439 | |
440 | if (proc_cmdline_value_missing(key, value)) |
441 | return 0; |
442 | |
443 | if (env_assignment_is_valid(value)) { |
444 | char **env; |
445 | |
446 | env = strv_env_set(arg_default_environment, value); |
447 | if (!env) |
448 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 448 , __func__); |
449 | |
450 | arg_default_environment = env; |
451 | } else |
452 | log_warning("Environment variable name '%s' is not valid. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 452, __func__, "Environment variable name '%s' is not valid. Ignoring." , value) : -abs(_e); }); |
453 | |
454 | } else if (proc_cmdline_key_streq(key, "systemd.machine_id")) { |
455 | |
456 | if (proc_cmdline_value_missing(key, value)) |
457 | return 0; |
458 | |
459 | r = set_machine_id(value); |
460 | if (r < 0) |
461 | log_warning("MachineID '%s' is not valid. Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 461, __func__, "MachineID '%s' is not valid. Ignoring." , value) : -abs(_e); }); |
462 | |
463 | } else if (proc_cmdline_key_streq(key, "systemd.default_timeout_start_sec")) { |
464 | |
465 | if (proc_cmdline_value_missing(key, value)) |
466 | return 0; |
467 | |
468 | r = parse_sec(value, &arg_default_timeout_start_usec); |
469 | if (r < 0) |
470 | log_warning_errno(r, "Failed to parse default start timeout: %s, ignoring.", value)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 470, __func__, "Failed to parse default start timeout: %s, ignoring." , value) : -abs(_e); }); |
471 | |
472 | if (arg_default_timeout_start_usec <= 0) |
473 | arg_default_timeout_start_usec = USEC_INFINITY((usec_t) -1); |
474 | |
475 | } else if (proc_cmdline_key_streq(key, "systemd.cpu_affinity")) { |
476 | |
477 | if (proc_cmdline_value_missing(key, value)) |
478 | return 0; |
479 | |
480 | r = parse_cpu_set(value, &arg_cpu_affinity); |
481 | if (r < 0) |
482 | log_warning_errno(r, "Failed to parse CPU affinity mask '%s', ignoring: %m", value)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 482, __func__, "Failed to parse CPU affinity mask '%s', ignoring: %m" , value) : -abs(_e); }); |
483 | |
484 | } else if (proc_cmdline_key_streq(key, "systemd.watchdog_device")) { |
485 | |
486 | if (proc_cmdline_value_missing(key, value)) |
487 | return 0; |
488 | |
489 | parse_path_argument_and_warn(value, false0, &arg_watchdog_device); |
490 | |
491 | } else if (streq(key, "quiet")(strcmp((key),("quiet")) == 0) && !value) { |
492 | |
493 | if (arg_show_status == _SHOW_STATUS_UNSET) |
494 | arg_show_status = SHOW_STATUS_AUTO; |
495 | |
496 | } else if (streq(key, "debug")(strcmp((key),("debug")) == 0) && !value) { |
497 | |
498 | /* Note that log_parse_environment() handles 'debug' |
499 | * too, and sets the log level to LOG_DEBUG. */ |
500 | |
501 | if (detect_container() > 0) |
502 | log_set_target(LOG_TARGET_CONSOLE); |
503 | |
504 | } else if (!value) { |
505 | const char *target; |
506 | |
507 | /* SysV compatibility */ |
508 | target = runlevel_to_target(key); |
509 | if (target) |
510 | return free_and_strdup(&arg_default_unit, target); |
511 | } |
512 | |
513 | return 0; |
514 | } |
515 | |
516 | #define DEFINE_SETTER(name, func, descr)static int name(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata ) { int r; do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/core/main.c", 516, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c" , 516, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/core/main.c", 516, __PRETTY_FUNCTION__) ; } while (0); r = func(rvalue); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level, filename , line, _e, "../src/core/main.c", 516, __func__, "Invalid " descr "'%s': %m", rvalue) : -abs(_e); }); return 0; } \ |
517 | static int name(const char *unit, \ |
518 | const char *filename, \ |
519 | unsigned line, \ |
520 | const char *section, \ |
521 | unsigned section_line, \ |
522 | const char *lvalue, \ |
523 | int ltype, \ |
524 | const char *rvalue, \ |
525 | void *data, \ |
526 | void *userdata) { \ |
527 | \ |
528 | int r; \ |
529 | \ |
530 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/core/main.c", 530, __PRETTY_FUNCTION__ ); } while (0); \ |
531 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 531, __PRETTY_FUNCTION__ ); } while (0); \ |
532 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c", 532, __PRETTY_FUNCTION__ ); } while (0); \ |
533 | \ |
534 | r = func(rvalue); \ |
535 | if (r < 0) \ |
536 | log_syntax(unit, LOG_ERR, filename, line, r, \({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 538, __func__, "Invalid " descr "'%s': %m", rvalue) : -abs(_e); }) |
537 | "Invalid " descr "'%s': %m", \({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 538, __func__, "Invalid " descr "'%s': %m", rvalue) : -abs(_e); }) |
538 | rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 538, __func__, "Invalid " descr "'%s': %m", rvalue) : -abs(_e); }); \ |
539 | \ |
540 | return 0; \ |
541 | } |
542 | |
543 | DEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level")static int config_parse_level2(const char *unit, const char * filename, unsigned line, const char *section, unsigned section_line , const char *lvalue, int ltype, const char *rvalue, void *data , void *userdata) { int r; do { if ((__builtin_expect(!!(!(filename )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/core/main.c", 543, __PRETTY_FUNCTION__); } while ( 0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 543, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c" , 543, __PRETTY_FUNCTION__); } while (0); r = log_set_max_level_from_string_realm (LOG_REALM_SYSTEMD, (rvalue)); if (r < 0) ({ int _level = ( 3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level, filename , line, _e, "../src/core/main.c", 543, __func__, "Invalid " "log level" "'%s': %m", rvalue) : -abs(_e); }); return 0; }; |
544 | DEFINE_SETTER(config_parse_target, log_set_target_from_string, "target")static int config_parse_target(const char *unit, const char * filename, unsigned line, const char *section, unsigned section_line , const char *lvalue, int ltype, const char *rvalue, void *data , void *userdata) { int r; do { if ((__builtin_expect(!!(!(filename )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/core/main.c", 544, __PRETTY_FUNCTION__); } while ( 0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 544, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c" , 544, __PRETTY_FUNCTION__); } while (0); r = log_set_target_from_string (rvalue); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/core/main.c", 544, __func__, "Invalid " "target" "'%s': %m", rvalue) : -abs(_e) ; }); return 0; }; |
545 | DEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" )static int config_parse_color(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { int r; do { if ((__builtin_expect(!!(!(filename )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/core/main.c", 545, __PRETTY_FUNCTION__); } while ( 0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 545, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c" , 545, __PRETTY_FUNCTION__); } while (0); r = log_show_color_from_string (rvalue); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/core/main.c", 545, __func__, "Invalid " "color" "'%s': %m", rvalue) : -abs(_e); }); return 0; }; |
546 | DEFINE_SETTER(config_parse_location, log_show_location_from_string, "location")static int config_parse_location(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line , const char *lvalue, int ltype, const char *rvalue, void *data , void *userdata) { int r; do { if ((__builtin_expect(!!(!(filename )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/core/main.c", 546, __PRETTY_FUNCTION__); } while ( 0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 546, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c" , 546, __PRETTY_FUNCTION__); } while (0); r = log_show_location_from_string (rvalue); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/core/main.c", 546, __func__, "Invalid " "location" "'%s': %m", rvalue) : -abs(_e ); }); return 0; }; |
547 | |
548 | static int config_parse_cpu_affinity2( |
549 | const char *unit, |
550 | const char *filename, |
551 | unsigned line, |
552 | const char *section, |
553 | unsigned section_line, |
554 | const char *lvalue, |
555 | int ltype, |
556 | const char *rvalue, |
557 | void *data, |
558 | void *userdata) { |
559 | |
560 | CPUSet *affinity = data; |
561 | |
562 | assert(affinity)do { if ((__builtin_expect(!!(!(affinity)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("affinity"), "../src/core/main.c", 562, __PRETTY_FUNCTION__ ); } while (0); |
563 | |
564 | (void) parse_cpu_set_extend(rvalue, affinity, true1, unit, filename, line, lvalue); |
565 | |
566 | return 0; |
567 | } |
568 | |
569 | static int config_parse_show_status( |
570 | const char* unit, |
571 | const char *filename, |
572 | unsigned line, |
573 | const char *section, |
574 | unsigned section_line, |
575 | const char *lvalue, |
576 | int ltype, |
577 | const char *rvalue, |
578 | void *data, |
579 | void *userdata) { |
580 | |
581 | int k; |
582 | ShowStatus *b = data; |
583 | |
584 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/core/main.c", 584, __PRETTY_FUNCTION__ ); } while (0); |
585 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 585, __PRETTY_FUNCTION__ ); } while (0); |
586 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c", 586, __PRETTY_FUNCTION__ ); } while (0); |
587 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/core/main.c", 587, __PRETTY_FUNCTION__ ); } while (0); |
588 | |
589 | k = parse_show_status(rvalue, b); |
590 | if (k < 0) { |
591 | log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue)({ int _level = (3), _e = (k); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 591, __func__, "Failed to parse show status setting, ignoring: %s" , rvalue) : -abs(_e); }); |
592 | return 0; |
593 | } |
594 | |
595 | return 0; |
596 | } |
597 | |
598 | static int config_parse_output_restricted( |
599 | const char* unit, |
600 | const char *filename, |
601 | unsigned line, |
602 | const char *section, |
603 | unsigned section_line, |
604 | const char *lvalue, |
605 | int ltype, |
606 | const char *rvalue, |
607 | void *data, |
608 | void *userdata) { |
609 | |
610 | ExecOutput t, *eo = data; |
611 | |
612 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/core/main.c", 612, __PRETTY_FUNCTION__ ); } while (0); |
613 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 613, __PRETTY_FUNCTION__ ); } while (0); |
614 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c", 614, __PRETTY_FUNCTION__ ); } while (0); |
615 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/core/main.c", 615, __PRETTY_FUNCTION__ ); } while (0); |
616 | |
617 | t = exec_output_from_string(rvalue); |
618 | if (t < 0) { |
619 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output type, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 619, __func__, "Failed to parse output type, ignoring: %s" , rvalue) : -abs(_e); }); |
620 | return 0; |
621 | } |
622 | |
623 | if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD , EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND})/sizeof(int)]; switch (t) { case EXEC_OUTPUT_SOCKET: case EXEC_OUTPUT_NAMED_FD: case EXEC_OUTPUT_FILE: case EXEC_OUTPUT_FILE_APPEND: _found = 1; break ; default: break; } _found; })) { |
624 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 624, __func__, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s" , rvalue) : -abs(_e); }); |
625 | return 0; |
626 | } |
627 | |
628 | *eo = t; |
629 | return 0; |
630 | } |
631 | |
632 | static int config_parse_crash_chvt( |
633 | const char* unit, |
634 | const char *filename, |
635 | unsigned line, |
636 | const char *section, |
637 | unsigned section_line, |
638 | const char *lvalue, |
639 | int ltype, |
640 | const char *rvalue, |
641 | void *data, |
642 | void *userdata) { |
643 | |
644 | int r; |
645 | |
646 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/core/main.c", 646, __PRETTY_FUNCTION__ ); } while (0); |
647 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/core/main.c", 647, __PRETTY_FUNCTION__ ); } while (0); |
648 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/core/main.c", 648, __PRETTY_FUNCTION__ ); } while (0); |
649 | |
650 | r = parse_crash_chvt(rvalue); |
651 | if (r < 0) { |
652 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/core/main.c", 652, __func__, "Failed to parse CrashChangeVT= setting, ignoring: %s" , rvalue) : -abs(_e); }); |
653 | return 0; |
654 | } |
655 | |
656 | return 0; |
657 | } |
658 | |
659 | static int parse_config_file(void) { |
660 | |
661 | const ConfigTableItem items[] = { |
662 | { "Manager", "LogLevel", config_parse_level2, 0, NULL((void*)0) }, |
663 | { "Manager", "LogTarget", config_parse_target, 0, NULL((void*)0) }, |
664 | { "Manager", "LogColor", config_parse_color, 0, NULL((void*)0) }, |
665 | { "Manager", "LogLocation", config_parse_location, 0, NULL((void*)0) }, |
666 | { "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core }, |
667 | { "Manager", "CrashChVT", /* legacy */ config_parse_crash_chvt, 0, NULL((void*)0) }, |
668 | { "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, NULL((void*)0) }, |
669 | { "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell }, |
670 | { "Manager", "CrashReboot", config_parse_bool, 0, &arg_crash_reboot }, |
671 | { "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status }, |
672 | { "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, &arg_cpu_affinity }, |
673 | { "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers }, |
674 | { "Manager", "NUMAPolicy", config_parse_numa_policy, 0, &arg_numa_policy.type }, |
675 | { "Manager", "NUMAMask", config_parse_numa_mask, 0, &arg_numa_policy }, |
676 | { "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog }, |
677 | { "Manager", "ShutdownWatchdogSec", config_parse_sec, 0, &arg_shutdown_watchdog }, |
678 | { "Manager", "WatchdogDevice", config_parse_path, 0, &arg_watchdog_device }, |
679 | { "Manager", "CapabilityBoundingSet", config_parse_capability_set, 0, &arg_capability_bounding_set }, |
680 | { "Manager", "NoNewPrivileges", config_parse_bool, 0, &arg_no_new_privs }, |
681 | #if HAVE_SECCOMP1 |
682 | { "Manager", "SystemCallArchitectures", config_parse_syscall_archs, 0, &arg_syscall_archs }, |
683 | #endif |
684 | { "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec }, |
685 | { "Manager", "DefaultTimerAccuracySec", config_parse_sec, 0, &arg_default_timer_accuracy_usec }, |
686 | { "Manager", "DefaultStandardOutput", config_parse_output_restricted,0, &arg_default_std_output }, |
687 | { "Manager", "DefaultStandardError", config_parse_output_restricted,0, &arg_default_std_error }, |
688 | { "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec }, |
689 | { "Manager", "DefaultTimeoutStopSec", config_parse_sec, 0, &arg_default_timeout_stop_usec }, |
690 | { "Manager", "DefaultRestartSec", config_parse_sec, 0, &arg_default_restart_usec }, |
691 | { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval }, /* obsolete alias */ |
692 | { "Manager", "DefaultStartLimitIntervalSec",config_parse_sec, 0, &arg_default_start_limit_interval }, |
693 | { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst }, |
694 | { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment }, |
695 | { "Manager", "DefaultLimitCPU", config_parse_rlimit, RLIMIT_CPURLIMIT_CPU, arg_default_rlimit }, |
696 | { "Manager", "DefaultLimitFSIZE", config_parse_rlimit, RLIMIT_FSIZERLIMIT_FSIZE, arg_default_rlimit }, |
697 | { "Manager", "DefaultLimitDATA", config_parse_rlimit, RLIMIT_DATARLIMIT_DATA, arg_default_rlimit }, |
698 | { "Manager", "DefaultLimitSTACK", config_parse_rlimit, RLIMIT_STACKRLIMIT_STACK, arg_default_rlimit }, |
699 | { "Manager", "DefaultLimitCORE", config_parse_rlimit, RLIMIT_CORERLIMIT_CORE, arg_default_rlimit }, |
700 | { "Manager", "DefaultLimitRSS", config_parse_rlimit, RLIMIT_RSS__RLIMIT_RSS, arg_default_rlimit }, |
701 | { "Manager", "DefaultLimitNOFILE", config_parse_rlimit, RLIMIT_NOFILERLIMIT_NOFILE, arg_default_rlimit }, |
702 | { "Manager", "DefaultLimitAS", config_parse_rlimit, RLIMIT_ASRLIMIT_AS, arg_default_rlimit }, |
703 | { "Manager", "DefaultLimitNPROC", config_parse_rlimit, RLIMIT_NPROC__RLIMIT_NPROC, arg_default_rlimit }, |
704 | { "Manager", "DefaultLimitMEMLOCK", config_parse_rlimit, RLIMIT_MEMLOCK__RLIMIT_MEMLOCK, arg_default_rlimit }, |
705 | { "Manager", "DefaultLimitLOCKS", config_parse_rlimit, RLIMIT_LOCKS__RLIMIT_LOCKS, arg_default_rlimit }, |
706 | { "Manager", "DefaultLimitSIGPENDING", config_parse_rlimit, RLIMIT_SIGPENDING__RLIMIT_SIGPENDING, arg_default_rlimit }, |
707 | { "Manager", "DefaultLimitMSGQUEUE", config_parse_rlimit, RLIMIT_MSGQUEUE__RLIMIT_MSGQUEUE, arg_default_rlimit }, |
708 | { "Manager", "DefaultLimitNICE", config_parse_rlimit, RLIMIT_NICE__RLIMIT_NICE, arg_default_rlimit }, |
709 | { "Manager", "DefaultLimitRTPRIO", config_parse_rlimit, RLIMIT_RTPRIO__RLIMIT_RTPRIO, arg_default_rlimit }, |
710 | { "Manager", "DefaultLimitRTTIME", config_parse_rlimit, RLIMIT_RTTIME__RLIMIT_RTTIME, arg_default_rlimit }, |
711 | { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_default_cpu_accounting }, |
712 | { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_default_io_accounting }, |
713 | { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_default_ip_accounting }, |
714 | { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, |
715 | { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, |
716 | { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting }, |
717 | { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max }, |
718 | { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, 0, &arg_cad_burst_action }, |
719 | {} |
720 | }; |
721 | |
722 | const char *fn, *conf_dirs_nulstr; |
723 | |
724 | fn = arg_system ? |
725 | PKGSYSCONFDIR"/etc/systemd" "/system.conf" : |
726 | PKGSYSCONFDIR"/etc/systemd" "/user.conf"; |
727 | |
728 | conf_dirs_nulstr = arg_system ? |
729 | CONF_PATHS_NULSTR("systemd/system.conf.d")"/etc/" "systemd/system.conf.d" "\0" "/run/" "systemd/system.conf.d" "\0" "/usr/local/lib/" "systemd/system.conf.d" "\0" "/usr/lib/" "systemd/system.conf.d" "\0" : |
730 | CONF_PATHS_NULSTR("systemd/user.conf.d")"/etc/" "systemd/user.conf.d" "\0" "/run/" "systemd/user.conf.d" "\0" "/usr/local/lib/" "systemd/user.conf.d" "\0" "/usr/lib/" "systemd/user.conf.d" "\0"; |
731 | |
732 | (void) config_parse_many_nulstr(fn, conf_dirs_nulstr, "Manager\0", config_item_table_lookup, items, CONFIG_PARSE_WARN, NULL((void*)0)); |
733 | |
734 | /* Traditionally "0" was used to turn off the default unit timeouts. Fix this up so that we used USEC_INFINITY |
735 | * like everywhere else. */ |
736 | if (arg_default_timeout_start_usec <= 0) |
737 | arg_default_timeout_start_usec = USEC_INFINITY((usec_t) -1); |
738 | if (arg_default_timeout_stop_usec <= 0) |
739 | arg_default_timeout_stop_usec = USEC_INFINITY((usec_t) -1); |
740 | |
741 | return 0; |
742 | } |
743 | |
744 | static void set_manager_defaults(Manager *m) { |
745 | |
746 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 746, __PRETTY_FUNCTION__ ); } while (0); |
747 | |
748 | /* Propagates the various default unit property settings into the manager object, i.e. properties that do not |
749 | * affect the manager itself, but are just what newly allocated units will have set if they haven't set |
750 | * anything else. (Also see set_manager_settings() for the settings that affect the manager's own behaviour) */ |
751 | |
752 | m->default_timer_accuracy_usec = arg_default_timer_accuracy_usec; |
753 | m->default_std_output = arg_default_std_output; |
754 | m->default_std_error = arg_default_std_error; |
755 | m->default_timeout_start_usec = arg_default_timeout_start_usec; |
756 | m->default_timeout_stop_usec = arg_default_timeout_stop_usec; |
757 | m->default_restart_usec = arg_default_restart_usec; |
758 | m->default_start_limit_interval = arg_default_start_limit_interval; |
759 | m->default_start_limit_burst = arg_default_start_limit_burst; |
760 | m->default_cpu_accounting = arg_default_cpu_accounting; |
761 | m->default_io_accounting = arg_default_io_accounting; |
762 | m->default_ip_accounting = arg_default_ip_accounting; |
763 | m->default_blockio_accounting = arg_default_blockio_accounting; |
764 | m->default_memory_accounting = arg_default_memory_accounting; |
765 | m->default_tasks_accounting = arg_default_tasks_accounting; |
766 | m->default_tasks_max = arg_default_tasks_max; |
767 | |
768 | manager_set_default_rlimits(m, arg_default_rlimit); |
769 | manager_environment_add(m, NULL((void*)0), arg_default_environment); |
770 | } |
771 | |
772 | static void set_manager_settings(Manager *m) { |
773 | |
774 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 774, __PRETTY_FUNCTION__ ); } while (0); |
775 | |
776 | /* Propagates the various manager settings into the manager object, i.e. properties that effect the manager |
777 | * itself (as opposed to just being inherited into newly allocated units, see set_manager_defaults() above). */ |
778 | |
779 | m->confirm_spawn = arg_confirm_spawn; |
780 | m->service_watchdogs = arg_service_watchdogs; |
781 | m->runtime_watchdog = arg_runtime_watchdog; |
782 | m->shutdown_watchdog = arg_shutdown_watchdog; |
783 | m->cad_burst_action = arg_cad_burst_action; |
784 | |
785 | manager_set_show_status(m, arg_show_status); |
786 | } |
787 | |
788 | static int parse_argv(int argc, char *argv[]) { |
789 | enum { |
790 | ARG_LOG_LEVEL = 0x100, |
791 | ARG_LOG_TARGET, |
792 | ARG_LOG_COLOR, |
793 | ARG_LOG_LOCATION, |
794 | ARG_UNIT, |
795 | ARG_SYSTEM, |
796 | ARG_USER, |
797 | ARG_TEST, |
798 | ARG_NO_PAGER, |
799 | ARG_VERSION, |
800 | ARG_DUMP_CONFIGURATION_ITEMS, |
801 | ARG_DUMP_BUS_PROPERTIES, |
802 | ARG_DUMP_CORE, |
803 | ARG_CRASH_CHVT, |
804 | ARG_CRASH_SHELL, |
805 | ARG_CRASH_REBOOT, |
806 | ARG_CONFIRM_SPAWN, |
807 | ARG_SHOW_STATUS, |
808 | ARG_DESERIALIZE, |
809 | ARG_SWITCHED_ROOT, |
810 | ARG_DEFAULT_STD_OUTPUT, |
811 | ARG_DEFAULT_STD_ERROR, |
812 | ARG_MACHINE_ID, |
813 | ARG_SERVICE_WATCHDOGS, |
814 | }; |
815 | |
816 | static const struct option options[] = { |
817 | { "log-level", required_argument1, NULL((void*)0), ARG_LOG_LEVEL }, |
818 | { "log-target", required_argument1, NULL((void*)0), ARG_LOG_TARGET }, |
819 | { "log-color", optional_argument2, NULL((void*)0), ARG_LOG_COLOR }, |
820 | { "log-location", optional_argument2, NULL((void*)0), ARG_LOG_LOCATION }, |
821 | { "unit", required_argument1, NULL((void*)0), ARG_UNIT }, |
822 | { "system", no_argument0, NULL((void*)0), ARG_SYSTEM }, |
823 | { "user", no_argument0, NULL((void*)0), ARG_USER }, |
824 | { "test", no_argument0, NULL((void*)0), ARG_TEST }, |
825 | { "no-pager", no_argument0, NULL((void*)0), ARG_NO_PAGER }, |
826 | { "help", no_argument0, NULL((void*)0), 'h' }, |
827 | { "version", no_argument0, NULL((void*)0), ARG_VERSION }, |
828 | { "dump-configuration-items", no_argument0, NULL((void*)0), ARG_DUMP_CONFIGURATION_ITEMS }, |
829 | { "dump-bus-properties", no_argument0, NULL((void*)0), ARG_DUMP_BUS_PROPERTIES }, |
830 | { "dump-core", optional_argument2, NULL((void*)0), ARG_DUMP_CORE }, |
831 | { "crash-chvt", required_argument1, NULL((void*)0), ARG_CRASH_CHVT }, |
832 | { "crash-shell", optional_argument2, NULL((void*)0), ARG_CRASH_SHELL }, |
833 | { "crash-reboot", optional_argument2, NULL((void*)0), ARG_CRASH_REBOOT }, |
834 | { "confirm-spawn", optional_argument2, NULL((void*)0), ARG_CONFIRM_SPAWN }, |
835 | { "show-status", optional_argument2, NULL((void*)0), ARG_SHOW_STATUS }, |
836 | { "deserialize", required_argument1, NULL((void*)0), ARG_DESERIALIZE }, |
837 | { "switched-root", no_argument0, NULL((void*)0), ARG_SWITCHED_ROOT }, |
838 | { "default-standard-output", required_argument1, NULL((void*)0), ARG_DEFAULT_STD_OUTPUT, }, |
839 | { "default-standard-error", required_argument1, NULL((void*)0), ARG_DEFAULT_STD_ERROR, }, |
840 | { "machine-id", required_argument1, NULL((void*)0), ARG_MACHINE_ID }, |
841 | { "service-watchdogs", required_argument1, NULL((void*)0), ARG_SERVICE_WATCHDOGS }, |
842 | {} |
843 | }; |
844 | |
845 | int c, r; |
846 | |
847 | assert(argc >= 1)do { if ((__builtin_expect(!!(!(argc >= 1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argc >= 1"), "../src/core/main.c", 847 , __PRETTY_FUNCTION__); } while (0); |
848 | assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argv"), "../src/core/main.c", 848, __PRETTY_FUNCTION__ ); } while (0); |
849 | |
850 | if (getpid_cached() == 1) |
851 | opterr = 0; |
852 | |
853 | while ((c = getopt_long(argc, argv, "hDbsz:", options, NULL((void*)0))) >= 0) |
854 | |
855 | switch (c) { |
856 | |
857 | case ARG_LOG_LEVEL: |
858 | r = log_set_max_level_from_string(optarg)log_set_max_level_from_string_realm(LOG_REALM_SYSTEMD, (optarg )); |
859 | if (r < 0) { |
860 | log_error("Failed to parse log level %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 860, __func__, "Failed to parse log level %s." , optarg) : -abs(_e); }); |
861 | return r; |
862 | } |
863 | |
864 | break; |
865 | |
866 | case ARG_LOG_TARGET: |
867 | r = log_set_target_from_string(optarg); |
868 | if (r < 0) { |
869 | log_error("Failed to parse log target %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 869, __func__, "Failed to parse log target %s." , optarg) : -abs(_e); }); |
870 | return r; |
871 | } |
872 | |
873 | break; |
874 | |
875 | case ARG_LOG_COLOR: |
876 | |
877 | if (optarg) { |
878 | r = log_show_color_from_string(optarg); |
879 | if (r < 0) { |
880 | log_error("Failed to parse log color setting %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 880, __func__, "Failed to parse log color setting %s." , optarg) : -abs(_e); }); |
881 | return r; |
882 | } |
883 | } else |
884 | log_show_color(true1); |
885 | |
886 | break; |
887 | |
888 | case ARG_LOG_LOCATION: |
889 | if (optarg) { |
890 | r = log_show_location_from_string(optarg); |
891 | if (r < 0) { |
892 | log_error("Failed to parse log location setting %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 892, __func__, "Failed to parse log location setting %s." , optarg) : -abs(_e); }); |
893 | return r; |
894 | } |
895 | } else |
896 | log_show_location(true1); |
897 | |
898 | break; |
899 | |
900 | case ARG_DEFAULT_STD_OUTPUT: |
901 | r = exec_output_from_string(optarg); |
902 | if (r < 0) { |
903 | log_error("Failed to parse default standard output setting %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 903, __func__, "Failed to parse default standard output setting %s." , optarg) : -abs(_e); }); |
904 | return r; |
905 | } else |
906 | arg_default_std_output = r; |
907 | break; |
908 | |
909 | case ARG_DEFAULT_STD_ERROR: |
910 | r = exec_output_from_string(optarg); |
911 | if (r < 0) { |
912 | log_error("Failed to parse default standard error output setting %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 912, __func__, "Failed to parse default standard error output setting %s." , optarg) : -abs(_e); }); |
913 | return r; |
914 | } else |
915 | arg_default_std_error = r; |
916 | break; |
917 | |
918 | case ARG_UNIT: |
919 | r = free_and_strdup(&arg_default_unit, optarg); |
920 | if (r < 0) |
921 | return log_error_errno(r, "Failed to set default unit %s: %m", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 921, __func__, "Failed to set default unit %s: %m" , optarg) : -abs(_e); }); |
922 | |
923 | break; |
924 | |
925 | case ARG_SYSTEM: |
926 | arg_system = true1; |
927 | break; |
928 | |
929 | case ARG_USER: |
930 | arg_system = false0; |
931 | break; |
932 | |
933 | case ARG_TEST: |
934 | arg_action = ACTION_TEST; |
935 | break; |
936 | |
937 | case ARG_NO_PAGER: |
938 | arg_no_pager = true1; |
939 | break; |
940 | |
941 | case ARG_VERSION: |
942 | arg_action = ACTION_VERSION; |
943 | break; |
944 | |
945 | case ARG_DUMP_CONFIGURATION_ITEMS: |
946 | arg_action = ACTION_DUMP_CONFIGURATION_ITEMS; |
947 | break; |
948 | |
949 | case ARG_DUMP_BUS_PROPERTIES: |
950 | arg_action = ACTION_DUMP_BUS_PROPERTIES; |
951 | break; |
952 | |
953 | case ARG_DUMP_CORE: |
954 | if (!optarg) |
955 | arg_dump_core = true1; |
956 | else { |
957 | r = parse_boolean(optarg); |
958 | if (r < 0) |
959 | return log_error_errno(r, "Failed to parse dump core boolean: %s", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 959, __func__, "Failed to parse dump core boolean: %s" , optarg) : -abs(_e); }); |
960 | arg_dump_core = r; |
961 | } |
962 | break; |
963 | |
964 | case ARG_CRASH_CHVT: |
965 | r = parse_crash_chvt(optarg); |
966 | if (r < 0) |
967 | return log_error_errno(r, "Failed to parse crash virtual terminal index: %s", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 967, __func__, "Failed to parse crash virtual terminal index: %s" , optarg) : -abs(_e); }); |
968 | break; |
969 | |
970 | case ARG_CRASH_SHELL: |
971 | if (!optarg) |
972 | arg_crash_shell = true1; |
973 | else { |
974 | r = parse_boolean(optarg); |
975 | if (r < 0) |
976 | return log_error_errno(r, "Failed to parse crash shell boolean: %s", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 976, __func__, "Failed to parse crash shell boolean: %s" , optarg) : -abs(_e); }); |
977 | arg_crash_shell = r; |
978 | } |
979 | break; |
980 | |
981 | case ARG_CRASH_REBOOT: |
982 | if (!optarg) |
983 | arg_crash_reboot = true1; |
984 | else { |
985 | r = parse_boolean(optarg); |
986 | if (r < 0) |
987 | return log_error_errno(r, "Failed to parse crash shell boolean: %s", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 987, __func__, "Failed to parse crash shell boolean: %s" , optarg) : -abs(_e); }); |
988 | arg_crash_reboot = r; |
989 | } |
990 | break; |
991 | |
992 | case ARG_CONFIRM_SPAWN: |
993 | arg_confirm_spawn = mfree(arg_confirm_spawn); |
994 | |
995 | r = parse_confirm_spawn(optarg, &arg_confirm_spawn); |
996 | if (r < 0) |
997 | return log_error_errno(r, "Failed to parse confirm spawn option: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 997, __func__, "Failed to parse confirm spawn option: %m" ) : -abs(_e); }); |
998 | break; |
999 | |
1000 | case ARG_SERVICE_WATCHDOGS: |
1001 | r = parse_boolean(optarg); |
1002 | if (r < 0) |
1003 | return log_error_errno(r, "Failed to parse service watchdogs boolean: %s", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1003, __func__, "Failed to parse service watchdogs boolean: %s" , optarg) : -abs(_e); }); |
1004 | arg_service_watchdogs = r; |
1005 | break; |
1006 | |
1007 | case ARG_SHOW_STATUS: |
1008 | if (optarg) { |
1009 | r = parse_show_status(optarg, &arg_show_status); |
1010 | if (r < 0) { |
1011 | log_error("Failed to parse show status boolean %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1011, __func__, "Failed to parse show status boolean %s." , optarg) : -abs(_e); }); |
1012 | return r; |
1013 | } |
1014 | } else |
1015 | arg_show_status = SHOW_STATUS_YES; |
1016 | break; |
1017 | |
1018 | case ARG_DESERIALIZE: { |
1019 | int fd; |
1020 | FILE *f; |
1021 | |
1022 | r = safe_atoi(optarg, &fd); |
1023 | if (r < 0 || fd < 0) { |
1024 | log_error("Failed to parse deserialize option %s.", optarg)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1024, __func__, "Failed to parse deserialize option %s." , optarg) : -abs(_e); }); |
1025 | return -EINVAL22; |
1026 | } |
1027 | |
1028 | (void) fd_cloexec(fd, true1); |
1029 | |
1030 | f = fdopen(fd, "r"); |
1031 | if (!f) |
1032 | return log_error_errno(errno, "Failed to open serialization fd: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1032, __func__, "Failed to open serialization fd: %m" ) : -abs(_e); }); |
1033 | |
1034 | safe_fclose(arg_serialization); |
1035 | arg_serialization = f; |
1036 | |
1037 | break; |
1038 | } |
1039 | |
1040 | case ARG_SWITCHED_ROOT: |
1041 | arg_switched_root = true1; |
1042 | break; |
1043 | |
1044 | case ARG_MACHINE_ID: |
1045 | r = set_machine_id(optarg); |
1046 | if (r < 0) |
1047 | return log_error_errno(r, "MachineID '%s' is not valid.", optarg)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1047, __func__, "MachineID '%s' is not valid." , optarg) : -abs(_e); }); |
1048 | break; |
1049 | |
1050 | case 'h': |
1051 | arg_action = ACTION_HELP; |
1052 | break; |
1053 | |
1054 | case 'D': |
1055 | log_set_max_level(LOG_DEBUG)log_set_max_level_realm(LOG_REALM_SYSTEMD, (7)); |
1056 | break; |
1057 | |
1058 | case 'b': |
1059 | case 's': |
1060 | case 'z': |
1061 | /* Just to eat away the sysvinit kernel |
1062 | * cmdline args without getopt() error |
1063 | * messages that we'll parse in |
1064 | * parse_proc_cmdline_word() or ignore. */ |
1065 | |
1066 | case '?': |
1067 | if (getpid_cached() != 1) |
1068 | return -EINVAL22; |
1069 | else |
1070 | return 0; |
1071 | |
1072 | default: |
1073 | assert_not_reached("Unhandled option code.")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "Unhandled option code."), "../src/core/main.c", 1073, __PRETTY_FUNCTION__ ); } while (0); |
1074 | } |
1075 | |
1076 | if (optind < argc && getpid_cached() != 1) { |
1077 | /* Hmm, when we aren't run as init system |
1078 | * let's complain about excess arguments */ |
1079 | |
1080 | log_error("Excess arguments.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1080, __func__, "Excess arguments.") : -abs(_e); }); |
1081 | return -EINVAL22; |
1082 | } |
1083 | |
1084 | return 0; |
1085 | } |
1086 | |
1087 | static int help(void) { |
1088 | |
1089 | printf("%s [OPTIONS...]\n\n" |
1090 | "Starts up and maintains the system or user services.\n\n" |
1091 | " -h --help Show this help\n" |
1092 | " --version Show version\n" |
1093 | " --test Determine startup sequence, dump it and exit\n" |
1094 | " --no-pager Do not pipe output into a pager\n" |
1095 | " --dump-configuration-items Dump understood unit configuration items\n" |
1096 | " --dump-bus-properties Dump exposed bus properties\n" |
1097 | " --unit=UNIT Set default unit\n" |
1098 | " --system Run a system instance, even if PID != 1\n" |
1099 | " --user Run a user instance\n" |
1100 | " --dump-core[=BOOL] Dump core on crash\n" |
1101 | " --crash-vt=NR Change to specified VT on crash\n" |
1102 | " --crash-reboot[=BOOL] Reboot on crash\n" |
1103 | " --crash-shell[=BOOL] Run shell on crash\n" |
1104 | " --confirm-spawn[=BOOL] Ask for confirmation when spawning processes\n" |
1105 | " --show-status[=BOOL] Show status updates on the console during bootup\n" |
1106 | " --log-target=TARGET Set log target (console, journal, kmsg, journal-or-kmsg, null)\n" |
1107 | " --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n" |
1108 | " --log-color[=BOOL] Highlight important log messages\n" |
1109 | " --log-location[=BOOL] Include code location in log messages\n" |
1110 | " --default-standard-output= Set default standard output for services\n" |
1111 | " --default-standard-error= Set default standard error output for services\n", |
1112 | program_invocation_short_name); |
1113 | |
1114 | return 0; |
1115 | } |
1116 | |
1117 | static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool_Bool switching_root) { |
1118 | _cleanup_fdset_free___attribute__((cleanup(fdset_freep))) FDSet *fds = NULL((void*)0); |
1119 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0); |
1120 | int r; |
1121 | |
1122 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 1122, __PRETTY_FUNCTION__ ); } while (0); |
1123 | assert(_f)do { if ((__builtin_expect(!!(!(_f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("_f"), "../src/core/main.c", 1123, __PRETTY_FUNCTION__ ); } while (0); |
1124 | assert(_fds)do { if ((__builtin_expect(!!(!(_fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("_fds"), "../src/core/main.c", 1124, __PRETTY_FUNCTION__ ); } while (0); |
1125 | |
1126 | r = manager_open_serialization(m, &f); |
1127 | if (r < 0) |
1128 | return log_error_errno(r, "Failed to create serialization file: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1128, __func__, "Failed to create serialization file: %m" ) : -abs(_e); }); |
1129 | |
1130 | /* Make sure nothing is really destructed when we shut down */ |
1131 | m->n_reloading++; |
1132 | bus_manager_send_reloading(m, true1); |
1133 | |
1134 | fds = fdset_new(); |
1135 | if (!fds) |
1136 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 1136 , __func__); |
1137 | |
1138 | r = manager_serialize(m, f, fds, switching_root); |
1139 | if (r < 0) |
1140 | return log_error_errno(r, "Failed to serialize state: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1140, __func__, "Failed to serialize state: %m" ) : -abs(_e); }); |
1141 | |
1142 | if (fseeko(f, 0, SEEK_SET0) == (off_t) -1) |
1143 | return log_error_errno(errno, "Failed to rewind serialization fd: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1143, __func__, "Failed to rewind serialization fd: %m" ) : -abs(_e); }); |
1144 | |
1145 | r = fd_cloexec(fileno(f), false0); |
1146 | if (r < 0) |
1147 | return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1147, __func__, "Failed to disable O_CLOEXEC for serialization: %m" ) : -abs(_e); }); |
1148 | |
1149 | r = fdset_cloexec(fds, false0); |
1150 | if (r < 0) |
1151 | return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1151, __func__, "Failed to disable O_CLOEXEC for serialization fds: %m" ) : -abs(_e); }); |
1152 | |
1153 | *_f = TAKE_PTR(f)({ typeof(f) _ptr_ = (f); (f) = ((void*)0); _ptr_; }); |
1154 | *_fds = TAKE_PTR(fds)({ typeof(fds) _ptr_ = (fds); (fds) = ((void*)0); _ptr_; }); |
1155 | |
1156 | return 0; |
1157 | } |
1158 | |
1159 | static int bump_rlimit_nofile(struct rlimit *saved_rlimit) { |
1160 | int r, nr; |
1161 | |
1162 | /* Bump up the resource limit for ourselves substantially, all the way to the maximum the kernel allows */ |
1163 | nr = read_nr_open(); |
1164 | r = setrlimit_closest(RLIMIT_NOFILERLIMIT_NOFILE, &RLIMIT_MAKE_CONST(nr)((struct rlimit) { nr, nr })); |
1165 | if (r < 0) |
1166 | return log_warning_errno(r, "Setting RLIMIT_NOFILE failed, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1166, __func__, "Setting RLIMIT_NOFILE failed, ignoring: %m" ) : -abs(_e); }); |
1167 | |
1168 | return 0; |
1169 | } |
1170 | |
1171 | static int bump_rlimit_memlock(struct rlimit *saved_rlimit) { |
1172 | int r; |
1173 | |
1174 | assert(getuid() == 0)do { if ((__builtin_expect(!!(!(getuid() == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("getuid() == 0"), "../src/core/main.c", 1174 , __PRETTY_FUNCTION__); } while (0); |
1175 | |
1176 | /* BPF_MAP_TYPE_LPM_TRIE bpf maps are charged against RLIMIT_MEMLOCK, even though we have CAP_IPC_LOCK which |
1177 | * should normally disable such checks. We need them to implement IPAccessAllow= and IPAccessDeny=, hence let's |
1178 | * bump the value high enough for the root user. */ |
1179 | |
1180 | r = setrlimit_closest(RLIMIT_MEMLOCK__RLIMIT_MEMLOCK, &RLIMIT_MAKE_CONST(HIGH_RLIMIT_MEMLOCK)((struct rlimit) { (1024ULL*1024ULL*64ULL), (1024ULL*1024ULL* 64ULL) })); |
1181 | if (r < 0) |
1182 | return log_warning_errno(r, "Setting RLIMIT_MEMLOCK failed, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1182, __func__, "Setting RLIMIT_MEMLOCK failed, ignoring: %m" ) : -abs(_e); }); |
1183 | |
1184 | return 0; |
1185 | } |
1186 | |
1187 | static void test_usr(void) { |
1188 | |
1189 | /* Check that /usr is not a separate fs */ |
1190 | |
1191 | if (dir_is_empty("/usr") <= 0) |
1192 | return; |
1193 | |
1194 | log_warning("/usr appears to be on its own filesystem and is not already mounted. This is not a supported setup. "({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1196, __func__, "/usr appears to be on its own filesystem and is not already mounted. This is not a supported setup. " "Some things will probably break (sometimes even silently) in mysterious ways. " "Consult http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken for more information." ) : -abs(_e); }) |
1195 | "Some things will probably break (sometimes even silently) in mysterious ways. "({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1196, __func__, "/usr appears to be on its own filesystem and is not already mounted. This is not a supported setup. " "Some things will probably break (sometimes even silently) in mysterious ways. " "Consult http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken for more information." ) : -abs(_e); }) |
1196 | "Consult http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken for more information.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1196, __func__, "/usr appears to be on its own filesystem and is not already mounted. This is not a supported setup. " "Some things will probably break (sometimes even silently) in mysterious ways. " "Consult http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken for more information." ) : -abs(_e); }); |
1197 | } |
1198 | |
1199 | static int enforce_syscall_archs(Set *archs) { |
1200 | #if HAVE_SECCOMP1 |
1201 | int r; |
1202 | |
1203 | if (!is_seccomp_available()) |
1204 | return 0; |
1205 | |
1206 | r = seccomp_restrict_archs(arg_syscall_archs); |
1207 | if (r < 0) |
1208 | return log_error_errno(r, "Failed to enforce system call architecture restrication: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1208, __func__, "Failed to enforce system call architecture restrication: %m" ) : -abs(_e); }); |
1209 | #endif |
1210 | return 0; |
1211 | } |
1212 | |
1213 | static int status_welcome(void) { |
1214 | _cleanup_free___attribute__((cleanup(freep))) char *pretty_name = NULL((void*)0), *ansi_color = NULL((void*)0); |
1215 | int r; |
1216 | |
1217 | if (arg_show_status <= 0) |
1218 | return 0; |
1219 | |
1220 | r = parse_os_release(NULL((void*)0), |
1221 | "PRETTY_NAME", &pretty_name, |
1222 | "ANSI_COLOR", &ansi_color, |
1223 | NULL((void*)0)); |
1224 | if (r < 0) |
1225 | log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,({ int _level = ((r == -2 ? 7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1226, __func__, "Failed to read os-release file, ignoring: %m" ) : -abs(_e); }) |
1226 | "Failed to read os-release file, ignoring: %m")({ int _level = ((r == -2 ? 7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1226, __func__, "Failed to read os-release file, ignoring: %m" ) : -abs(_e); }); |
1227 | |
1228 | if (log_get_show_color()) |
1229 | return status_printf(NULL((void*)0), false0, false0, |
1230 | "\nWelcome to \x1B[%sm%s\x1B[0m!\n", |
1231 | isempty(ansi_color) ? "1" : ansi_color, |
1232 | isempty(pretty_name) ? "Linux" : pretty_name); |
1233 | else |
1234 | return status_printf(NULL((void*)0), false0, false0, |
1235 | "\nWelcome to %s!\n", |
1236 | isempty(pretty_name) ? "Linux" : pretty_name); |
1237 | } |
1238 | |
1239 | static int write_container_id(void) { |
1240 | const char *c; |
1241 | int r; |
1242 | |
1243 | c = getenv("container"); |
1244 | if (isempty(c)) |
1245 | return 0; |
1246 | |
1247 | RUN_WITH_UMASK(0022)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_ _saved_umask_ = { umask(0022), 0 }; !_saved_umask_.quit ; _saved_umask_ .quit = 1) |
1248 | r = write_string_file("/run/systemd/container", c, WRITE_STRING_FILE_CREATE); |
1249 | if (r < 0) |
1250 | return log_warning_errno(r, "Failed to write /run/systemd/container, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1250, __func__, "Failed to write /run/systemd/container, ignoring: %m" ) : -abs(_e); }); |
1251 | |
1252 | return 1; |
1253 | } |
1254 | |
1255 | static int bump_unix_max_dgram_qlen(void) { |
1256 | _cleanup_free___attribute__((cleanup(freep))) char *qlen = NULL((void*)0); |
1257 | unsigned long v; |
1258 | int r; |
1259 | |
1260 | /* Let's bump the net.unix.max_dgram_qlen sysctl. The kernel default of 16 is simply too low. We set the value |
1261 | * really really early during boot, so that it is actually applied to all our sockets, including the |
1262 | * $NOTIFY_SOCKET one. */ |
1263 | |
1264 | r = read_one_line_file("/proc/sys/net/unix/max_dgram_qlen", &qlen); |
1265 | if (r < 0) |
1266 | return log_warning_errno(r, "Failed to read AF_UNIX datagram queue length, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1266, __func__, "Failed to read AF_UNIX datagram queue length, ignoring: %m" ) : -abs(_e); }); |
1267 | |
1268 | r = safe_atolu(qlen, &v); |
1269 | if (r < 0) |
1270 | return log_warning_errno(r, "Failed to parse AF_UNIX datagram queue length '%s', ignoring: %m", qlen)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1270, __func__, "Failed to parse AF_UNIX datagram queue length '%s', ignoring: %m" , qlen) : -abs(_e); }); |
1271 | |
1272 | if (v >= DEFAULT_UNIX_MAX_DGRAM_QLEN512UL) |
1273 | return 0; |
1274 | |
1275 | r = write_string_filef("/proc/sys/net/unix/max_dgram_qlen", 0, "%lu", DEFAULT_UNIX_MAX_DGRAM_QLEN512UL); |
1276 | if (r < 0) |
1277 | return log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,({ int _level = ((({ _Bool _found = 0; static __attribute__ ( (unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){-30, -1, -13})/sizeof(int)]; switch(r) { case -30: case -1: case -13: _found = 1; break; default: break; } _found; }) ? 7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1278, __func__, "Failed to bump AF_UNIX datagram queue length, ignoring: %m" ) : -abs(_e); }) |
1278 | "Failed to bump AF_UNIX datagram queue length, ignoring: %m")({ int _level = ((({ _Bool _found = 0; static __attribute__ ( (unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){-30, -1, -13})/sizeof(int)]; switch(r) { case -30: case -1: case -13: _found = 1; break; default: break; } _found; }) ? 7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1278, __func__, "Failed to bump AF_UNIX datagram queue length, ignoring: %m" ) : -abs(_e); }); |
1279 | |
1280 | return 1; |
1281 | } |
1282 | |
1283 | static int fixup_environment(void) { |
1284 | _cleanup_free___attribute__((cleanup(freep))) char *term = NULL((void*)0); |
1285 | const char *t; |
1286 | int r; |
1287 | |
1288 | /* Only fix up the environment when we are started as PID 1 */ |
1289 | if (getpid_cached() != 1) |
1290 | return 0; |
1291 | |
1292 | /* We expect the environment to be set correctly if run inside a container. */ |
1293 | if (detect_container() > 0) |
1294 | return 0; |
1295 | |
1296 | /* When started as PID1, the kernel uses /dev/console for our stdios and uses TERM=linux whatever the backend |
1297 | * device used by the console. We try to make a better guess here since some consoles might not have support |
1298 | * for color mode for example. |
1299 | * |
1300 | * However if TERM was configured through the kernel command line then leave it alone. */ |
1301 | r = proc_cmdline_get_key("TERM", 0, &term); |
1302 | if (r < 0) |
1303 | return r; |
1304 | |
1305 | t = term ?: default_term_for_tty("/dev/console"); |
1306 | |
1307 | if (setenv("TERM", t, 1) < 0) |
1308 | return -errno(*__errno_location ()); |
1309 | |
1310 | return 0; |
1311 | } |
1312 | |
1313 | static void redirect_telinit(int argc, char *argv[]) { |
1314 | |
1315 | /* This is compatibility support for SysV, where calling init as a user is identical to telinit. */ |
1316 | |
1317 | #if HAVE_SYSV_COMPAT1 |
1318 | if (getpid_cached() == 1) |
1319 | return; |
1320 | |
1321 | if (!strstr(program_invocation_short_name, "init")) |
1322 | return; |
1323 | |
1324 | execv(SYSTEMCTL_BINARY_PATH"/usr/bin/systemctl", argv); |
1325 | log_error_errno(errno, "Failed to exec " SYSTEMCTL_BINARY_PATH ": %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1325, __func__, "Failed to exec " "/usr/bin/systemctl" ": %m") : -abs(_e); }); |
1326 | exit(EXIT_FAILURE1); |
1327 | #endif |
1328 | } |
1329 | |
1330 | static int become_shutdown( |
1331 | const char *shutdown_verb, |
1332 | int retval) { |
1333 | |
1334 | char log_level[DECIMAL_STR_MAX(int)(2+(sizeof(int) <= 1 ? 3 : sizeof(int) <= 2 ? 5 : sizeof (int) <= 4 ? 10 : sizeof(int) <= 8 ? 20 : sizeof(int[-2 *(sizeof(int) > 8)]))) + 1], |
1335 | exit_code[DECIMAL_STR_MAX(uint8_t)(2+(sizeof(uint8_t) <= 1 ? 3 : sizeof(uint8_t) <= 2 ? 5 : sizeof(uint8_t) <= 4 ? 10 : sizeof(uint8_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uint8_t) > 8)]))) + 1], |
1336 | timeout[DECIMAL_STR_MAX(usec_t)(2+(sizeof(usec_t) <= 1 ? 3 : sizeof(usec_t) <= 2 ? 5 : sizeof(usec_t) <= 4 ? 10 : sizeof(usec_t) <= 8 ? 20 : sizeof (int[-2*(sizeof(usec_t) > 8)]))) + 1]; |
1337 | |
1338 | const char* command_line[13] = { |
1339 | SYSTEMD_SHUTDOWN_BINARY_PATH"/usr/lib/systemd/systemd-shutdown", |
1340 | shutdown_verb, |
1341 | "--timeout", timeout, |
1342 | "--log-level", log_level, |
1343 | "--log-target", |
1344 | }; |
1345 | |
1346 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **env_block = NULL((void*)0); |
1347 | size_t pos = 7; |
1348 | int r; |
1349 | |
1350 | assert(shutdown_verb)do { if ((__builtin_expect(!!(!(shutdown_verb)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("shutdown_verb"), "../src/core/main.c", 1350 , __PRETTY_FUNCTION__); } while (0); |
1351 | assert(!command_line[pos])do { if ((__builtin_expect(!!(!(!command_line[pos])),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!command_line[pos]"), "../src/core/main.c" , 1351, __PRETTY_FUNCTION__); } while (0); |
1352 | env_block = strv_copy(environ); |
1353 | |
1354 | xsprintf(log_level, "%d", log_get_max_level())do { if ((__builtin_expect(!!(!(((size_t) snprintf(log_level, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(log_level), typeof(&*(log_level))), sizeof(log_level )/sizeof((log_level)[0]), ((void)0))), "%d", log_get_max_level_realm (LOG_REALM_SYSTEMD)) < (__extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(log_level), typeof(& *(log_level))), sizeof(log_level)/sizeof((log_level)[0]), ((void )0))))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: " "log_level" "[] must be big enough"), "../src/core/main.c", 1354 , __PRETTY_FUNCTION__); } while (0); |
1355 | xsprintf(timeout, "%" PRI_USEC "us", arg_default_timeout_stop_usec)do { if ((__builtin_expect(!!(!(((size_t) snprintf(timeout, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (timeout), typeof(&*(timeout))), sizeof(timeout)/sizeof(( timeout)[0]), ((void)0))), "%" "l" "u" "us", arg_default_timeout_stop_usec ) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(timeout), typeof(&*(timeout))), sizeof(timeout)/sizeof ((timeout)[0]), ((void)0))))))),0))) log_assert_failed_realm( LOG_REALM_SYSTEMD, ("xsprintf: " "timeout" "[] must be big enough" ), "../src/core/main.c", 1355, __PRETTY_FUNCTION__); } while ( 0); |
1356 | |
1357 | switch (log_get_target()) { |
1358 | |
1359 | case LOG_TARGET_KMSG: |
1360 | case LOG_TARGET_JOURNAL_OR_KMSG: |
1361 | case LOG_TARGET_SYSLOG_OR_KMSG: |
1362 | command_line[pos++] = "kmsg"; |
1363 | break; |
1364 | |
1365 | case LOG_TARGET_NULL: |
1366 | command_line[pos++] = "null"; |
1367 | break; |
1368 | |
1369 | case LOG_TARGET_CONSOLE: |
1370 | default: |
1371 | command_line[pos++] = "console"; |
1372 | break; |
1373 | }; |
1374 | |
1375 | if (log_get_show_color()) |
1376 | command_line[pos++] = "--log-color"; |
1377 | |
1378 | if (log_get_show_location()) |
1379 | command_line[pos++] = "--log-location"; |
1380 | |
1381 | if (streq(shutdown_verb, "exit")(strcmp((shutdown_verb),("exit")) == 0)) { |
1382 | command_line[pos++] = "--exit-code"; |
1383 | command_line[pos++] = exit_code; |
1384 | xsprintf(exit_code, "%d", retval)do { if ((__builtin_expect(!!(!(((size_t) snprintf(exit_code, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(exit_code), typeof(&*(exit_code))), sizeof(exit_code )/sizeof((exit_code)[0]), ((void)0))), "%d", retval) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (exit_code), typeof(&*(exit_code))), sizeof(exit_code)/sizeof ((exit_code)[0]), ((void)0))))))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("xsprintf: " "exit_code" "[] must be big enough" ), "../src/core/main.c", 1384, __PRETTY_FUNCTION__); } while ( 0); |
1385 | } |
1386 | |
1387 | assert(pos < ELEMENTSOF(command_line))do { if ((__builtin_expect(!!(!(pos < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(command_line), typeof( &*(command_line))), sizeof(command_line)/sizeof((command_line )[0]), ((void)0))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("pos < ELEMENTSOF(command_line)"), "../src/core/main.c" , 1387, __PRETTY_FUNCTION__); } while (0); |
1388 | |
1389 | if (streq(shutdown_verb, "reboot")(strcmp((shutdown_verb),("reboot")) == 0) && |
1390 | arg_shutdown_watchdog > 0 && |
1391 | arg_shutdown_watchdog != USEC_INFINITY((usec_t) -1)) { |
1392 | |
1393 | char *e; |
1394 | |
1395 | /* If we reboot let's set the shutdown |
1396 | * watchdog and tell the shutdown binary to |
1397 | * repeatedly ping it */ |
1398 | r = watchdog_set_timeout(&arg_shutdown_watchdog); |
1399 | watchdog_close(r < 0); |
1400 | |
1401 | /* Tell the binary how often to ping, ignore failure */ |
1402 | if (asprintf(&e, "WATCHDOG_USEC="USEC_FMT"%" "l" "u", arg_shutdown_watchdog) > 0) |
1403 | (void) strv_consume(&env_block, e); |
1404 | |
1405 | if (arg_watchdog_device && |
1406 | asprintf(&e, "WATCHDOG_DEVICE=%s", arg_watchdog_device) > 0) |
1407 | (void) strv_consume(&env_block, e); |
1408 | } else |
1409 | watchdog_close(true1); |
1410 | |
1411 | /* Avoid the creation of new processes forked by the |
1412 | * kernel; at this point, we will not listen to the |
1413 | * signals anyway */ |
1414 | if (detect_container() <= 0) |
1415 | (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER"_systemd"); |
1416 | |
1417 | execve(SYSTEMD_SHUTDOWN_BINARY_PATH"/usr/lib/systemd/systemd-shutdown", (char **) command_line, env_block); |
1418 | return -errno(*__errno_location ()); |
1419 | } |
1420 | |
1421 | static void initialize_clock(void) { |
1422 | int r; |
1423 | |
1424 | if (clock_is_localtime(NULL((void*)0)) > 0) { |
1425 | int min; |
1426 | |
1427 | /* |
1428 | * The very first call of settimeofday() also does a time warp in the kernel. |
1429 | * |
1430 | * In the rtc-in-local time mode, we set the kernel's timezone, and rely on external tools to take care |
1431 | * of maintaining the RTC and do all adjustments. This matches the behavior of Windows, which leaves |
1432 | * the RTC alone if the registry tells that the RTC runs in UTC. |
1433 | */ |
1434 | r = clock_set_timezone(&min); |
1435 | if (r < 0) |
1436 | log_error_errno(r, "Failed to apply local time delta, ignoring: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1436, __func__, "Failed to apply local time delta, ignoring: %m" ) : -abs(_e); }); |
1437 | else |
1438 | log_info("RTC configured in localtime, applying delta of %i minutes to system time.", min)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1438, __func__, "RTC configured in localtime, applying delta of %i minutes to system time." , min) : -abs(_e); }); |
1439 | |
1440 | } else if (!in_initrd()) { |
1441 | /* |
1442 | * Do a dummy very first call to seal the kernel's time warp magic. |
1443 | * |
1444 | * Do not call this from inside the initrd. The initrd might not carry /etc/adjtime with LOCAL, but the |
1445 | * real system could be set up that way. In such case, we need to delay the time-warp or the sealing |
1446 | * until we reach the real system. |
1447 | * |
1448 | * Do no set the kernel's timezone. The concept of local time cannot be supported reliably, the time |
1449 | * will jump or be incorrect at every daylight saving time change. All kernel local time concepts will |
1450 | * be treated as UTC that way. |
1451 | */ |
1452 | (void) clock_reset_timewarp(); |
1453 | } |
1454 | |
1455 | r = clock_apply_epoch(); |
1456 | if (r < 0) |
1457 | log_error_errno(r, "Current system time is before build time, but cannot correct: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1457, __func__, "Current system time is before build time, but cannot correct: %m" ) : -abs(_e); }); |
1458 | else if (r > 0) |
1459 | log_info("System time before build time, advancing clock.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1459, __func__, "System time before build time, advancing clock." ) : -abs(_e); }); |
1460 | } |
1461 | |
1462 | static void initialize_coredump(bool_Bool skip_setup) { |
1463 | #if ENABLE_COREDUMP1 |
1464 | if (getpid_cached() != 1) |
1465 | return; |
1466 | |
1467 | /* Don't limit the core dump size, so that coredump handlers such as systemd-coredump (which honour the limit) |
1468 | * will process core dumps for system services by default. */ |
1469 | if (setrlimit(RLIMIT_CORERLIMIT_CORE, &RLIMIT_MAKE_CONST(RLIM_INFINITY)((struct rlimit) { 0xffffffffffffffffuLL, 0xffffffffffffffffuLL })) < 0) |
1470 | log_warning_errno(errno, "Failed to set RLIMIT_CORE: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1470, __func__, "Failed to set RLIMIT_CORE: %m" ) : -abs(_e); }); |
1471 | |
1472 | /* But at the same time, turn off the core_pattern logic by default, so that no coredumps are stored |
1473 | * until the systemd-coredump tool is enabled via sysctl. */ |
1474 | if (!skip_setup) |
1475 | disable_coredumps(); |
1476 | #endif |
1477 | } |
1478 | |
1479 | static void update_cpu_affinity(bool_Bool skip_setup) { |
1480 | _cleanup_free___attribute__((cleanup(freep))) char *mask = NULL((void*)0); |
1481 | |
1482 | if (skip_setup || !arg_cpu_affinity.set) |
1483 | return; |
1484 | |
1485 | assert(arg_cpu_affinity.allocated > 0)do { if ((__builtin_expect(!!(!(arg_cpu_affinity.allocated > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("arg_cpu_affinity.allocated > 0" ), "../src/core/main.c", 1485, __PRETTY_FUNCTION__); } while ( 0); |
1486 | |
1487 | mask = cpu_set_to_string(&arg_cpu_affinity); |
1488 | log_debug("Setting CPU affinity to %s.", strnull(mask))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1488, __func__, "Setting CPU affinity to %s." , strnull(mask)) : -abs(_e); }); |
1489 | |
1490 | if (sched_setaffinity(0, arg_cpu_affinity.allocated, arg_cpu_affinity.set) < 0) |
1491 | log_warning_errno(errno, "Failed to set CPU affinity: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1491, __func__, "Failed to set CPU affinity: %m" ) : -abs(_e); }); |
1492 | } |
1493 | |
1494 | static void update_numa_policy(bool_Bool skip_setup) { |
1495 | int r; |
1496 | _cleanup_free___attribute__((cleanup(freep))) char *nodes = NULL((void*)0); |
1497 | const char * policy = NULL((void*)0); |
1498 | |
1499 | if (skip_setup || !mpol_is_valid(numa_policy_get_type(&arg_numa_policy))) |
1500 | return; |
1501 | |
1502 | if (DEBUG_LOGGING(__builtin_expect(!!(log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= 7),0))) { |
1503 | policy = mpol_to_string(numa_policy_get_type(&arg_numa_policy)); |
1504 | nodes = cpu_set_to_range_string(&arg_numa_policy.nodes); |
1505 | log_debug("Setting NUMA policy to %s, with nodes %s.", strnull(policy), strnull(nodes))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1505, __func__, "Setting NUMA policy to %s, with nodes %s." , strnull(policy), strnull(nodes)) : -abs(_e); }); |
1506 | } |
1507 | |
1508 | r = apply_numa_policy(&arg_numa_policy); |
1509 | if (r == -EOPNOTSUPP95) |
1510 | log_debug_errno(r, "NUMA support not available, ignoring.")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1510, __func__, "NUMA support not available, ignoring." ) : -abs(_e); }); |
1511 | else if (r < 0) |
1512 | log_warning_errno(r, "Failed to set NUMA memory policy: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1512, __func__, "Failed to set NUMA memory policy: %m" ) : -abs(_e); }); |
1513 | } |
1514 | |
1515 | static void do_reexecute( |
1516 | int argc, |
1517 | char *argv[], |
1518 | const struct rlimit *saved_rlimit_nofile, |
1519 | const struct rlimit *saved_rlimit_memlock, |
1520 | FDSet *fds, |
1521 | const char *switch_root_dir, |
1522 | const char *switch_root_init, |
1523 | const char **ret_error_message) { |
1524 | |
1525 | unsigned i, j, args_size; |
1526 | const char **args; |
1527 | int r; |
1528 | |
1529 | assert(saved_rlimit_nofile)do { if ((__builtin_expect(!!(!(saved_rlimit_nofile)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_nofile"), "../src/core/main.c" , 1529, __PRETTY_FUNCTION__); } while (0); |
1530 | assert(saved_rlimit_memlock)do { if ((__builtin_expect(!!(!(saved_rlimit_memlock)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_memlock"), "../src/core/main.c" , 1530, __PRETTY_FUNCTION__); } while (0); |
1531 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 1531, __PRETTY_FUNCTION__); } while (0); |
1532 | |
1533 | /* Close and disarm the watchdog, so that the new instance can reinitialize it, but doesn't get rebooted while |
1534 | * we do that */ |
1535 | watchdog_close(true1); |
1536 | |
1537 | /* Reset the RLIMIT_NOFILE to the kernel default, so that the new systemd can pass the kernel default to its |
1538 | * child processes */ |
1539 | |
1540 | if (saved_rlimit_nofile->rlim_cur > 0) |
1541 | (void) setrlimit(RLIMIT_NOFILERLIMIT_NOFILE, saved_rlimit_nofile); |
1542 | if (saved_rlimit_memlock->rlim_cur != (rlim_t) -1) |
1543 | (void) setrlimit(RLIMIT_MEMLOCK__RLIMIT_MEMLOCK, saved_rlimit_memlock); |
1544 | |
1545 | if (switch_root_dir) { |
1546 | /* Kill all remaining processes from the initrd, but don't wait for them, so that we can handle the |
1547 | * SIGCHLD for them after deserializing. */ |
1548 | broadcast_signal(SIGTERM15, false0, true1, arg_default_timeout_stop_usec); |
1549 | |
1550 | /* And switch root with MS_MOVE, because we remove the old directory afterwards and detach it. */ |
1551 | r = switch_root(switch_root_dir, "/mnt", true1, MS_MOVEMS_MOVE); |
1552 | if (r < 0) |
1553 | log_error_errno(r, "Failed to switch root, trying to continue: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1553, __func__, "Failed to switch root, trying to continue: %m" ) : -abs(_e); }); |
1554 | } |
1555 | |
1556 | args_size = MAX(6, argc+1)__extension__ ({ const typeof((6)) __unique_prefix_A25 = ((6) ); const typeof((argc+1)) __unique_prefix_B26 = ((argc+1)); __unique_prefix_A25 > __unique_prefix_B26 ? __unique_prefix_A25 : __unique_prefix_B26 ; }); |
1557 | args = newa(const char*, args_size)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (const char*), args_size))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!size_multiply_overflow(sizeof(const char*), args_size)") , "../src/core/main.c", 1557, __PRETTY_FUNCTION__); } while ( 0); (const char**) __builtin_alloca (sizeof(const char*)*(args_size )); }); |
1558 | |
1559 | if (!switch_root_init) { |
1560 | char sfd[DECIMAL_STR_MAX(int)(2+(sizeof(int) <= 1 ? 3 : sizeof(int) <= 2 ? 5 : sizeof (int) <= 4 ? 10 : sizeof(int) <= 8 ? 20 : sizeof(int[-2 *(sizeof(int) > 8)]))) + 1]; |
1561 | |
1562 | /* First try to spawn ourselves with the right path, and with full serialization. We do this only if |
1563 | * the user didn't specify an explicit init to spawn. */ |
1564 | |
1565 | assert(arg_serialization)do { if ((__builtin_expect(!!(!(arg_serialization)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("arg_serialization"), "../src/core/main.c" , 1565, __PRETTY_FUNCTION__); } while (0); |
1566 | assert(fds)do { if ((__builtin_expect(!!(!(fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fds"), "../src/core/main.c", 1566, __PRETTY_FUNCTION__ ); } while (0); |
1567 | |
1568 | xsprintf(sfd, "%i", fileno(arg_serialization))do { if ((__builtin_expect(!!(!(((size_t) snprintf(sfd, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (sfd), typeof(&*(sfd))), sizeof(sfd)/sizeof((sfd)[0]), (( void)0))), "%i", fileno(arg_serialization)) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (sfd), typeof(&*(sfd))), sizeof(sfd)/sizeof((sfd)[0]), (( void)0))))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: " "sfd" "[] must be big enough"), "../src/core/main.c" , 1568, __PRETTY_FUNCTION__); } while (0); |
1569 | |
1570 | i = 0; |
1571 | args[i++] = SYSTEMD_BINARY_PATH"/usr/lib/systemd/systemd"; |
1572 | if (switch_root_dir) |
1573 | args[i++] = "--switched-root"; |
1574 | args[i++] = arg_system ? "--system" : "--user"; |
1575 | args[i++] = "--deserialize"; |
1576 | args[i++] = sfd; |
1577 | args[i++] = NULL((void*)0); |
1578 | |
1579 | assert(i <= args_size)do { if ((__builtin_expect(!!(!(i <= args_size)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("i <= args_size"), "../src/core/main.c" , 1579, __PRETTY_FUNCTION__); } while (0); |
1580 | |
1581 | /* |
1582 | * We want valgrind to print its memory usage summary before reexecution. Valgrind won't do this is on |
1583 | * its own on exec(), but it will do it on exit(). Hence, to ensure we get a summary here, fork() off |
1584 | * a child, let it exit() cleanly, so that it prints the summary, and wait() for it in the parent, |
1585 | * before proceeding into the exec(). |
1586 | */ |
1587 | valgrind_summary_hack(); |
1588 | |
1589 | (void) execv(args[0], (char* const*) args); |
1590 | log_debug_errno(errno, "Failed to execute our own binary, trying fallback: %m")({ int _level = ((7)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1590, __func__, "Failed to execute our own binary, trying fallback: %m" ) : -abs(_e); }); |
1591 | } |
1592 | |
1593 | /* Try the fallback, if there is any, without any serialization. We pass the original argv[] and envp[]. (Well, |
1594 | * modulo the ordering changes due to getopt() in argv[], and some cleanups in envp[], but let's hope that |
1595 | * doesn't matter.) */ |
1596 | |
1597 | arg_serialization = safe_fclose(arg_serialization); |
1598 | fds = fdset_free(fds); |
Value stored to 'fds' is never read | |
1599 | |
1600 | /* Reopen the console */ |
1601 | (void) make_console_stdio(); |
1602 | |
1603 | for (j = 1, i = 1; j < (unsigned) argc; j++) |
1604 | args[i++] = argv[j]; |
1605 | args[i++] = NULL((void*)0); |
1606 | assert(i <= args_size)do { if ((__builtin_expect(!!(!(i <= args_size)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("i <= args_size"), "../src/core/main.c" , 1606, __PRETTY_FUNCTION__); } while (0); |
1607 | |
1608 | /* Reenable any blocked signals, especially important if we switch from initial ramdisk to init=... */ |
1609 | (void) reset_all_signal_handlers(); |
1610 | (void) reset_signal_mask(); |
1611 | |
1612 | if (switch_root_init) { |
1613 | args[0] = switch_root_init; |
1614 | (void) execv(args[0], (char* const*) args); |
1615 | log_warning_errno(errno, "Failed to execute configured init, trying fallback: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1615, __func__, "Failed to execute configured init, trying fallback: %m" ) : -abs(_e); }); |
1616 | } |
1617 | |
1618 | args[0] = "/sbin/init"; |
1619 | (void) execv(args[0], (char* const*) args); |
1620 | r = -errno(*__errno_location ()); |
1621 | |
1622 | manager_status_printf(NULL((void*)0), STATUS_TYPE_EMERGENCY, |
1623 | ANSI_HIGHLIGHT_RED"\x1B[0;1;31m" " !! " ANSI_NORMAL"\x1B[0m", |
1624 | "Failed to execute /sbin/init"); |
1625 | |
1626 | if (r == -ENOENT2) { |
1627 | log_warning("No /sbin/init, trying fallback")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1627, __func__, "No /sbin/init, trying fallback" ) : -abs(_e); }); |
1628 | |
1629 | args[0] = "/bin/sh"; |
1630 | args[1] = NULL((void*)0); |
1631 | (void) execv(args[0], (char* const*) args); |
1632 | log_error_errno(errno, "Failed to execute /bin/sh, giving up: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1632, __func__, "Failed to execute /bin/sh, giving up: %m" ) : -abs(_e); }); |
1633 | } else |
1634 | log_warning_errno(r, "Failed to execute /sbin/init, giving up: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1634, __func__, "Failed to execute /sbin/init, giving up: %m" ) : -abs(_e); }); |
1635 | |
1636 | *ret_error_message = "Failed to execute fallback shell"; |
1637 | } |
1638 | |
1639 | static int invoke_main_loop( |
1640 | Manager *m, |
1641 | const struct rlimit *saved_rlimit_nofile, |
1642 | const struct rlimit *saved_rlimit_memlock, |
1643 | bool_Bool *ret_reexecute, |
1644 | int *ret_retval, /* Return parameters relevant for shutting down */ |
1645 | const char **ret_shutdown_verb, /* … */ |
1646 | FDSet **ret_fds, /* Return parameters for reexecuting */ |
1647 | char **ret_switch_root_dir, /* … */ |
1648 | char **ret_switch_root_init, /* … */ |
1649 | const char **ret_error_message) { |
1650 | |
1651 | int r; |
1652 | |
1653 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 1653, __PRETTY_FUNCTION__ ); } while (0); |
1654 | assert(saved_rlimit_nofile)do { if ((__builtin_expect(!!(!(saved_rlimit_nofile)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_nofile"), "../src/core/main.c" , 1654, __PRETTY_FUNCTION__); } while (0); |
1655 | assert(saved_rlimit_memlock)do { if ((__builtin_expect(!!(!(saved_rlimit_memlock)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_memlock"), "../src/core/main.c" , 1655, __PRETTY_FUNCTION__); } while (0); |
1656 | assert(ret_reexecute)do { if ((__builtin_expect(!!(!(ret_reexecute)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_reexecute"), "../src/core/main.c", 1656 , __PRETTY_FUNCTION__); } while (0); |
1657 | assert(ret_retval)do { if ((__builtin_expect(!!(!(ret_retval)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_retval"), "../src/core/main.c", 1657 , __PRETTY_FUNCTION__); } while (0); |
1658 | assert(ret_shutdown_verb)do { if ((__builtin_expect(!!(!(ret_shutdown_verb)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_shutdown_verb"), "../src/core/main.c" , 1658, __PRETTY_FUNCTION__); } while (0); |
1659 | assert(ret_fds)do { if ((__builtin_expect(!!(!(ret_fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_fds"), "../src/core/main.c", 1659, __PRETTY_FUNCTION__ ); } while (0); |
1660 | assert(ret_switch_root_dir)do { if ((__builtin_expect(!!(!(ret_switch_root_dir)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_switch_root_dir"), "../src/core/main.c" , 1660, __PRETTY_FUNCTION__); } while (0); |
1661 | assert(ret_switch_root_init)do { if ((__builtin_expect(!!(!(ret_switch_root_init)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_switch_root_init"), "../src/core/main.c" , 1661, __PRETTY_FUNCTION__); } while (0); |
1662 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 1662, __PRETTY_FUNCTION__); } while (0); |
1663 | |
1664 | for (;;) { |
1665 | r = manager_loop(m); |
1666 | if (r < 0) { |
1667 | *ret_error_message = "Failed to run main loop"; |
1668 | return log_emergency_errno(r, "Failed to run main loop: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1668, __func__, "Failed to run main loop: %m" ) : -abs(_e); }); |
1669 | } |
1670 | |
1671 | switch (m->exit_code) { |
1672 | |
1673 | case MANAGER_RELOAD: { |
1674 | LogTarget saved_log_target; |
1675 | int saved_log_level; |
1676 | |
1677 | log_info("Reloading.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1677, __func__, "Reloading.") : -abs( _e); }); |
1678 | |
1679 | /* First, save any overridden log level/target, then parse the configuration file, which might |
1680 | * change the log level to new settings. */ |
1681 | |
1682 | saved_log_level = m->log_level_overridden ? log_get_max_level()log_get_max_level_realm(LOG_REALM_SYSTEMD) : -1; |
1683 | saved_log_target = m->log_target_overridden ? log_get_target() : _LOG_TARGET_INVALID; |
1684 | |
1685 | (void) parse_configuration(saved_rlimit_nofile, saved_rlimit_memlock); |
1686 | |
1687 | set_manager_defaults(m); |
1688 | |
1689 | update_cpu_affinity(false0); |
1690 | update_numa_policy(false0); |
1691 | |
1692 | if (saved_log_level >= 0) |
1693 | manager_override_log_level(m, saved_log_level); |
1694 | if (saved_log_target >= 0) |
1695 | manager_override_log_target(m, saved_log_target); |
1696 | |
1697 | r = manager_reload(m); |
1698 | if (r < 0) |
1699 | log_warning_errno(r, "Failed to reload, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1699, __func__, "Failed to reload, ignoring: %m" ) : -abs(_e); }); |
1700 | |
1701 | break; |
1702 | } |
1703 | |
1704 | case MANAGER_REEXECUTE: |
1705 | |
1706 | r = prepare_reexecute(m, &arg_serialization, ret_fds, false0); |
1707 | if (r < 0) { |
1708 | *ret_error_message = "Failed to prepare for reexecution"; |
1709 | return r; |
1710 | } |
1711 | |
1712 | log_notice("Reexecuting.")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1712, __func__, "Reexecuting.") : -abs (_e); }); |
1713 | |
1714 | *ret_reexecute = true1; |
1715 | *ret_retval = EXIT_SUCCESS0; |
1716 | *ret_shutdown_verb = NULL((void*)0); |
1717 | *ret_switch_root_dir = *ret_switch_root_init = NULL((void*)0); |
1718 | |
1719 | return 0; |
1720 | |
1721 | case MANAGER_SWITCH_ROOT: |
1722 | if (!m->switch_root_init) { |
1723 | r = prepare_reexecute(m, &arg_serialization, ret_fds, true1); |
1724 | if (r < 0) { |
1725 | *ret_error_message = "Failed to prepare for reexecution"; |
1726 | return r; |
1727 | } |
1728 | } else |
1729 | *ret_fds = NULL((void*)0); |
1730 | |
1731 | log_notice("Switching root.")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1731, __func__, "Switching root.") : - abs(_e); }); |
1732 | |
1733 | *ret_reexecute = true1; |
1734 | *ret_retval = EXIT_SUCCESS0; |
1735 | *ret_shutdown_verb = NULL((void*)0); |
1736 | |
1737 | /* Steal the switch root parameters */ |
1738 | *ret_switch_root_dir = m->switch_root; |
1739 | *ret_switch_root_init = m->switch_root_init; |
1740 | m->switch_root = m->switch_root_init = NULL((void*)0); |
1741 | |
1742 | return 0; |
1743 | |
1744 | case MANAGER_EXIT: |
1745 | |
1746 | if (MANAGER_IS_USER(m)((m)->unit_file_scope != UNIT_FILE_SYSTEM)) { |
1747 | log_debug("Exit.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1747, __func__, "Exit.") : -abs(_e); } ); |
1748 | |
1749 | *ret_reexecute = false0; |
1750 | *ret_retval = m->return_value; |
1751 | *ret_shutdown_verb = NULL((void*)0); |
1752 | *ret_fds = NULL((void*)0); |
1753 | *ret_switch_root_dir = *ret_switch_root_init = NULL((void*)0); |
1754 | |
1755 | return 0; |
1756 | } |
1757 | |
1758 | _fallthrough_; |
1759 | case MANAGER_REBOOT: |
1760 | case MANAGER_POWEROFF: |
1761 | case MANAGER_HALT: |
1762 | case MANAGER_KEXEC: { |
1763 | static const char * const table[_MANAGER_EXIT_CODE_MAX] = { |
1764 | [MANAGER_EXIT] = "exit", |
1765 | [MANAGER_REBOOT] = "reboot", |
1766 | [MANAGER_POWEROFF] = "poweroff", |
1767 | [MANAGER_HALT] = "halt", |
1768 | [MANAGER_KEXEC] = "kexec" |
1769 | }; |
1770 | |
1771 | log_notice("Shutting down.")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1771, __func__, "Shutting down.") : - abs(_e); }); |
1772 | |
1773 | *ret_reexecute = false0; |
1774 | *ret_retval = m->return_value; |
1775 | assert_se(*ret_shutdown_verb = table[m->exit_code])do { if ((__builtin_expect(!!(!(*ret_shutdown_verb = table[m-> exit_code])),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "*ret_shutdown_verb = table[m->exit_code]"), "../src/core/main.c" , 1775, __PRETTY_FUNCTION__); } while (0); |
1776 | *ret_fds = NULL((void*)0); |
1777 | *ret_switch_root_dir = *ret_switch_root_init = NULL((void*)0); |
1778 | |
1779 | return 0; |
1780 | } |
1781 | |
1782 | default: |
1783 | assert_not_reached("Unknown exit code.")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "Unknown exit code."), "../src/core/main.c", 1783, __PRETTY_FUNCTION__ ); } while (0); |
1784 | } |
1785 | } |
1786 | } |
1787 | |
1788 | static void log_execution_mode(bool_Bool *ret_first_boot) { |
1789 | assert(ret_first_boot)do { if ((__builtin_expect(!!(!(ret_first_boot)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_first_boot"), "../src/core/main.c", 1789, __PRETTY_FUNCTION__); } while (0); |
1790 | |
1791 | if (arg_system) { |
1792 | int v; |
1793 | |
1794 | log_info(PACKAGE_STRING " running in %ssystem mode. (" SYSTEMD_FEATURES ")",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1795, __func__, "systemd 239" " running in %ssystem mode. (" "+PAM" " " "+AUDIT" " " "+SELINUX" " " "+IMA" " " "-APPARMOR" " " "+SMACK" " " "+SYSVINIT" " " "+UTMP" " " "+LIBCRYPTSETUP" " " "+GCRYPT" " " "+GNUTLS" " " "+ACL" " " "+XZ" " " "+LZ4" " " "+SECCOMP" " " "+BLKID" " " "+ELFUTILS" " " "+KMOD" " " "+IDN2" " " "-IDN" " " "+PCRE2" " " "default-hierarchy=" "hybrid" ")" , arg_action == ACTION_TEST ? "test " : "") : -abs(_e); }) |
1795 | arg_action == ACTION_TEST ? "test " : "" )({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1795, __func__, "systemd 239" " running in %ssystem mode. (" "+PAM" " " "+AUDIT" " " "+SELINUX" " " "+IMA" " " "-APPARMOR" " " "+SMACK" " " "+SYSVINIT" " " "+UTMP" " " "+LIBCRYPTSETUP" " " "+GCRYPT" " " "+GNUTLS" " " "+ACL" " " "+XZ" " " "+LZ4" " " "+SECCOMP" " " "+BLKID" " " "+ELFUTILS" " " "+KMOD" " " "+IDN2" " " "-IDN" " " "+PCRE2" " " "default-hierarchy=" "hybrid" ")" , arg_action == ACTION_TEST ? "test " : "") : -abs(_e); }); |
1796 | |
1797 | v = detect_virtualization(); |
1798 | if (v > 0) |
1799 | log_info("Detected virtualization %s.", virtualization_to_string(v))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1799, __func__, "Detected virtualization %s." , virtualization_to_string(v)) : -abs(_e); }); |
1800 | |
1801 | log_info("Detected architecture %s.", architecture_to_string(uname_architecture()))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1801, __func__, "Detected architecture %s." , architecture_to_string(uname_architecture())) : -abs(_e); } ); |
1802 | |
1803 | if (in_initrd()) { |
1804 | *ret_first_boot = false0; |
1805 | log_info("Running in initial RAM disk.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1805, __func__, "Running in initial RAM disk." ) : -abs(_e); }); |
1806 | } else { |
1807 | /* Let's check whether we are in first boot, i.e. whether /etc is still unpopulated. We use |
1808 | * /etc/machine-id as flag file, for this: if it exists we assume /etc is populated, if it |
1809 | * doesn't it's unpopulated. This allows container managers and installers to provision a |
1810 | * couple of files already. If the container manager wants to provision the machine ID itself |
1811 | * it should pass $container_uuid to PID 1. */ |
1812 | |
1813 | *ret_first_boot = access("/etc/machine-id", F_OK0) < 0; |
1814 | if (*ret_first_boot) |
1815 | log_info("Running with unpopulated /etc.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1815, __func__, "Running with unpopulated /etc." ) : -abs(_e); }); |
1816 | } |
1817 | } else { |
1818 | if (DEBUG_LOGGING(__builtin_expect(!!(log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= 7),0))) { |
1819 | _cleanup_free___attribute__((cleanup(freep))) char *t; |
1820 | |
1821 | t = uid_to_name(getuid()); |
1822 | log_debug(PACKAGE_STRING " running in %suser mode for user " UID_FMT "/%s. (" SYSTEMD_FEATURES ")",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1823, __func__, "systemd 239" " running in %suser mode for user " "%" "u" "/%s. (" "+PAM" " " "+AUDIT" " " "+SELINUX" " " "+IMA" " " "-APPARMOR" " " "+SMACK" " " "+SYSVINIT" " " "+UTMP" " " "+LIBCRYPTSETUP" " " "+GCRYPT" " " "+GNUTLS" " " "+ACL" " " "+XZ" " " "+LZ4" " " "+SECCOMP" " " "+BLKID" " " "+ELFUTILS" " " "+KMOD" " " "+IDN2" " " "-IDN" " " "+PCRE2" " " "default-hierarchy=" "hybrid" ")", arg_action == ACTION_TEST ? " test" : "", getuid (), strna(t)) : -abs(_e); }) |
1823 | arg_action == ACTION_TEST ? " test" : "", getuid(), strna(t))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1823, __func__, "systemd 239" " running in %suser mode for user " "%" "u" "/%s. (" "+PAM" " " "+AUDIT" " " "+SELINUX" " " "+IMA" " " "-APPARMOR" " " "+SMACK" " " "+SYSVINIT" " " "+UTMP" " " "+LIBCRYPTSETUP" " " "+GCRYPT" " " "+GNUTLS" " " "+ACL" " " "+XZ" " " "+LZ4" " " "+SECCOMP" " " "+BLKID" " " "+ELFUTILS" " " "+KMOD" " " "+IDN2" " " "-IDN" " " "+PCRE2" " " "default-hierarchy=" "hybrid" ")", arg_action == ACTION_TEST ? " test" : "", getuid (), strna(t)) : -abs(_e); }); |
1824 | } |
1825 | |
1826 | *ret_first_boot = false0; |
1827 | } |
1828 | } |
1829 | |
1830 | static int initialize_runtime( |
1831 | bool_Bool skip_setup, |
1832 | struct rlimit *saved_rlimit_nofile, |
1833 | struct rlimit *saved_rlimit_memlock, |
1834 | const char **ret_error_message) { |
1835 | |
1836 | int r; |
1837 | |
1838 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 1838, __PRETTY_FUNCTION__); } while (0); |
1839 | |
1840 | /* Sets up various runtime parameters. Many of these initializations are conditionalized: |
1841 | * |
1842 | * - Some only apply to --system instances |
1843 | * - Some only apply to --user instances |
1844 | * - Some only apply when we first start up, but not when we reexecute |
1845 | */ |
1846 | |
1847 | if (arg_action != ACTION_RUN) |
1848 | return 0; |
1849 | |
1850 | update_cpu_affinity(skip_setup); |
1851 | update_numa_policy(skip_setup); |
1852 | |
1853 | if (arg_system) { |
1854 | /* Make sure we leave a core dump without panicing the kernel. */ |
1855 | install_crash_handler(); |
1856 | |
1857 | if (!skip_setup) { |
1858 | r = mount_cgroup_controllers(arg_join_controllers); |
1859 | if (r < 0) { |
1860 | *ret_error_message = "Failed to mount cgroup hierarchies"; |
1861 | return r; |
1862 | } |
1863 | |
1864 | status_welcome(); |
1865 | hostname_setup(); |
1866 | machine_id_setup(NULL((void*)0), arg_machine_id, NULL((void*)0)); |
1867 | loopback_setup(); |
1868 | bump_unix_max_dgram_qlen(); |
1869 | test_usr(); |
1870 | write_container_id(); |
1871 | } |
1872 | |
1873 | if (arg_watchdog_device) { |
1874 | r = watchdog_set_device(arg_watchdog_device); |
1875 | if (r < 0) |
1876 | log_warning_errno(r, "Failed to set watchdog device to %s, ignoring: %m", arg_watchdog_device)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1876, __func__, "Failed to set watchdog device to %s, ignoring: %m" , arg_watchdog_device) : -abs(_e); }); |
1877 | } |
1878 | |
1879 | if (arg_runtime_watchdog > 0 && arg_runtime_watchdog != USEC_INFINITY((usec_t) -1)) |
1880 | watchdog_set_timeout(&arg_runtime_watchdog); |
1881 | } |
1882 | |
1883 | if (arg_timer_slack_nsec != NSEC_INFINITY((nsec_t) -1)) |
1884 | if (prctl(PR_SET_TIMERSLACK29, arg_timer_slack_nsec) < 0) |
1885 | log_warning_errno(errno, "Failed to adjust timer slack, ignoring: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1885, __func__, "Failed to adjust timer slack, ignoring: %m" ) : -abs(_e); }); |
1886 | |
1887 | if (arg_system && !cap_test_all(arg_capability_bounding_set)) { |
1888 | r = capability_bounding_set_drop_usermode(arg_capability_bounding_set); |
1889 | if (r < 0) { |
1890 | *ret_error_message = "Failed to drop capability bounding set of usermode helpers"; |
1891 | return log_emergency_errno(r, "Failed to drop capability bounding set of usermode helpers: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1891, __func__, "Failed to drop capability bounding set of usermode helpers: %m" ) : -abs(_e); }); |
1892 | } |
1893 | |
1894 | r = capability_bounding_set_drop(arg_capability_bounding_set, true1); |
1895 | if (r < 0) { |
1896 | *ret_error_message = "Failed to drop capability bounding set"; |
1897 | return log_emergency_errno(r, "Failed to drop capability bounding set: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1897, __func__, "Failed to drop capability bounding set: %m" ) : -abs(_e); }); |
1898 | } |
1899 | } |
1900 | |
1901 | if (arg_system && arg_no_new_privs) { |
1902 | if (prctl(PR_SET_NO_NEW_PRIVS38, 1, 0, 0, 0) < 0) { |
1903 | *ret_error_message = "Failed to disable new privileges"; |
1904 | return log_emergency_errno(errno, "Failed to disable new privileges: %m")({ int _level = ((log_emergency_level())), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 1904 , __func__, "Failed to disable new privileges: %m") : -abs(_e ); }); |
1905 | } |
1906 | } |
1907 | |
1908 | if (arg_syscall_archs) { |
1909 | r = enforce_syscall_archs(arg_syscall_archs); |
1910 | if (r < 0) { |
1911 | *ret_error_message = "Failed to set syscall architectures"; |
1912 | return r; |
1913 | } |
1914 | } |
1915 | |
1916 | if (!arg_system) |
1917 | /* Become reaper of our children */ |
1918 | if (prctl(PR_SET_CHILD_SUBREAPER36, 1) < 0) |
1919 | log_warning_errno(errno, "Failed to make us a subreaper: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1919, __func__, "Failed to make us a subreaper: %m" ) : -abs(_e); }); |
1920 | |
1921 | if (arg_system) { |
1922 | /* Bump up RLIMIT_NOFILE for systemd itself */ |
1923 | (void) bump_rlimit_nofile(saved_rlimit_nofile); |
1924 | (void) bump_rlimit_memlock(saved_rlimit_memlock); |
1925 | } |
1926 | |
1927 | return 0; |
1928 | } |
1929 | |
1930 | static int do_queue_default_job( |
1931 | Manager *m, |
1932 | const char **ret_error_message) { |
1933 | |
1934 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); |
1935 | Job *default_unit_job; |
1936 | Unit *target = NULL((void*)0); |
1937 | int r; |
1938 | |
1939 | log_debug("Activating default unit: %s", arg_default_unit)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1939, __func__, "Activating default unit: %s" , arg_default_unit) : -abs(_e); }); |
1940 | |
1941 | r = manager_load_startable_unit_or_warn(m, arg_default_unit, NULL((void*)0), &target); |
1942 | if (r < 0) { |
1943 | log_info("Falling back to rescue target: " SPECIAL_RESCUE_TARGET)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1943, __func__, "Falling back to rescue target: " "rescue.target") : -abs(_e); }); |
1944 | |
1945 | r = manager_load_startable_unit_or_warn(m, SPECIAL_RESCUE_TARGET"rescue.target", NULL((void*)0), &target); |
1946 | if (r < 0) { |
1947 | *ret_error_message = r == -ERFKILL132 ? "Rescue target masked" |
1948 | : "Failed to load rescue target"; |
1949 | return r; |
1950 | } |
1951 | } |
1952 | |
1953 | assert(target->load_state == UNIT_LOADED)do { if ((__builtin_expect(!!(!(target->load_state == UNIT_LOADED )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("target->load_state == UNIT_LOADED" ), "../src/core/main.c", 1953, __PRETTY_FUNCTION__); } while ( 0); |
1954 | |
1955 | r = manager_add_job(m, JOB_START, target, JOB_ISOLATE, NULL((void*)0), &error, &default_unit_job); |
1956 | if (r == -EPERM1) { |
1957 | log_debug_errno(r, "Default target could not be isolated, starting instead: %s", bus_error_message(&error, r))({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 1957, __func__, "Default target could not be isolated, starting instead: %s" , bus_error_message(&error, r)) : -abs(_e); }); |
1958 | |
1959 | sd_bus_error_free(&error); |
1960 | |
1961 | r = manager_add_job(m, JOB_START, target, JOB_REPLACE, NULL((void*)0), &error, &default_unit_job); |
1962 | if (r < 0) { |
1963 | *ret_error_message = "Failed to start default target"; |
1964 | return log_emergency_errno(r, "Failed to start default target: %s", bus_error_message(&error, r))({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1964, __func__, "Failed to start default target: %s" , bus_error_message(&error, r)) : -abs(_e); }); |
1965 | } |
1966 | |
1967 | } else if (r < 0) { |
1968 | *ret_error_message = "Failed to isolate default target"; |
1969 | return log_emergency_errno(r, "Failed to isolate default target: %s", bus_error_message(&error, r))({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1969, __func__, "Failed to isolate default target: %s" , bus_error_message(&error, r)) : -abs(_e); }); |
1970 | } |
1971 | |
1972 | m->default_unit_job_id = default_unit_job->id; |
1973 | |
1974 | return 0; |
1975 | } |
1976 | |
1977 | static void save_rlimits(struct rlimit *saved_rlimit_nofile, |
1978 | struct rlimit *saved_rlimit_memlock) { |
1979 | |
1980 | assert(saved_rlimit_nofile)do { if ((__builtin_expect(!!(!(saved_rlimit_nofile)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_nofile"), "../src/core/main.c" , 1980, __PRETTY_FUNCTION__); } while (0); |
1981 | assert(saved_rlimit_memlock)do { if ((__builtin_expect(!!(!(saved_rlimit_memlock)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_memlock"), "../src/core/main.c" , 1981, __PRETTY_FUNCTION__); } while (0); |
1982 | |
1983 | if (getrlimit(RLIMIT_NOFILERLIMIT_NOFILE, saved_rlimit_nofile) < 0) |
1984 | log_warning_errno(errno, "Reading RLIMIT_NOFILE failed, ignoring: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1984, __func__, "Reading RLIMIT_NOFILE failed, ignoring: %m" ) : -abs(_e); }); |
1985 | |
1986 | if (getrlimit(RLIMIT_MEMLOCK__RLIMIT_MEMLOCK, saved_rlimit_memlock) < 0) |
1987 | log_warning_errno(errno, "Reading RLIMIT_MEMLOCK failed, ignoring: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 1987, __func__, "Reading RLIMIT_MEMLOCK failed, ignoring: %m" ) : -abs(_e); }); |
1988 | } |
1989 | |
1990 | static void fallback_rlimit_nofile(const struct rlimit *saved_rlimit_nofile) { |
1991 | struct rlimit *rl; |
1992 | |
1993 | if (arg_default_rlimit[RLIMIT_NOFILERLIMIT_NOFILE]) |
1994 | return; |
1995 | |
1996 | /* Make sure forked processes get limits based on the original kernel setting */ |
1997 | |
1998 | rl = newdup(struct rlimit, saved_rlimit_nofile, 1)((struct rlimit*) memdup_multiply(saved_rlimit_nofile, sizeof (struct rlimit), (1))); |
1999 | if (!rl) { |
2000 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 2000 , __func__); |
2001 | return; |
2002 | } |
2003 | |
2004 | /* Bump the hard limit for system services to a substantially higher value. The default |
2005 | * hard limit current kernels set is pretty low (4K), mostly for historical |
2006 | * reasons. According to kernel developers, the fd handling in recent kernels has been |
2007 | * optimized substantially enough, so that we can bump the limit now, without paying too |
2008 | * high a price in memory or performance. Note however that we only bump the hard limit, |
2009 | * not the soft limit. That's because select() works the way it works, and chokes on fds |
2010 | * >= 1024. If we'd bump the soft limit globally, it might accidentally happen to |
2011 | * unexpecting programs that they get fds higher than what they can process using |
2012 | * select(). By only bumping the hard limit but leaving the low limit as it is we avoid |
2013 | * this pitfall: programs that are written by folks aware of the select() problem in mind |
2014 | * (and thus use poll()/epoll instead of select(), the way everybody should) can |
2015 | * explicitly opt into high fds by bumping their soft limit beyond 1024, to the hard limit |
2016 | * we pass. */ |
2017 | if (arg_system) { |
2018 | int nr; |
2019 | |
2020 | /* Get the underlying absolute limit the kernel enforces */ |
2021 | nr = read_nr_open(); |
2022 | |
2023 | rl->rlim_max = MIN((rlim_t) nr, MAX(rl->rlim_max, (rlim_t) HIGH_RLIMIT_NOFILE))__extension__ ({ const typeof(((rlim_t) nr)) __unique_prefix_A29 = (((rlim_t) nr)); const typeof((__extension__ ({ const typeof ((rl->rlim_max)) __unique_prefix_A27 = ((rl->rlim_max)) ; const typeof(((rlim_t) (256*1024))) __unique_prefix_B28 = ( ((rlim_t) (256*1024))); __unique_prefix_A27 > __unique_prefix_B28 ? __unique_prefix_A27 : __unique_prefix_B28; }))) __unique_prefix_B30 = ((__extension__ ({ const typeof((rl->rlim_max)) __unique_prefix_A27 = ((rl->rlim_max)); const typeof(((rlim_t) (256*1024))) __unique_prefix_B28 = (((rlim_t) (256*1024))); __unique_prefix_A27 > __unique_prefix_B28 ? __unique_prefix_A27 : __unique_prefix_B28; }))); __unique_prefix_A29 < __unique_prefix_B30 ? __unique_prefix_A29 : __unique_prefix_B30 ; }); |
2024 | } |
2025 | |
2026 | /* If for some reason we were invoked with a soft limit above 1024 (which should never |
2027 | * happen!, but who knows what we get passed in from pam_limit when invoked as --user |
2028 | * instance), then lower what we pass on to not confuse our children */ |
2029 | rl->rlim_cur = MIN(rl->rlim_cur, (rlim_t) FD_SETSIZE)__extension__ ({ const typeof((rl->rlim_cur)) __unique_prefix_A31 = ((rl->rlim_cur)); const typeof(((rlim_t) 1024)) __unique_prefix_B32 = (((rlim_t) 1024)); __unique_prefix_A31 < __unique_prefix_B32 ? __unique_prefix_A31 : __unique_prefix_B32; }); |
2030 | |
2031 | arg_default_rlimit[RLIMIT_NOFILERLIMIT_NOFILE] = rl; |
2032 | } |
2033 | |
2034 | static void fallback_rlimit_memlock(const struct rlimit *saved_rlimit_memlock) { |
2035 | struct rlimit *rl; |
2036 | |
2037 | /* Pass the original value down to invoked processes */ |
2038 | |
2039 | if (arg_default_rlimit[RLIMIT_MEMLOCK__RLIMIT_MEMLOCK]) |
2040 | return; |
2041 | |
2042 | rl = newdup(struct rlimit, saved_rlimit_memlock, 1)((struct rlimit*) memdup_multiply(saved_rlimit_memlock, sizeof (struct rlimit), (1))); |
2043 | if (!rl) { |
2044 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 2044 , __func__); |
2045 | return; |
2046 | } |
2047 | |
2048 | arg_default_rlimit[RLIMIT_MEMLOCK__RLIMIT_MEMLOCK] = rl; |
2049 | } |
2050 | |
2051 | static void reset_arguments(void) { |
2052 | /* Frees/resets arg_* variables, with a few exceptions commented below. */ |
2053 | |
2054 | arg_default_unit = mfree(arg_default_unit); |
2055 | |
2056 | /* arg_system — ignore */ |
2057 | |
2058 | arg_dump_core = true1; |
2059 | arg_crash_chvt = -1; |
2060 | arg_crash_shell = false0; |
2061 | arg_crash_reboot = false0; |
2062 | arg_confirm_spawn = mfree(arg_confirm_spawn); |
2063 | arg_join_controllers = strv_free_free(arg_join_controllers); |
2064 | arg_show_status = _SHOW_STATUS_UNSET; |
2065 | arg_switched_root = false0; |
2066 | arg_no_pager = false0; |
2067 | arg_service_watchdogs = true1; |
2068 | arg_default_std_output = EXEC_OUTPUT_JOURNAL; |
2069 | arg_default_std_error = EXEC_OUTPUT_INHERIT; |
2070 | arg_default_restart_usec = DEFAULT_RESTART_USEC(100*((usec_t) 1000ULL)); |
2071 | arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC(90*((usec_t) 1000000ULL)); |
2072 | arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC(90*((usec_t) 1000000ULL)); |
2073 | arg_default_timeout_abort_usec = DEFAULT_TIMEOUT_USEC(90*((usec_t) 1000000ULL)); |
2074 | arg_default_timeout_abort_set = false0; |
2075 | arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL(10*((usec_t) 1000000ULL)); |
2076 | arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST5; |
2077 | arg_runtime_watchdog = 0; |
2078 | arg_shutdown_watchdog = 10 * USEC_PER_MINUTE((usec_t) (60ULL*((usec_t) 1000000ULL))); |
2079 | arg_early_core_pattern = NULL((void*)0); |
2080 | arg_watchdog_device = NULL((void*)0); |
2081 | |
2082 | arg_default_environment = strv_free(arg_default_environment); |
2083 | rlimit_free_all(arg_default_rlimit); |
2084 | |
2085 | arg_capability_bounding_set = CAP_ALL(uint64_t) -1; |
2086 | arg_no_new_privs = false0; |
2087 | arg_timer_slack_nsec = NSEC_INFINITY((nsec_t) -1); |
2088 | arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE((usec_t) (60ULL*((usec_t) 1000000ULL))); |
2089 | |
2090 | arg_syscall_archs = set_free(arg_syscall_archs); |
2091 | |
2092 | /* arg_serialization — ignore */ |
2093 | |
2094 | arg_default_cpu_accounting = 0; |
2095 | arg_default_io_accounting = false0; |
2096 | arg_default_ip_accounting = false0; |
2097 | arg_default_blockio_accounting = false0; |
2098 | arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT1; |
2099 | arg_default_tasks_accounting = true1; |
2100 | arg_default_tasks_max = system_tasks_max_scale(DEFAULT_TASKS_MAX_PERCENTAGE80U, 100U); |
2101 | arg_machine_id = (sd_id128_t) {}; |
2102 | arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE; |
2103 | |
2104 | cpu_set_reset(&arg_cpu_affinity); |
2105 | numa_policy_reset(&arg_numa_policy); |
2106 | } |
2107 | |
2108 | static int parse_configuration(const struct rlimit *saved_rlimit_nofile, |
2109 | const struct rlimit *saved_rlimit_memlock) { |
2110 | int r; |
2111 | |
2112 | assert(saved_rlimit_nofile)do { if ((__builtin_expect(!!(!(saved_rlimit_nofile)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_nofile"), "../src/core/main.c" , 2112, __PRETTY_FUNCTION__); } while (0); |
2113 | assert(saved_rlimit_memlock)do { if ((__builtin_expect(!!(!(saved_rlimit_memlock)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_memlock"), "../src/core/main.c" , 2113, __PRETTY_FUNCTION__); } while (0); |
2114 | |
2115 | /* Assign configuration defaults */ |
2116 | reset_arguments(); |
2117 | |
2118 | r = parse_config_file(); |
2119 | if (r < 0) |
2120 | log_warning_errno(r, "Failed to parse config file, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2120, __func__, "Failed to parse config file, ignoring: %m" ) : -abs(_e); }); |
2121 | |
2122 | if (arg_system) { |
2123 | r = proc_cmdline_parse(parse_proc_cmdline_item, NULL((void*)0), 0); |
2124 | if (r < 0) |
2125 | log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2125, __func__, "Failed to parse kernel command line, ignoring: %m" ) : -abs(_e); }); |
2126 | } |
2127 | |
2128 | /* Initialize some default rlimits for services if they haven't been configured */ |
2129 | fallback_rlimit_nofile(saved_rlimit_nofile); |
2130 | fallback_rlimit_memlock(saved_rlimit_memlock); |
2131 | |
2132 | /* Note that this also parses bits from the kernel command line, including "debug". */ |
2133 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); |
2134 | |
2135 | return 0; |
2136 | } |
2137 | |
2138 | static int load_configuration( |
2139 | int argc, |
2140 | char **argv, |
2141 | const struct rlimit *saved_rlimit_nofile, |
2142 | const struct rlimit *saved_rlimit_memlock, |
2143 | const char **ret_error_message) { |
2144 | int r; |
2145 | |
2146 | assert(saved_rlimit_nofile)do { if ((__builtin_expect(!!(!(saved_rlimit_nofile)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_nofile"), "../src/core/main.c" , 2146, __PRETTY_FUNCTION__); } while (0); |
2147 | assert(saved_rlimit_memlock)do { if ((__builtin_expect(!!(!(saved_rlimit_memlock)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("saved_rlimit_memlock"), "../src/core/main.c" , 2147, __PRETTY_FUNCTION__); } while (0); |
2148 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 2148, __PRETTY_FUNCTION__); } while (0); |
2149 | |
2150 | (void) parse_configuration(saved_rlimit_nofile, saved_rlimit_memlock); |
2151 | |
2152 | r = parse_argv(argc, argv); |
2153 | if (r < 0) { |
2154 | *ret_error_message = "Failed to parse commandline arguments"; |
2155 | return r; |
2156 | } |
2157 | |
2158 | /* Initialize default unit */ |
2159 | if (!arg_default_unit) { |
2160 | arg_default_unit = strdup(SPECIAL_DEFAULT_TARGET"default.target"); |
2161 | if (!arg_default_unit) { |
2162 | *ret_error_message = "Failed to set default unit"; |
2163 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/core/main.c", 2163 , __func__); |
2164 | } |
2165 | } |
2166 | |
2167 | /* Initialize the show status setting if it hasn't been set explicitly yet */ |
2168 | if (arg_show_status == _SHOW_STATUS_UNSET) |
2169 | arg_show_status = SHOW_STATUS_YES; |
2170 | |
2171 | return 0; |
2172 | } |
2173 | |
2174 | static int safety_checks(void) { |
2175 | |
2176 | if (getpid_cached() == 1 && |
2177 | arg_action != ACTION_RUN) { |
2178 | log_error("Unsupported execution mode while PID 1.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2178, __func__, "Unsupported execution mode while PID 1." ) : -abs(_e); }); |
2179 | return -EPERM1; |
2180 | } |
2181 | |
2182 | if (getpid_cached() == 1 && |
2183 | !arg_system) { |
2184 | log_error("Can't run --user mode as PID 1.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2184, __func__, "Can't run --user mode as PID 1." ) : -abs(_e); }); |
2185 | return -EPERM1; |
2186 | } |
2187 | |
2188 | if (arg_action == ACTION_RUN && |
2189 | arg_system && |
2190 | getpid_cached() != 1) { |
2191 | log_error("Can't run system mode unless PID 1.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2191, __func__, "Can't run system mode unless PID 1." ) : -abs(_e); }); |
2192 | return -EPERM1; |
2193 | } |
2194 | |
2195 | if (arg_action == ACTION_TEST && |
2196 | geteuid() == 0) { |
2197 | log_error("Don't run test mode as root.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2197, __func__, "Don't run test mode as root." ) : -abs(_e); }); |
2198 | return -EPERM1; |
2199 | } |
2200 | |
2201 | if (!arg_system && |
2202 | arg_action == ACTION_RUN && |
2203 | sd_booted() <= 0) { |
2204 | log_error("Trying to run as user instance, but the system has not been booted with systemd.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2204, __func__, "Trying to run as user instance, but the system has not been booted with systemd." ) : -abs(_e); }); |
2205 | return -EOPNOTSUPP95; |
2206 | } |
2207 | |
2208 | if (!arg_system && |
2209 | arg_action == ACTION_RUN && |
2210 | !getenv("XDG_RUNTIME_DIR")) { |
2211 | log_error("Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2211, __func__, "Trying to run as user instance, but $XDG_RUNTIME_DIR is not set." ) : -abs(_e); }); |
2212 | return -EUNATCH49; |
2213 | } |
2214 | |
2215 | if (arg_system && |
2216 | arg_action == ACTION_RUN && |
2217 | running_in_chroot() > 0) { |
2218 | log_error("Cannot be run in a chroot() environment.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2218, __func__, "Cannot be run in a chroot() environment." ) : -abs(_e); }); |
2219 | return -EOPNOTSUPP95; |
2220 | } |
2221 | |
2222 | return 0; |
2223 | } |
2224 | |
2225 | static int initialize_security( |
2226 | bool_Bool *loaded_policy, |
2227 | dual_timestamp *security_start_timestamp, |
2228 | dual_timestamp *security_finish_timestamp, |
2229 | const char **ret_error_message) { |
2230 | |
2231 | int r; |
2232 | |
2233 | assert(loaded_policy)do { if ((__builtin_expect(!!(!(loaded_policy)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("loaded_policy"), "../src/core/main.c", 2233 , __PRETTY_FUNCTION__); } while (0); |
2234 | assert(security_start_timestamp)do { if ((__builtin_expect(!!(!(security_start_timestamp)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("security_start_timestamp" ), "../src/core/main.c", 2234, __PRETTY_FUNCTION__); } while ( 0); |
2235 | assert(security_finish_timestamp)do { if ((__builtin_expect(!!(!(security_finish_timestamp)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("security_finish_timestamp" ), "../src/core/main.c", 2235, __PRETTY_FUNCTION__); } while ( 0); |
2236 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 2236, __PRETTY_FUNCTION__); } while (0); |
2237 | |
2238 | dual_timestamp_get(security_start_timestamp); |
2239 | |
2240 | r = mac_selinux_setup(loaded_policy); |
2241 | if (r < 0) { |
2242 | *ret_error_message = "Failed to load SELinux policy"; |
2243 | return r; |
2244 | } |
2245 | |
2246 | r = mac_smack_setup(loaded_policy); |
2247 | if (r < 0) { |
2248 | *ret_error_message = "Failed to load SMACK policy"; |
2249 | return r; |
2250 | } |
2251 | |
2252 | r = ima_setup(); |
2253 | if (r < 0) { |
2254 | *ret_error_message = "Failed to load IMA policy"; |
2255 | return r; |
2256 | } |
2257 | |
2258 | dual_timestamp_get(security_finish_timestamp); |
2259 | return 0; |
2260 | } |
2261 | |
2262 | static void test_summary(Manager *m) { |
2263 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/main.c", 2263, __PRETTY_FUNCTION__ ); } while (0); |
2264 | |
2265 | printf("-> By units:\n"); |
2266 | manager_dump_units(m, stdoutstdout, "\t"); |
2267 | |
2268 | printf("-> By jobs:\n"); |
2269 | manager_dump_jobs(m, stdoutstdout, "\t"); |
2270 | } |
2271 | |
2272 | static int collect_fds(FDSet **ret_fds, const char **ret_error_message) { |
2273 | int r; |
2274 | |
2275 | assert(ret_fds)do { if ((__builtin_expect(!!(!(ret_fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_fds"), "../src/core/main.c", 2275, __PRETTY_FUNCTION__ ); } while (0); |
2276 | assert(ret_error_message)do { if ((__builtin_expect(!!(!(ret_error_message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret_error_message"), "../src/core/main.c" , 2276, __PRETTY_FUNCTION__); } while (0); |
2277 | |
2278 | r = fdset_new_fill(ret_fds); |
2279 | if (r < 0) { |
2280 | *ret_error_message = "Failed to allocate fd set"; |
2281 | return log_emergency_errno(r, "Failed to allocate fd set: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 2281, __func__, "Failed to allocate fd set: %m" ) : -abs(_e); }); |
2282 | } |
2283 | |
2284 | fdset_cloexec(*ret_fds, true1); |
2285 | |
2286 | if (arg_serialization) |
2287 | assert_se(fdset_remove(*ret_fds, fileno(arg_serialization)) >= 0)do { if ((__builtin_expect(!!(!(fdset_remove(*ret_fds, fileno (arg_serialization)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("fdset_remove(*ret_fds, fileno(arg_serialization)) >= 0" ), "../src/core/main.c", 2287, __PRETTY_FUNCTION__); } while ( 0); |
2288 | |
2289 | return 0; |
2290 | } |
2291 | |
2292 | static void setup_console_terminal(bool_Bool skip_setup) { |
2293 | |
2294 | if (!arg_system) |
2295 | return; |
2296 | |
2297 | /* Become a session leader if we aren't one yet. */ |
2298 | (void) setsid(); |
2299 | |
2300 | /* If we are init, we connect stdin/stdout/stderr to /dev/null and make sure we don't have a controlling |
2301 | * tty. */ |
2302 | (void) release_terminal(); |
2303 | |
2304 | /* Reset the console, but only if this is really init and we are freshly booted */ |
2305 | if (getpid_cached() == 1 && !skip_setup) |
2306 | (void) console_setup(); |
2307 | } |
2308 | |
2309 | static bool_Bool early_skip_setup_check(int argc, char *argv[]) { |
2310 | bool_Bool found_deserialize = false0; |
2311 | int i; |
2312 | |
2313 | /* Determine if this is a reexecution or normal bootup. We do the full command line parsing much later, so |
2314 | * let's just have a quick peek here. Note that if we have switched root, do all the special setup things |
2315 | * anyway, even if in that case we also do deserialization. */ |
2316 | |
2317 | for (i = 1; i < argc; i++) { |
2318 | if (streq(argv[i], "--switched-root")(strcmp((argv[i]),("--switched-root")) == 0)) |
2319 | return false0; /* If we switched root, don't skip the setup. */ |
2320 | else if (streq(argv[i], "--deserialize")(strcmp((argv[i]),("--deserialize")) == 0)) |
2321 | found_deserialize = true1; |
2322 | } |
2323 | |
2324 | return found_deserialize; /* When we are deserializing, then we are reexecuting, hence avoid the extensive setup */ |
2325 | } |
2326 | |
2327 | int main(int argc, char *argv[]) { |
2328 | |
2329 | dual_timestamp initrd_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}), userspace_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}), kernel_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}), |
2330 | security_start_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}), security_finish_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}); |
2331 | struct rlimit saved_rlimit_nofile = RLIMIT_MAKE_CONST(0)((struct rlimit) { 0, 0 }), saved_rlimit_memlock = RLIMIT_MAKE_CONST((rlim_t) -1)((struct rlimit) { (rlim_t) -1, (rlim_t) -1 }); |
2332 | bool_Bool skip_setup, loaded_policy = false0, queue_default_job = false0, first_boot = false0, reexecute = false0; |
2333 | char *switch_root_dir = NULL((void*)0), *switch_root_init = NULL((void*)0); |
2334 | usec_t before_startup, after_startup; |
2335 | static char systemd[] = "systemd"; |
2336 | char timespan[FORMAT_TIMESPAN_MAX64]; |
2337 | const char *shutdown_verb = NULL((void*)0), *error_message = NULL((void*)0); |
2338 | int r, retval = EXIT_FAILURE1; |
2339 | Manager *m = NULL((void*)0); |
2340 | FDSet *fds = NULL((void*)0); |
2341 | |
2342 | /* SysV compatibility: redirect init → telinit */ |
2343 | redirect_telinit(argc, argv); |
2344 | |
2345 | /* Take timestamps early on */ |
2346 | dual_timestamp_from_monotonic(&kernel_timestamp, 0); |
2347 | dual_timestamp_get(&userspace_timestamp); |
2348 | |
2349 | /* Figure out whether we need to do initialize the system, or if we already did that because we are |
2350 | * reexecuting */ |
2351 | skip_setup = early_skip_setup_check(argc, argv); |
2352 | |
2353 | /* If we get started via the /sbin/init symlink then we are called 'init'. After a subsequent reexecution we |
2354 | * are then called 'systemd'. That is confusing, hence let's call us systemd right-away. */ |
2355 | program_invocation_short_name = systemd; |
2356 | (void) prctl(PR_SET_NAME15, systemd); |
2357 | |
2358 | /* Save the original command line */ |
2359 | saved_argv = argv; |
2360 | saved_argc = argc; |
2361 | |
2362 | /* Make sure that if the user says "syslog" we actually log to the journal. */ |
2363 | log_set_upgrade_syslog_to_journal(true1); |
2364 | |
2365 | if (getpid_cached() == 1) { |
2366 | /* When we run as PID 1 force system mode */ |
2367 | arg_system = true1; |
2368 | |
2369 | /* Disable the umask logic */ |
2370 | umask(0); |
2371 | |
2372 | /* Make sure that at least initially we do not ever log to journald/syslogd, because it might not be |
2373 | * activated yet (even though the log socket for it exists). */ |
2374 | log_set_prohibit_ipc(true1); |
2375 | |
2376 | /* Always reopen /dev/console when running as PID 1 or one of its pre-execve() children. This is |
2377 | * important so that we never end up logging to any foreign stderr, for example if we have to log in a |
2378 | * child process right before execve()'ing the actual binary, at a point in time where socket |
2379 | * activation stderr/stdout area already set up. */ |
2380 | log_set_always_reopen_console(true1); |
2381 | |
2382 | if (detect_container() <= 0) { |
2383 | |
2384 | /* Running outside of a container as PID 1 */ |
2385 | log_set_target(LOG_TARGET_KMSG); |
2386 | log_open(); |
2387 | |
2388 | if (in_initrd()) |
2389 | initrd_timestamp = userspace_timestamp; |
2390 | |
2391 | if (!skip_setup) { |
2392 | r = mount_setup_early(); |
2393 | if (r < 0) { |
2394 | error_message = "Failed to mount early API filesystems"; |
2395 | goto finish; |
2396 | } |
2397 | |
2398 | /* Let's open the log backend a second time, in case the first time didn't |
2399 | * work. Quite possibly we have mounted /dev just now, so /dev/kmsg became |
2400 | * available, and it previously wasn't. */ |
2401 | log_open(); |
2402 | |
2403 | r = initialize_security( |
2404 | &loaded_policy, |
2405 | &security_start_timestamp, |
2406 | &security_finish_timestamp, |
2407 | &error_message); |
2408 | if (r < 0) |
2409 | goto finish; |
2410 | } |
2411 | |
2412 | if (mac_selinux_init() < 0) { |
2413 | error_message = "Failed to initialize SELinux policy"; |
2414 | goto finish; |
2415 | } |
2416 | |
2417 | if (!skip_setup) |
2418 | initialize_clock(); |
2419 | |
2420 | /* Set the default for later on, but don't actually open the logs like this for now. Note that |
2421 | * if we are transitioning from the initrd there might still be journal fd open, and we |
2422 | * shouldn't attempt opening that before we parsed /proc/cmdline which might redirect output |
2423 | * elsewhere. */ |
2424 | log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); |
2425 | |
2426 | } else { |
2427 | /* Running inside a container, as PID 1 */ |
2428 | log_set_target(LOG_TARGET_CONSOLE); |
2429 | log_open(); |
2430 | |
2431 | /* For later on, see above... */ |
2432 | log_set_target(LOG_TARGET_JOURNAL); |
2433 | |
2434 | /* clear the kernel timestamp, |
2435 | * because we are in a container */ |
2436 | kernel_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}); |
2437 | } |
2438 | |
2439 | initialize_coredump(skip_setup); |
2440 | |
2441 | r = fixup_environment(); |
2442 | if (r < 0) { |
2443 | log_emergency_errno(r, "Failed to fix up PID 1 environment: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 2443, __func__, "Failed to fix up PID 1 environment: %m" ) : -abs(_e); }); |
2444 | error_message = "Failed to fix up PID1 environment"; |
2445 | goto finish; |
2446 | } |
2447 | |
2448 | } else { |
2449 | /* Running as user instance */ |
2450 | arg_system = false0; |
2451 | log_set_target(LOG_TARGET_AUTO); |
2452 | log_open(); |
2453 | |
2454 | /* clear the kernel timestamp, |
2455 | * because we are not PID 1 */ |
2456 | kernel_timestamp = DUAL_TIMESTAMP_NULL((struct dual_timestamp) {}); |
2457 | } |
2458 | |
2459 | if (arg_system) { |
2460 | /* Try to figure out if we can use colors with the console. No need to do that for user instances since |
2461 | * they never log into the console. */ |
2462 | log_show_color(colors_enabled()); |
2463 | |
2464 | r = make_null_stdio(); |
2465 | if (r < 0) |
2466 | log_warning_errno(r, "Failed to redirect standard streams to /dev/null, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2466, __func__, "Failed to redirect standard streams to /dev/null, ignoring: %m" ) : -abs(_e); }); |
2467 | } |
2468 | |
2469 | /* Mount /proc, /sys and friends, so that /proc/cmdline and |
2470 | * /proc/$PID/fd is available. */ |
2471 | if (getpid_cached() == 1) { |
2472 | |
2473 | /* Load the kernel modules early. */ |
2474 | if (!skip_setup) |
2475 | kmod_setup(); |
2476 | |
2477 | r = mount_setup(loaded_policy); |
2478 | if (r < 0) { |
2479 | error_message = "Failed to mount API filesystems"; |
2480 | goto finish; |
2481 | } |
2482 | } |
2483 | |
2484 | /* Save the original RLIMIT_NOFILE/RLIMIT_MEMLOCK so that we can reset it later when |
2485 | * transitioning from the initrd to the main systemd or suchlike. */ |
2486 | save_rlimits(&saved_rlimit_nofile, &saved_rlimit_memlock); |
2487 | |
2488 | /* Reset all signal handlers. */ |
2489 | (void) reset_all_signal_handlers(); |
2490 | (void) ignore_signals(SIGNALS_IGNORE13, -1); |
2491 | |
2492 | r = load_configuration(argc, argv, &saved_rlimit_nofile, &saved_rlimit_memlock, &error_message); |
2493 | if (r < 0) |
2494 | goto finish; |
2495 | |
2496 | r = safety_checks(); |
2497 | if (r < 0) |
2498 | goto finish; |
2499 | |
2500 | if (IN_SET(arg_action, ACTION_TEST, ACTION_HELP, ACTION_DUMP_CONFIGURATION_ITEMS, ACTION_DUMP_BUS_PROPERTIES)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){ACTION_TEST, ACTION_HELP, ACTION_DUMP_CONFIGURATION_ITEMS , ACTION_DUMP_BUS_PROPERTIES})/sizeof(int)]; switch(arg_action ) { case ACTION_TEST: case ACTION_HELP: case ACTION_DUMP_CONFIGURATION_ITEMS : case ACTION_DUMP_BUS_PROPERTIES: _found = 1; break; default : break; } _found; })) |
2501 | (void) pager_open(arg_no_pager, false0); |
2502 | |
2503 | if (arg_action != ACTION_RUN) |
2504 | skip_setup = true1; |
2505 | |
2506 | if (arg_action == ACTION_HELP) { |
2507 | retval = help(); |
2508 | goto finish; |
2509 | } else if (arg_action == ACTION_VERSION) { |
2510 | retval = version(); |
2511 | goto finish; |
2512 | } else if (arg_action == ACTION_DUMP_CONFIGURATION_ITEMS) { |
2513 | unit_dump_config_items(stdoutstdout); |
2514 | retval = EXIT_SUCCESS0; |
2515 | goto finish; |
2516 | } else if (arg_action == ACTION_DUMP_BUS_PROPERTIES) { |
2517 | dump_bus_properties(stdoutstdout); |
2518 | retval = EXIT_SUCCESS0; |
2519 | goto finish; |
2520 | } |
2521 | |
2522 | assert_se(IN_SET(arg_action, ACTION_RUN, ACTION_TEST))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){ACTION_RUN, ACTION_TEST})/sizeof(int)]; switch (arg_action) { case ACTION_RUN: case ACTION_TEST: _found = 1; break; default: break; } _found; }))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("IN_SET(arg_action, ACTION_RUN, ACTION_TEST)" ), "../src/core/main.c", 2522, __PRETTY_FUNCTION__); } while ( 0); |
2523 | |
2524 | /* Move out of the way, so that we won't block unmounts */ |
2525 | assert_se(chdir("/") == 0)do { if ((__builtin_expect(!!(!(chdir("/") == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("chdir(\"/\") == 0"), "../src/core/main.c" , 2525, __PRETTY_FUNCTION__); } while (0); |
2526 | |
2527 | if (arg_action == ACTION_RUN) { |
2528 | |
2529 | /* Close logging fds, in order not to confuse collecting passed fds and terminal logic below */ |
2530 | log_close(); |
2531 | |
2532 | /* Remember open file descriptors for later deserialization */ |
2533 | r = collect_fds(&fds, &error_message); |
2534 | if (r < 0) |
2535 | goto finish; |
2536 | |
2537 | /* Give up any control of the console, but make sure its initialized. */ |
2538 | setup_console_terminal(skip_setup); |
2539 | |
2540 | /* Open the logging devices, if possible and necessary */ |
2541 | log_open(); |
2542 | } |
2543 | |
2544 | log_execution_mode(&first_boot); |
2545 | |
2546 | r = initialize_runtime(skip_setup, |
2547 | &saved_rlimit_nofile, |
2548 | &saved_rlimit_memlock, |
2549 | &error_message); |
2550 | if (r < 0) |
2551 | goto finish; |
2552 | |
2553 | r = manager_new(arg_system ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, |
2554 | arg_action == ACTION_TEST ? MANAGER_TEST_FULL : 0, |
2555 | &m); |
2556 | if (r < 0) { |
2557 | log_emergency_errno(r, "Failed to allocate manager object: %m")({ int _level = ((log_emergency_level())), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/core/main.c", 2557, __func__, "Failed to allocate manager object: %m" ) : -abs(_e); }); |
2558 | error_message = "Failed to allocate manager object"; |
2559 | goto finish; |
2560 | } |
2561 | |
2562 | m->timestamps[MANAGER_TIMESTAMP_KERNEL] = kernel_timestamp; |
2563 | m->timestamps[MANAGER_TIMESTAMP_INITRD] = initrd_timestamp; |
2564 | m->timestamps[MANAGER_TIMESTAMP_USERSPACE] = userspace_timestamp; |
2565 | m->timestamps[MANAGER_TIMESTAMP_SECURITY_START] = security_start_timestamp; |
2566 | m->timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH] = security_finish_timestamp; |
2567 | |
2568 | set_manager_defaults(m); |
2569 | set_manager_settings(m); |
2570 | manager_set_first_boot(m, first_boot); |
2571 | |
2572 | /* Remember whether we should queue the default job */ |
2573 | queue_default_job = !arg_serialization || arg_switched_root; |
2574 | |
2575 | before_startup = now(CLOCK_MONOTONIC1); |
2576 | |
2577 | r = manager_startup(m, arg_serialization, fds); |
2578 | if (r < 0) { |
2579 | log_error_errno(r, "Failed to fully start up daemon: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2579, __func__, "Failed to fully start up daemon: %m" ) : -abs(_e); }); |
2580 | error_message = "Failed to start up manager"; |
2581 | goto finish; |
2582 | } |
2583 | |
2584 | /* This will close all file descriptors that were opened, but not claimed by any unit. */ |
2585 | fds = fdset_free(fds); |
2586 | arg_serialization = safe_fclose(arg_serialization); |
2587 | |
2588 | if (queue_default_job) { |
2589 | r = do_queue_default_job(m, &error_message); |
2590 | if (r < 0) |
2591 | goto finish; |
2592 | } |
2593 | |
2594 | after_startup = now(CLOCK_MONOTONIC1); |
2595 | |
2596 | log_full(arg_action == ACTION_TEST ? LOG_INFO : LOG_DEBUG,({ int _level = (((arg_action == ACTION_TEST ? 6 : 7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 2598 , __func__, "Loaded units and determined initial transaction in %s." , format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * ((usec_t) 1000ULL))) : -abs(_e); }) |
2597 | "Loaded units and determined initial transaction in %s.",({ int _level = (((arg_action == ACTION_TEST ? 6 : 7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 2598 , __func__, "Loaded units and determined initial transaction in %s." , format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * ((usec_t) 1000ULL))) : -abs(_e); }) |
2598 | format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * USEC_PER_MSEC))({ int _level = (((arg_action == ACTION_TEST ? 6 : 7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/core/main.c", 2598 , __func__, "Loaded units and determined initial transaction in %s." , format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * ((usec_t) 1000ULL))) : -abs(_e); }); |
2599 | |
2600 | if (arg_action == ACTION_TEST) { |
2601 | test_summary(m); |
2602 | retval = EXIT_SUCCESS0; |
2603 | goto finish; |
2604 | } |
2605 | |
2606 | (void) invoke_main_loop(m, |
2607 | &saved_rlimit_nofile, |
2608 | &saved_rlimit_memlock, |
2609 | &reexecute, |
2610 | &retval, |
2611 | &shutdown_verb, |
2612 | &fds, |
2613 | &switch_root_dir, |
2614 | &switch_root_init, |
2615 | &error_message); |
2616 | |
2617 | finish: |
2618 | pager_close(); |
2619 | |
2620 | if (m) { |
2621 | arg_shutdown_watchdog = m->shutdown_watchdog; |
2622 | m = manager_free(m); |
2623 | } |
2624 | |
2625 | reset_arguments(); |
2626 | mac_selinux_finish(); |
2627 | |
2628 | if (reexecute) |
2629 | do_reexecute(argc, argv, |
2630 | &saved_rlimit_nofile, |
2631 | &saved_rlimit_memlock, |
2632 | fds, |
2633 | switch_root_dir, |
2634 | switch_root_init, |
2635 | &error_message); /* This only returns if reexecution failed */ |
2636 | |
2637 | arg_serialization = safe_fclose(arg_serialization); |
2638 | fds = fdset_free(fds); |
2639 | |
2640 | #if HAVE_VALGRIND_VALGRIND_H1 |
2641 | /* If we are PID 1 and running under valgrind, then let's exit |
2642 | * here explicitly. valgrind will only generate nice output on |
2643 | * exit(), not on exec(), hence let's do the former not the |
2644 | * latter here. */ |
2645 | if (getpid_cached() == 1 && RUNNING_ON_VALGRIND(unsigned)__extension__ ({ volatile unsigned long int _zzq_args [6]; volatile unsigned long int _zzq_result; _zzq_args[0] = ( unsigned long int)(VG_USERREQ__RUNNING_ON_VALGRIND); _zzq_args [1] = (unsigned long int)(0); _zzq_args[2] = (unsigned long int )(0); _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = ( unsigned long int)(0); _zzq_args[5] = (unsigned long int)(0); __asm__ volatile("rolq $3, %%rdi ; rolq $13, %%rdi\n\t" "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" : "=d" (_zzq_result) : "a" (&_zzq_args [0]), "0" (0) : "cc", "memory" ); _zzq_result; })) { |
2646 | /* Cleanup watchdog_device strings for valgrind. We need them |
2647 | * in become_shutdown() so normally we cannot free them yet. */ |
2648 | watchdog_free_device(); |
2649 | arg_watchdog_device = mfree(arg_watchdog_device); |
2650 | return retval; |
2651 | } |
2652 | #endif |
2653 | |
2654 | if (shutdown_verb) { |
2655 | r = become_shutdown(shutdown_verb, retval); |
2656 | log_error_errno(r, "Failed to execute shutdown binary, %s: %m", getpid_cached() == 1 ? "freezing" : "quitting")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/main.c", 2656, __func__, "Failed to execute shutdown binary, %s: %m" , getpid_cached() == 1 ? "freezing" : "quitting") : -abs(_e); }); |
2657 | error_message = "Failed to execute shutdown binary"; |
2658 | } |
2659 | |
2660 | watchdog_free_device(); |
2661 | arg_watchdog_device = mfree(arg_watchdog_device); |
2662 | |
2663 | if (getpid_cached() == 1) { |
2664 | if (error_message) |
2665 | manager_status_printf(NULL((void*)0), STATUS_TYPE_EMERGENCY, |
2666 | ANSI_HIGHLIGHT_RED"\x1B[0;1;31m" "!!!!!!" ANSI_NORMAL"\x1B[0m", |
2667 | "%s, freezing.", error_message); |
2668 | freeze_or_reboot(); |
2669 | } |
2670 | |
2671 | return retval; |
2672 | } |