]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemctl/systemctl.c
Merge pull request #18481 from keszybz/rpm-restart-post-trans
[thirdparty/systemd.git] / src / systemctl / systemctl.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <getopt.h>
4 #include <locale.h>
5 #include <unistd.h>
6
7 #include "sd-daemon.h"
8
9 #include "bus-util.h"
10 #include "install.h"
11 #include "main-func.h"
12 #include "output-mode.h"
13 #include "pager.h"
14 #include "parse-argument.h"
15 #include "path-util.h"
16 #include "pretty-print.h"
17 #include "rlimit-util.h"
18 #include "sigbus.h"
19 #include "signal-util.h"
20 #include "string-table.h"
21 #include "systemctl-add-dependency.h"
22 #include "systemctl-cancel-job.h"
23 #include "systemctl-clean-or-freeze.h"
24 #include "systemctl-compat-halt.h"
25 #include "systemctl-compat-runlevel.h"
26 #include "systemctl-compat-shutdown.h"
27 #include "systemctl-compat-telinit.h"
28 #include "systemctl-daemon-reload.h"
29 #include "systemctl-edit.h"
30 #include "systemctl-enable.h"
31 #include "systemctl-is-active.h"
32 #include "systemctl-is-enabled.h"
33 #include "systemctl-is-system-running.h"
34 #include "systemctl-kill.h"
35 #include "systemctl-list-dependencies.h"
36 #include "systemctl-list-jobs.h"
37 #include "systemctl-list-machines.h"
38 #include "systemctl-list-unit-files.h"
39 #include "systemctl-list-units.h"
40 #include "systemctl-log-setting.h"
41 #include "systemctl-logind.h"
42 #include "systemctl-mount.h"
43 #include "systemctl-preset-all.h"
44 #include "systemctl-reset-failed.h"
45 #include "systemctl-service-watchdogs.h"
46 #include "systemctl-set-default.h"
47 #include "systemctl-set-environment.h"
48 #include "systemctl-set-property.h"
49 #include "systemctl-show.h"
50 #include "systemctl-start-special.h"
51 #include "systemctl-start-unit.h"
52 #include "systemctl-switch-root.h"
53 #include "systemctl-sysv-compat.h"
54 #include "systemctl-trivial-method.h"
55 #include "systemctl-util.h"
56 #include "systemctl.h"
57 #include "terminal-util.h"
58 #include "time-util.h"
59 #include "verbs.h"
60 #include "virt.h"
61
62 char **arg_types = NULL;
63 char **arg_states = NULL;
64 char **arg_properties = NULL;
65 bool arg_all = false;
66 enum dependency arg_dependency = DEPENDENCY_FORWARD;
67 const char *arg_job_mode = "replace";
68 UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
69 bool arg_wait = false;
70 bool arg_no_block = false;
71 bool arg_no_legend = false;
72 PagerFlags arg_pager_flags = 0;
73 bool arg_no_wtmp = false;
74 bool arg_no_sync = false;
75 bool arg_no_wall = false;
76 bool arg_no_reload = false;
77 bool arg_value = false;
78 bool arg_show_types = false;
79 int arg_check_inhibitors = -1;
80 bool arg_dry_run = false;
81 bool arg_quiet = false;
82 bool arg_full = false;
83 bool arg_recursive = false;
84 bool arg_with_dependencies = false;
85 bool arg_show_transaction = false;
86 int arg_force = 0;
87 bool arg_ask_password = false;
88 bool arg_runtime = false;
89 UnitFilePresetMode arg_preset_mode = UNIT_FILE_PRESET_FULL;
90 char **arg_wall = NULL;
91 const char *arg_kill_who = NULL;
92 int arg_signal = SIGTERM;
93 char *arg_root = NULL;
94 usec_t arg_when = 0;
95 const char *arg_reboot_argument = NULL;
96 enum action arg_action = ACTION_SYSTEMCTL;
97 BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
98 const char *arg_host = NULL;
99 unsigned arg_lines = 10;
100 OutputMode arg_output = OUTPUT_SHORT;
101 bool arg_plain = false;
102 bool arg_firmware_setup = false;
103 usec_t arg_boot_loader_menu = USEC_INFINITY;
104 const char *arg_boot_loader_entry = NULL;
105 bool arg_now = false;
106 bool arg_jobs_before = false;
107 bool arg_jobs_after = false;
108 char **arg_clean_what = NULL;
109 TimestampStyle arg_timestamp_style = TIMESTAMP_PRETTY;
110 bool arg_read_only = false;
111 bool arg_mkdir = false;
112 bool arg_marked = false;
113
114 STATIC_DESTRUCTOR_REGISTER(arg_wall, strv_freep);
115 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
116 STATIC_DESTRUCTOR_REGISTER(arg_types, strv_freep);
117 STATIC_DESTRUCTOR_REGISTER(arg_states, strv_freep);
118 STATIC_DESTRUCTOR_REGISTER(arg_properties, strv_freep);
119 STATIC_DESTRUCTOR_REGISTER(arg_clean_what, strv_freep);
120
121 static int systemctl_help(void) {
122 _cleanup_free_ char *link = NULL;
123 int r;
124
125 (void) pager_open(arg_pager_flags);
126
127 r = terminal_urlify_man("systemctl", "1", &link);
128 if (r < 0)
129 return log_oom();
130
131 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
132 "%5$sQuery or send control commands to the system manager.%6$s\n"
133 "\n%3$sUnit Commands:%4$s\n"
134 " list-units [PATTERN...] List units currently in memory\n"
135 " list-sockets [PATTERN...] List socket units currently in memory,\n"
136 " ordered by address\n"
137 " list-timers [PATTERN...] List timer units currently in memory,\n"
138 " ordered by next elapse\n"
139 " is-active PATTERN... Check whether units are active\n"
140 " is-failed PATTERN... Check whether units are failed\n"
141 " status [PATTERN...|PID...] Show runtime status of one or more units\n"
142 " show [PATTERN...|JOB...] Show properties of one or more\n"
143 " units/jobs or the manager\n"
144 " cat PATTERN... Show files and drop-ins of specified units\n"
145 " help PATTERN...|PID... Show manual for one or more units\n"
146 " list-dependencies [UNIT...] Recursively show units which are required\n"
147 " or wanted by the units or by which those\n"
148 " units are required or wanted\n"
149 " start UNIT... Start (activate) one or more units\n"
150 " stop UNIT... Stop (deactivate) one or more units\n"
151 " reload UNIT... Reload one or more units\n"
152 " restart UNIT... Start or restart one or more units\n"
153 " try-restart UNIT... Restart one or more units if active\n"
154 " reload-or-restart UNIT... Reload one or more units if possible,\n"
155 " otherwise start or restart\n"
156 " try-reload-or-restart UNIT... If active, reload one or more units,\n"
157 " if supported, otherwise restart\n"
158 " isolate UNIT Start one unit and stop all others\n"
159 " kill UNIT... Send signal to processes of a unit\n"
160 " clean UNIT... Clean runtime, cache, state, logs or\n"
161 " configuration of unit\n"
162 " freeze PATTERN... Freeze execution of unit processes\n"
163 " thaw PATTERN... Resume execution of a frozen unit\n"
164 " set-property UNIT PROPERTY=VALUE... Sets one or more properties of a unit\n"
165 " bind UNIT PATH [PATH] Bind-mount a path from the host into a\n"
166 " unit's namespace\n"
167 " mount-image UNIT PATH [PATH [OPTS]] Mount an image from the host into a\n"
168 " unit's namespace\n"
169 " service-log-level SERVICE [LEVEL] Get/set logging threshold for service\n"
170 " service-log-target SERVICE [TARGET] Get/set logging target for service\n"
171 " reset-failed [PATTERN...] Reset failed state for all, one, or more\n"
172 " units"
173 "\n%3$sUnit File Commands:%4$s\n"
174 " list-unit-files [PATTERN...] List installed unit files\n"
175 " enable [UNIT...|PATH...] Enable one or more unit files\n"
176 " disable UNIT... Disable one or more unit files\n"
177 " reenable UNIT... Reenable one or more unit files\n"
178 " preset UNIT... Enable/disable one or more unit files\n"
179 " based on preset configuration\n"
180 " preset-all Enable/disable all unit files based on\n"
181 " preset configuration\n"
182 " is-enabled UNIT... Check whether unit files are enabled\n"
183 " mask UNIT... Mask one or more units\n"
184 " unmask UNIT... Unmask one or more units\n"
185 " link PATH... Link one or more units files into\n"
186 " the search path\n"
187 " revert UNIT... Revert one or more unit files to vendor\n"
188 " version\n"
189 " add-wants TARGET UNIT... Add 'Wants' dependency for the target\n"
190 " on specified one or more units\n"
191 " add-requires TARGET UNIT... Add 'Requires' dependency for the target\n"
192 " on specified one or more units\n"
193 " edit UNIT... Edit one or more unit files\n"
194 " get-default Get the name of the default target\n"
195 " set-default TARGET Set the default target\n"
196 "\n%3$sMachine Commands:%4$s\n"
197 " list-machines [PATTERN...] List local containers and host\n"
198 "\n%3$sJob Commands:%4$s\n"
199 " list-jobs [PATTERN...] List jobs\n"
200 " cancel [JOB...] Cancel all, one, or more jobs\n"
201 "\n%3$sEnvironment Commands:%4$s\n"
202 " show-environment Dump environment\n"
203 " set-environment VARIABLE=VALUE... Set one or more environment variables\n"
204 " unset-environment VARIABLE... Unset one or more environment variables\n"
205 " import-environment VARIABLE... Import all or some environment variables\n"
206 "\n%3$sManager State Commands:%4$s\n"
207 " daemon-reload Reload systemd manager configuration\n"
208 " daemon-reexec Reexecute systemd manager\n"
209 " log-level [LEVEL] Get/set logging threshold for manager\n"
210 " log-target [TARGET] Get/set logging target for manager\n"
211 " service-watchdogs [BOOL] Get/set service watchdog state\n"
212 "\n%3$sSystem Commands:%4$s\n"
213 " is-system-running Check whether system is fully running\n"
214 " default Enter system default mode\n"
215 " rescue Enter system rescue mode\n"
216 " emergency Enter system emergency mode\n"
217 " halt Shut down and halt the system\n"
218 " poweroff Shut down and power-off the system\n"
219 " reboot Shut down and reboot the system\n"
220 " kexec Shut down and reboot the system with kexec\n"
221 " exit [EXIT_CODE] Request user instance or container exit\n"
222 " switch-root ROOT [INIT] Change to a different root file system\n"
223 " suspend Suspend the system\n"
224 " hibernate Hibernate the system\n"
225 " hybrid-sleep Hibernate and suspend the system\n"
226 " suspend-then-hibernate Suspend the system, wake after a period of\n"
227 " time, and hibernate"
228 "\n%3$sOptions:%4$s\n"
229 " -h --help Show this help\n"
230 " --version Show package version\n"
231 " --system Connect to system manager\n"
232 " --user Connect to user service manager\n"
233 " -H --host=[USER@]HOST Operate on remote host\n"
234 " -M --machine=CONTAINER Operate on a local container\n"
235 " -t --type=TYPE List units of a particular type\n"
236 " --state=STATE List units with particular LOAD or SUB or ACTIVE state\n"
237 " --failed Shortcut for --state=failed\n"
238 " -p --property=NAME Show only properties by this name\n"
239 " -P NAME Equivalent to --value --property=NAME\n"
240 " -a --all Show all properties/all units currently in memory,\n"
241 " including dead/empty ones. To list all units installed\n"
242 " on the system, use 'list-unit-files' instead.\n"
243 " -l --full Don't ellipsize unit names on output\n"
244 " -r --recursive Show unit list of host and local containers\n"
245 " --reverse Show reverse dependencies with 'list-dependencies'\n"
246 " --with-dependencies Show unit dependencies with 'status', 'cat',\n"
247 " 'list-units', and 'list-unit-files'.\n"
248 " --job-mode=MODE Specify how to deal with already queued jobs, when\n"
249 " queueing a new job\n"
250 " -T --show-transaction When enqueuing a unit job, show full transaction\n"
251 " --show-types When showing sockets, explicitly show their type\n"
252 " --value When showing properties, only print the value\n"
253 " --check-inhibitors=MODE\n"
254 " Specify if checking inhibitors before shutting down,\n"
255 " sleeping or hibernating\n"
256 " -i Shortcut for --check-inhibitors=no\n"
257 " --kill-who=WHO Whom to send signal to\n"
258 " -s --signal=SIGNAL Which signal to send\n"
259 " --what=RESOURCES Which types of resources to remove\n"
260 " --now Start or stop unit after enabling or disabling it\n"
261 " --dry-run Only print what would be done\n"
262 " Currently supported by verbs: halt, poweroff, reboot,\n"
263 " kexec, suspend, hibernate, suspend-then-hibernate,\n"
264 " hybrid-sleep, default, rescue, emergency, and exit.\n"
265 " -q --quiet Suppress output\n"
266 " --wait For (re)start, wait until service stopped again\n"
267 " For is-system-running, wait until startup is completed\n"
268 " --no-block Do not wait until operation finished\n"
269 " --no-wall Don't send wall message before halt/power-off/reboot\n"
270 " --no-reload Don't reload daemon after en-/dis-abling unit files\n"
271 " --no-legend Do not print a legend (column headers and hints)\n"
272 " --no-pager Do not pipe output into a pager\n"
273 " --no-ask-password Do not ask for system passwords\n"
274 " --global Enable/disable/mask unit files globally\n"
275 " --runtime Enable/disable/mask unit files temporarily until next\n"
276 " reboot\n"
277 " -f --force When enabling unit files, override existing symlinks\n"
278 " When shutting down, execute action immediately\n"
279 " --preset-mode= Apply only enable, only disable, or all presets\n"
280 " --root=PATH Enable/disable/mask unit files in the specified root\n"
281 " directory\n"
282 " -n --lines=INTEGER Number of journal entries to show\n"
283 " -o --output=STRING Change journal output mode (short, short-precise,\n"
284 " short-iso, short-iso-precise, short-full,\n"
285 " short-monotonic, short-unix,\n"
286 " verbose, export, json, json-pretty, json-sse, cat)\n"
287 " --firmware-setup Tell the firmware to show the setup menu on next boot\n"
288 " --boot-loader-menu=TIME\n"
289 " Boot into boot loader menu on next boot\n"
290 " --boot-loader-entry=NAME\n"
291 " Boot into a specific boot loader entry on next boot\n"
292 " --plain Print unit dependencies as a list instead of a tree\n"
293 " --timestamp=FORMAT Change format of printed timestamps.\n"
294 " 'pretty' (default): 'Day YYYY-MM-DD HH:MM:SS TZ\n"
295 " 'us': 'Day YYYY-MM-DD HH:MM:SS.UUUUUU TZ\n"
296 " 'utc': 'Day YYYY-MM-DD HH:MM:SS UTC\n"
297 " 'us+utc': 'Day YYYY-MM-DD HH:MM:SS.UUUUUU UTC\n"
298 " --read-only Create read-only bind mount\n"
299 " --mkdir Create directory before mounting, if missing\n"
300 " --marked Restart/reload previously marked units\n"
301 "\nSee the %2$s for details.\n",
302 program_invocation_short_name,
303 link,
304 ansi_underline(),
305 ansi_normal(),
306 ansi_highlight(),
307 ansi_normal());
308
309 return 0;
310 }
311
312 static void help_types(void) {
313 if (!arg_no_legend)
314 puts("Available unit types:");
315
316 DUMP_STRING_TABLE(unit_type, UnitType, _UNIT_TYPE_MAX);
317 }
318
319 static void help_states(void) {
320 if (!arg_no_legend)
321 puts("Available unit load states:");
322 DUMP_STRING_TABLE(unit_load_state, UnitLoadState, _UNIT_LOAD_STATE_MAX);
323
324 if (!arg_no_legend)
325 puts("\nAvailable unit active states:");
326 DUMP_STRING_TABLE(unit_active_state, UnitActiveState, _UNIT_ACTIVE_STATE_MAX);
327
328 if (!arg_no_legend)
329 puts("\nAvailable unit file states:");
330 DUMP_STRING_TABLE(unit_file_state, UnitFileState, _UNIT_FILE_STATE_MAX);
331
332 if (!arg_no_legend)
333 puts("\nAvailable automount unit substates:");
334 DUMP_STRING_TABLE(automount_state, AutomountState, _AUTOMOUNT_STATE_MAX);
335
336 if (!arg_no_legend)
337 puts("\nAvailable device unit substates:");
338 DUMP_STRING_TABLE(device_state, DeviceState, _DEVICE_STATE_MAX);
339
340 if (!arg_no_legend)
341 puts("\nAvailable mount unit substates:");
342 DUMP_STRING_TABLE(mount_state, MountState, _MOUNT_STATE_MAX);
343
344 if (!arg_no_legend)
345 puts("\nAvailable path unit substates:");
346 DUMP_STRING_TABLE(path_state, PathState, _PATH_STATE_MAX);
347
348 if (!arg_no_legend)
349 puts("\nAvailable scope unit substates:");
350 DUMP_STRING_TABLE(scope_state, ScopeState, _SCOPE_STATE_MAX);
351
352 if (!arg_no_legend)
353 puts("\nAvailable service unit substates:");
354 DUMP_STRING_TABLE(service_state, ServiceState, _SERVICE_STATE_MAX);
355
356 if (!arg_no_legend)
357 puts("\nAvailable slice unit substates:");
358 DUMP_STRING_TABLE(slice_state, SliceState, _SLICE_STATE_MAX);
359
360 if (!arg_no_legend)
361 puts("\nAvailable socket unit substates:");
362 DUMP_STRING_TABLE(socket_state, SocketState, _SOCKET_STATE_MAX);
363
364 if (!arg_no_legend)
365 puts("\nAvailable swap unit substates:");
366 DUMP_STRING_TABLE(swap_state, SwapState, _SWAP_STATE_MAX);
367
368 if (!arg_no_legend)
369 puts("\nAvailable target unit substates:");
370 DUMP_STRING_TABLE(target_state, TargetState, _TARGET_STATE_MAX);
371
372 if (!arg_no_legend)
373 puts("\nAvailable timer unit substates:");
374 DUMP_STRING_TABLE(timer_state, TimerState, _TIMER_STATE_MAX);
375 }
376
377 static int systemctl_parse_argv(int argc, char *argv[]) {
378 enum {
379 ARG_FAIL = 0x100,
380 ARG_REVERSE,
381 ARG_AFTER,
382 ARG_BEFORE,
383 ARG_CHECK_INHIBITORS,
384 ARG_DRY_RUN,
385 ARG_SHOW_TYPES,
386 ARG_IRREVERSIBLE,
387 ARG_IGNORE_DEPENDENCIES,
388 ARG_VALUE,
389 ARG_VERSION,
390 ARG_USER,
391 ARG_SYSTEM,
392 ARG_GLOBAL,
393 ARG_NO_BLOCK,
394 ARG_NO_LEGEND,
395 ARG_NO_PAGER,
396 ARG_NO_WALL,
397 ARG_ROOT,
398 ARG_NO_RELOAD,
399 ARG_KILL_WHO,
400 ARG_NO_ASK_PASSWORD,
401 ARG_FAILED,
402 ARG_RUNTIME,
403 ARG_PLAIN,
404 ARG_STATE,
405 ARG_JOB_MODE,
406 ARG_PRESET_MODE,
407 ARG_FIRMWARE_SETUP,
408 ARG_BOOT_LOADER_MENU,
409 ARG_BOOT_LOADER_ENTRY,
410 ARG_NOW,
411 ARG_MESSAGE,
412 ARG_WITH_DEPENDENCIES,
413 ARG_WAIT,
414 ARG_WHAT,
415 ARG_REBOOT_ARG,
416 ARG_TIMESTAMP_STYLE,
417 ARG_READ_ONLY,
418 ARG_MKDIR,
419 ARG_MARKED,
420 };
421
422 static const struct option options[] = {
423 { "help", no_argument, NULL, 'h' },
424 { "version", no_argument, NULL, ARG_VERSION },
425 { "type", required_argument, NULL, 't' },
426 { "property", required_argument, NULL, 'p' },
427 { "all", no_argument, NULL, 'a' },
428 { "reverse", no_argument, NULL, ARG_REVERSE },
429 { "after", no_argument, NULL, ARG_AFTER },
430 { "before", no_argument, NULL, ARG_BEFORE },
431 { "show-types", no_argument, NULL, ARG_SHOW_TYPES },
432 { "failed", no_argument, NULL, ARG_FAILED },
433 { "full", no_argument, NULL, 'l' },
434 { "job-mode", required_argument, NULL, ARG_JOB_MODE },
435 { "fail", no_argument, NULL, ARG_FAIL }, /* compatibility only */
436 { "irreversible", no_argument, NULL, ARG_IRREVERSIBLE }, /* compatibility only */
437 { "ignore-dependencies", no_argument, NULL, ARG_IGNORE_DEPENDENCIES }, /* compatibility only */
438 { "ignore-inhibitors", no_argument, NULL, 'i' }, /* compatibility only */
439 { "check-inhibitors", required_argument, NULL, ARG_CHECK_INHIBITORS },
440 { "value", no_argument, NULL, ARG_VALUE },
441 { "user", no_argument, NULL, ARG_USER },
442 { "system", no_argument, NULL, ARG_SYSTEM },
443 { "global", no_argument, NULL, ARG_GLOBAL },
444 { "wait", no_argument, NULL, ARG_WAIT },
445 { "no-block", no_argument, NULL, ARG_NO_BLOCK },
446 { "no-legend", no_argument, NULL, ARG_NO_LEGEND },
447 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
448 { "no-wall", no_argument, NULL, ARG_NO_WALL },
449 { "dry-run", no_argument, NULL, ARG_DRY_RUN },
450 { "quiet", no_argument, NULL, 'q' },
451 { "root", required_argument, NULL, ARG_ROOT },
452 { "force", no_argument, NULL, 'f' },
453 { "no-reload", no_argument, NULL, ARG_NO_RELOAD },
454 { "kill-who", required_argument, NULL, ARG_KILL_WHO },
455 { "signal", required_argument, NULL, 's' },
456 { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
457 { "host", required_argument, NULL, 'H' },
458 { "machine", required_argument, NULL, 'M' },
459 { "runtime", no_argument, NULL, ARG_RUNTIME },
460 { "lines", required_argument, NULL, 'n' },
461 { "output", required_argument, NULL, 'o' },
462 { "plain", no_argument, NULL, ARG_PLAIN },
463 { "state", required_argument, NULL, ARG_STATE },
464 { "recursive", no_argument, NULL, 'r' },
465 { "with-dependencies", no_argument, NULL, ARG_WITH_DEPENDENCIES },
466 { "preset-mode", required_argument, NULL, ARG_PRESET_MODE },
467 { "firmware-setup", no_argument, NULL, ARG_FIRMWARE_SETUP },
468 { "boot-loader-menu", required_argument, NULL, ARG_BOOT_LOADER_MENU },
469 { "boot-loader-entry", required_argument, NULL, ARG_BOOT_LOADER_ENTRY },
470 { "now", no_argument, NULL, ARG_NOW },
471 { "message", required_argument, NULL, ARG_MESSAGE },
472 { "show-transaction", no_argument, NULL, 'T' },
473 { "what", required_argument, NULL, ARG_WHAT },
474 { "reboot-argument", required_argument, NULL, ARG_REBOOT_ARG },
475 { "timestamp", required_argument, NULL, ARG_TIMESTAMP_STYLE },
476 { "read-only", no_argument, NULL, ARG_READ_ONLY },
477 { "mkdir", no_argument, NULL, ARG_MKDIR },
478 { "marked", no_argument, NULL, ARG_MARKED },
479 {}
480 };
481
482 int c, r;
483
484 assert(argc >= 0);
485 assert(argv);
486
487 /* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */
488 arg_ask_password = true;
489
490 while ((c = getopt_long(argc, argv, "ht:p:P:alqfs:H:M:n:o:iTr.::", options, NULL)) >= 0)
491
492 switch (c) {
493
494 case 'h':
495 return systemctl_help();
496
497 case ARG_VERSION:
498 return version();
499
500 case 't':
501 if (isempty(optarg))
502 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
503 "--type= requires arguments.");
504
505 for (const char *p = optarg;;) {
506 _cleanup_free_ char *type = NULL;
507
508 r = extract_first_word(&p, &type, ",", 0);
509 if (r < 0)
510 return log_error_errno(r, "Failed to parse type: %s", optarg);
511 if (r == 0)
512 break;
513
514 if (streq(type, "help")) {
515 help_types();
516 return 0;
517 }
518
519 if (unit_type_from_string(type) >= 0) {
520 if (strv_consume(&arg_types, TAKE_PTR(type)) < 0)
521 return log_oom();
522 continue;
523 }
524
525 /* It's much nicer to use --state= for load states, but let's support this in
526 * --types= too for compatibility with old versions */
527 if (unit_load_state_from_string(type) >= 0) {
528 if (strv_consume(&arg_states, TAKE_PTR(type)) < 0)
529 return log_oom();
530 continue;
531 }
532
533 log_error("Unknown unit type or load state '%s'.", type);
534 return log_info_errno(SYNTHETIC_ERRNO(EINVAL),
535 "Use -t help to see a list of allowed values.");
536 }
537
538 break;
539
540 case 'P':
541 arg_value = true;
542 _fallthrough_;
543
544 case 'p':
545 /* Make sure that if the empty property list was specified, we won't show any
546 properties. */
547 if (isempty(optarg) && !arg_properties) {
548 arg_properties = new0(char*, 1);
549 if (!arg_properties)
550 return log_oom();
551 } else
552 for (const char *p = optarg;;) {
553 _cleanup_free_ char *prop = NULL;
554
555 r = extract_first_word(&p, &prop, ",", 0);
556 if (r < 0)
557 return log_error_errno(r, "Failed to parse property: %s", optarg);
558 if (r == 0)
559 break;
560
561 if (strv_consume(&arg_properties, TAKE_PTR(prop)) < 0)
562 return log_oom();
563 }
564
565 /* If the user asked for a particular property, show it, even if it is empty. */
566 arg_all = true;
567
568 break;
569
570 case 'a':
571 arg_all = true;
572 break;
573
574 case ARG_REVERSE:
575 arg_dependency = DEPENDENCY_REVERSE;
576 break;
577
578 case ARG_AFTER:
579 arg_dependency = DEPENDENCY_AFTER;
580 arg_jobs_after = true;
581 break;
582
583 case ARG_BEFORE:
584 arg_dependency = DEPENDENCY_BEFORE;
585 arg_jobs_before = true;
586 break;
587
588 case ARG_SHOW_TYPES:
589 arg_show_types = true;
590 break;
591
592 case ARG_VALUE:
593 arg_value = true;
594 break;
595
596 case ARG_JOB_MODE:
597 arg_job_mode = optarg;
598 break;
599
600 case ARG_FAIL:
601 arg_job_mode = "fail";
602 break;
603
604 case ARG_IRREVERSIBLE:
605 arg_job_mode = "replace-irreversibly";
606 break;
607
608 case ARG_IGNORE_DEPENDENCIES:
609 arg_job_mode = "ignore-dependencies";
610 break;
611
612 case ARG_USER:
613 arg_scope = UNIT_FILE_USER;
614 break;
615
616 case ARG_SYSTEM:
617 arg_scope = UNIT_FILE_SYSTEM;
618 break;
619
620 case ARG_GLOBAL:
621 arg_scope = UNIT_FILE_GLOBAL;
622 break;
623
624 case ARG_WAIT:
625 arg_wait = true;
626 break;
627
628 case ARG_NO_BLOCK:
629 arg_no_block = true;
630 break;
631
632 case ARG_NO_LEGEND:
633 arg_no_legend = true;
634 break;
635
636 case ARG_NO_PAGER:
637 arg_pager_flags |= PAGER_DISABLE;
638 break;
639
640 case ARG_NO_WALL:
641 arg_no_wall = true;
642 break;
643
644 case ARG_ROOT:
645 r = parse_path_argument(optarg, false, &arg_root);
646 if (r < 0)
647 return r;
648 break;
649
650 case 'l':
651 arg_full = true;
652 break;
653
654 case ARG_FAILED:
655 if (strv_extend(&arg_states, "failed") < 0)
656 return log_oom();
657
658 break;
659
660 case ARG_DRY_RUN:
661 arg_dry_run = true;
662 break;
663
664 case 'q':
665 arg_quiet = true;
666 break;
667
668 case 'f':
669 arg_force++;
670 break;
671
672 case ARG_NO_RELOAD:
673 arg_no_reload = true;
674 break;
675
676 case ARG_KILL_WHO:
677 arg_kill_who = optarg;
678 break;
679
680 case 's':
681 r = parse_signal_argument(optarg, &arg_signal);
682 if (r <= 0)
683 return r;
684 break;
685
686 case ARG_NO_ASK_PASSWORD:
687 arg_ask_password = false;
688 break;
689
690 case 'H':
691 arg_transport = BUS_TRANSPORT_REMOTE;
692 arg_host = optarg;
693 break;
694
695 case 'M':
696 arg_transport = BUS_TRANSPORT_MACHINE;
697 arg_host = optarg;
698 break;
699
700 case ARG_RUNTIME:
701 arg_runtime = true;
702 break;
703
704 case 'n':
705 if (safe_atou(optarg, &arg_lines) < 0)
706 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
707 "Failed to parse lines '%s'",
708 optarg);
709 break;
710
711 case 'o':
712 if (streq(optarg, "help")) {
713 DUMP_STRING_TABLE(output_mode, OutputMode, _OUTPUT_MODE_MAX);
714 return 0;
715 }
716
717 arg_output = output_mode_from_string(optarg);
718 if (arg_output < 0)
719 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
720 "Unknown output '%s'.",
721 optarg);
722
723 if (OUTPUT_MODE_IS_JSON(arg_output)) {
724 arg_no_legend = true;
725 arg_plain = true;
726 }
727 break;
728
729 case 'i':
730 arg_check_inhibitors = 0;
731 break;
732
733 case ARG_CHECK_INHIBITORS:
734 if (streq(optarg, "auto"))
735 arg_check_inhibitors = -1;
736 else {
737 r = parse_boolean(optarg);
738 if (r < 0)
739 return log_error_errno(r, "Failed to parse --check-inhibitors= argument: %s", optarg);
740 arg_check_inhibitors = r;
741 }
742 break;
743
744 case ARG_PLAIN:
745 arg_plain = true;
746 break;
747
748 case ARG_FIRMWARE_SETUP:
749 arg_firmware_setup = true;
750 break;
751
752 case ARG_BOOT_LOADER_MENU:
753
754 r = parse_sec(optarg, &arg_boot_loader_menu);
755 if (r < 0)
756 return log_error_errno(r, "Failed to parse --boot-loader-menu= argument '%s': %m", optarg);
757
758 break;
759
760 case ARG_BOOT_LOADER_ENTRY:
761
762 if (streq(optarg, "help")) { /* Yes, this means, "help" is not a valid boot loader entry name we can deal with */
763 r = help_boot_loader_entry();
764 if (r < 0)
765 return r;
766
767 return 0;
768 }
769
770 arg_boot_loader_entry = empty_to_null(optarg);
771 break;
772
773 case ARG_STATE:
774 if (isempty(optarg))
775 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
776 "--state= requires arguments.");
777
778 for (const char *p = optarg;;) {
779 _cleanup_free_ char *s = NULL;
780
781 r = extract_first_word(&p, &s, ",", 0);
782 if (r < 0)
783 return log_error_errno(r, "Failed to parse state: %s", optarg);
784 if (r == 0)
785 break;
786
787 if (streq(s, "help")) {
788 help_states();
789 return 0;
790 }
791
792 if (strv_consume(&arg_states, TAKE_PTR(s)) < 0)
793 return log_oom();
794 }
795 break;
796
797 case 'r':
798 if (geteuid() != 0)
799 return log_error_errno(SYNTHETIC_ERRNO(EPERM),
800 "--recursive requires root privileges.");
801
802 arg_recursive = true;
803 break;
804
805 case ARG_PRESET_MODE:
806 if (streq(optarg, "help")) {
807 DUMP_STRING_TABLE(unit_file_preset_mode, UnitFilePresetMode, _UNIT_FILE_PRESET_MAX);
808 return 0;
809 }
810
811 arg_preset_mode = unit_file_preset_mode_from_string(optarg);
812 if (arg_preset_mode < 0)
813 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
814 "Failed to parse preset mode: %s.", optarg);
815
816 break;
817
818 case ARG_NOW:
819 arg_now = true;
820 break;
821
822 case ARG_MESSAGE:
823 if (strv_extend(&arg_wall, optarg) < 0)
824 return log_oom();
825 break;
826
827 case 'T':
828 arg_show_transaction = true;
829 break;
830
831 case ARG_WITH_DEPENDENCIES:
832 arg_with_dependencies = true;
833 break;
834
835 case ARG_WHAT:
836 if (isempty(optarg))
837 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--what= requires arguments.");
838
839 for (const char *p = optarg;;) {
840 _cleanup_free_ char *k = NULL;
841
842 r = extract_first_word(&p, &k, ",", 0);
843 if (r < 0)
844 return log_error_errno(r, "Failed to parse directory type: %s", optarg);
845 if (r == 0)
846 break;
847
848 if (streq(k, "help")) {
849 puts("runtime\n"
850 "state\n"
851 "cache\n"
852 "logs\n"
853 "configuration");
854 return 0;
855 }
856
857 r = strv_consume(&arg_clean_what, TAKE_PTR(k));
858 if (r < 0)
859 return log_oom();
860 }
861
862 break;
863
864 case ARG_REBOOT_ARG:
865 arg_reboot_argument = optarg;
866 break;
867
868 case ARG_TIMESTAMP_STYLE:
869 if (streq(optarg, "help")) {
870 DUMP_STRING_TABLE(timestamp_style, TimestampStyle, _TIMESTAMP_STYLE_MAX);
871 return 0;
872 }
873
874 arg_timestamp_style = timestamp_style_from_string(optarg);
875 if (arg_timestamp_style < 0)
876 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
877 "Invalid value: %s.", optarg);
878
879 break;
880
881 case ARG_READ_ONLY:
882 arg_read_only = true;
883 break;
884
885 case ARG_MKDIR:
886 arg_mkdir = true;
887 break;
888
889 case ARG_MARKED:
890 arg_marked = true;
891 break;
892
893 case '.':
894 /* Output an error mimicking getopt, and print a hint afterwards */
895 log_error("%s: invalid option -- '.'", program_invocation_name);
896 log_notice("Hint: to specify units starting with a dash, use \"--\":\n"
897 " %s [OPTIONS...] COMMAND -- -.%s ...",
898 program_invocation_name, optarg ?: "mount");
899 _fallthrough_;
900
901 case '?':
902 return -EINVAL;
903
904 default:
905 assert_not_reached("Unhandled option");
906 }
907
908 if (arg_transport == BUS_TRANSPORT_REMOTE && arg_scope != UNIT_FILE_SYSTEM)
909 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
910 "Cannot access user instance remotely.");
911
912 if (arg_wait && arg_no_block)
913 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
914 "--wait may not be combined with --no-block.");
915
916 bool do_reload_or_restart = streq_ptr(argv[optind], "reload-or-restart");
917 if (arg_marked) {
918 if (!do_reload_or_restart)
919 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
920 "--marked may only be used with 'reload-or-restart'.");
921 if (optind + 1 < argc)
922 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
923 "No additional arguments allowed with 'reload-or-restart --marked'.");
924 if (arg_wait)
925 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
926 "--marked --wait is not supported.");
927 if (arg_show_transaction)
928 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
929 "--marked --show-transaction is not supported.");
930
931 } else if (do_reload_or_restart) {
932 if (optind + 1 >= argc)
933 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
934 "List of units to restart/reload is required.");
935 }
936
937 return 1;
938 }
939
940 int systemctl_dispatch_parse_argv(int argc, char *argv[]) {
941 assert(argc >= 0);
942 assert(argv);
943
944 if (strstr_ptr(argv[0], "halt")) {
945 arg_action = ACTION_HALT;
946 return halt_parse_argv(argc, argv);
947
948 } else if (strstr_ptr(argv[0], "poweroff")) {
949 arg_action = ACTION_POWEROFF;
950 return halt_parse_argv(argc, argv);
951
952 } else if (strstr_ptr(argv[0], "reboot")) {
953 if (kexec_loaded())
954 arg_action = ACTION_KEXEC;
955 else
956 arg_action = ACTION_REBOOT;
957 return halt_parse_argv(argc, argv);
958
959 } else if (strstr_ptr(argv[0], "shutdown")) {
960 arg_action = ACTION_POWEROFF;
961 return shutdown_parse_argv(argc, argv);
962
963 } else if (strstr_ptr(argv[0], "init")) {
964
965 /* Matches invocations as "init" as well as "telinit", which are synonymous when run
966 * as PID != 1 on SysV.
967 *
968 * On SysV "telinit" was the official command to communicate with PID 1, but "init" would
969 * redirect itself to "telinit" if called with PID != 1. We follow the same logic here still,
970 * though we add one level of indirection, as we implement "telinit" in "systemctl". Hence,
971 * for us if you invoke "init" you get "systemd", but it will execve() "systemctl"
972 * immediately with argv[] unmodified if PID is != 1. If you invoke "telinit" you directly
973 * get "systemctl". In both cases we shall do the same thing, which is why we do
974 * strstr_ptr(argv[0], "init") here, as a quick way to match both.
975 *
976 * Also see redirect_telinit() in src/core/main.c. */
977
978 if (sd_booted() > 0) {
979 arg_action = _ACTION_INVALID;
980 return telinit_parse_argv(argc, argv);
981 } else {
982 /* Hmm, so some other init system is running, we need to forward this request to it.
983 */
984 arg_action = ACTION_TELINIT;
985 return 1;
986 }
987
988 } else if (strstr_ptr(argv[0], "runlevel")) {
989 arg_action = ACTION_RUNLEVEL;
990 return runlevel_parse_argv(argc, argv);
991 }
992
993 arg_action = ACTION_SYSTEMCTL;
994 return systemctl_parse_argv(argc, argv);
995 }
996
997 #ifndef FUZZ_SYSTEMCTL_PARSE_ARGV
998 static int systemctl_main(int argc, char *argv[]) {
999 static const Verb verbs[] = {
1000 { "list-units", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, list_units },
1001 { "list-unit-files", VERB_ANY, VERB_ANY, 0, list_unit_files },
1002 { "list-sockets", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_sockets },
1003 { "list-timers", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_timers },
1004 { "list-jobs", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_jobs },
1005 { "list-machines", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_machines },
1006 { "clear-jobs", VERB_ANY, 1, VERB_ONLINE_ONLY, trivial_method },
1007 { "cancel", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, cancel_job },
1008 { "start", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1009 { "stop", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1010 { "condstop", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with ALTLinux */
1011 { "reload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1012 { "restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1013 { "try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1014 { "reload-or-restart", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1015 { "reload-or-try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with old systemctl <= 228 */
1016 { "try-reload-or-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit },
1017 { "force-reload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with SysV */
1018 { "condreload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with ALTLinux */
1019 { "condrestart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with RH */
1020 { "isolate", 2, 2, VERB_ONLINE_ONLY, start_unit },
1021 { "kill", 2, VERB_ANY, VERB_ONLINE_ONLY, kill_unit },
1022 { "clean", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit },
1023 { "freeze", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit },
1024 { "thaw", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit },
1025 { "is-active", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_active },
1026 { "check", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_active }, /* deprecated alias of is-active */
1027 { "is-failed", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_failed },
1028 { "show", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show },
1029 { "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, cat },
1030 { "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show },
1031 { "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show },
1032 { "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload },
1033 { "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload },
1034 { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, log_setting },
1035 { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, log_setting },
1036 { "service-log-level", 2, 3, VERB_ONLINE_ONLY, service_log_setting },
1037 { "service-log-target", 2, 3, VERB_ONLINE_ONLY, service_log_setting },
1038 { "service-watchdogs", VERB_ANY, 2, VERB_ONLINE_ONLY, service_watchdogs },
1039 { "show-environment", VERB_ANY, 1, VERB_ONLINE_ONLY, show_environment },
1040 { "set-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment },
1041 { "unset-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment },
1042 { "import-environment", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, import_environment },
1043 { "halt", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1044 { "poweroff", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1045 { "reboot", VERB_ANY, 2, VERB_ONLINE_ONLY, start_system_special },
1046 { "kexec", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1047 { "suspend", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1048 { "hibernate", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1049 { "hybrid-sleep", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1050 { "suspend-then-hibernate",VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1051 { "default", VERB_ANY, 1, VERB_ONLINE_ONLY, start_special },
1052 { "rescue", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1053 { "emergency", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special },
1054 { "exit", VERB_ANY, 2, VERB_ONLINE_ONLY, start_special },
1055 { "reset-failed", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, reset_failed },
1056 { "enable", 2, VERB_ANY, 0, enable_unit },
1057 { "disable", 2, VERB_ANY, 0, enable_unit },
1058 { "is-enabled", 2, VERB_ANY, 0, unit_is_enabled },
1059 { "reenable", 2, VERB_ANY, 0, enable_unit },
1060 { "preset", 2, VERB_ANY, 0, enable_unit },
1061 { "preset-all", VERB_ANY, 1, 0, preset_all },
1062 { "mask", 2, VERB_ANY, 0, enable_unit },
1063 { "unmask", 2, VERB_ANY, 0, enable_unit },
1064 { "link", 2, VERB_ANY, 0, enable_unit },
1065 { "revert", 2, VERB_ANY, 0, enable_unit },
1066 { "switch-root", 2, VERB_ANY, VERB_ONLINE_ONLY, switch_root },
1067 { "list-dependencies", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_dependencies },
1068 { "set-default", 2, 2, 0, set_default },
1069 { "get-default", VERB_ANY, 1, 0, get_default },
1070 { "set-property", 3, VERB_ANY, VERB_ONLINE_ONLY, set_property },
1071 { "is-system-running", VERB_ANY, 1, 0, is_system_running },
1072 { "add-wants", 3, VERB_ANY, 0, add_dependency },
1073 { "add-requires", 3, VERB_ANY, 0, add_dependency },
1074 { "edit", 2, VERB_ANY, VERB_ONLINE_ONLY, edit },
1075 { "bind", 3, 4, VERB_ONLINE_ONLY, mount_bind },
1076 { "mount-image", 4, 5, VERB_ONLINE_ONLY, mount_image },
1077 {}
1078 };
1079
1080 const Verb *verb = verbs_find_verb(argv[optind], verbs);
1081 if (verb && (verb->flags & VERB_ONLINE_ONLY) && arg_root)
1082 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1083 "Verb '%s' cannot be used with --root=.",
1084 argv[optind] ?: verb->verb);
1085
1086 return dispatch_verb(argc, argv, verbs, NULL);
1087 }
1088
1089 static int run(int argc, char *argv[]) {
1090 int r;
1091
1092 setlocale(LC_ALL, "");
1093 log_parse_environment();
1094 log_open();
1095
1096 /* The journal merging logic potentially needs a lot of fds. */
1097 (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);
1098
1099 sigbus_install();
1100
1101 r = systemctl_dispatch_parse_argv(argc, argv);
1102 if (r <= 0)
1103 goto finish;
1104
1105 if (arg_action != ACTION_SYSTEMCTL && running_in_chroot() > 0) {
1106 if (!arg_quiet)
1107 log_info("Running in chroot, ignoring request.");
1108 r = 0;
1109 goto finish;
1110 }
1111
1112 /* systemctl_main() will print an error message for the bus connection, but only if it needs to */
1113
1114 switch (arg_action) {
1115
1116 case ACTION_SYSTEMCTL:
1117 r = systemctl_main(argc, argv);
1118 break;
1119
1120 /* Legacy command aliases set arg_action. They provide some fallbacks, e.g. to tell sysvinit to
1121 * reboot after you have installed systemd binaries. */
1122
1123 case ACTION_HALT:
1124 case ACTION_POWEROFF:
1125 case ACTION_REBOOT:
1126 case ACTION_KEXEC:
1127 r = halt_main();
1128 break;
1129
1130 case ACTION_RUNLEVEL2:
1131 case ACTION_RUNLEVEL3:
1132 case ACTION_RUNLEVEL4:
1133 case ACTION_RUNLEVEL5:
1134 case ACTION_RESCUE:
1135 r = start_with_fallback();
1136 break;
1137
1138 case ACTION_RELOAD:
1139 case ACTION_REEXEC:
1140 r = reload_with_fallback();
1141 break;
1142
1143 case ACTION_CANCEL_SHUTDOWN:
1144 r = logind_cancel_shutdown();
1145 break;
1146
1147 case ACTION_RUNLEVEL:
1148 r = runlevel_main();
1149 break;
1150
1151 case ACTION_TELINIT:
1152 r = exec_telinit(argv);
1153 break;
1154
1155 case ACTION_EXIT:
1156 case ACTION_SUSPEND:
1157 case ACTION_HIBERNATE:
1158 case ACTION_HYBRID_SLEEP:
1159 case ACTION_SUSPEND_THEN_HIBERNATE:
1160 case ACTION_EMERGENCY:
1161 case ACTION_DEFAULT:
1162 /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in
1163 * arg_action. Fall through. */
1164
1165 case _ACTION_INVALID:
1166 default:
1167 assert_not_reached("Unknown action");
1168 }
1169
1170 finish:
1171 release_busses();
1172
1173 /* Note that we return r here, not 0, so that we can implement the LSB-like return codes */
1174 return r;
1175 }
1176
1177 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);
1178 #endif