1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
11 #include "capsule-util.h"
12 #include "dissect-image.h"
14 #include "main-func.h"
15 #include "mount-util.h"
16 #include "output-mode.h"
18 #include "parse-argument.h"
19 #include "path-util.h"
20 #include "pretty-print.h"
21 #include "process-util.h"
22 #include "reboot-util.h"
23 #include "rlimit-util.h"
25 #include "signal-util.h"
26 #include "stat-util.h"
27 #include "string-table.h"
28 #include "systemctl-add-dependency.h"
29 #include "systemctl-cancel-job.h"
30 #include "systemctl-clean-or-freeze.h"
31 #include "systemctl-compat-halt.h"
32 #include "systemctl-compat-runlevel.h"
33 #include "systemctl-compat-shutdown.h"
34 #include "systemctl-compat-telinit.h"
35 #include "systemctl-daemon-reload.h"
36 #include "systemctl-edit.h"
37 #include "systemctl-enable.h"
38 #include "systemctl-is-active.h"
39 #include "systemctl-is-enabled.h"
40 #include "systemctl-is-system-running.h"
41 #include "systemctl-kill.h"
42 #include "systemctl-list-dependencies.h"
43 #include "systemctl-list-jobs.h"
44 #include "systemctl-list-machines.h"
45 #include "systemctl-list-unit-files.h"
46 #include "systemctl-list-units.h"
47 #include "systemctl-log-setting.h"
48 #include "systemctl-logind.h"
49 #include "systemctl-mount.h"
50 #include "systemctl-preset-all.h"
51 #include "systemctl-reset-failed.h"
52 #include "systemctl-service-watchdogs.h"
53 #include "systemctl-set-default.h"
54 #include "systemctl-set-environment.h"
55 #include "systemctl-set-property.h"
56 #include "systemctl-show.h"
57 #include "systemctl-start-special.h"
58 #include "systemctl-start-unit.h"
59 #include "systemctl-switch-root.h"
60 #include "systemctl-sysv-compat.h"
61 #include "systemctl-trivial-method.h"
62 #include "systemctl-util.h"
63 #include "systemctl-whoami.h"
64 #include "systemctl.h"
65 #include "terminal-util.h"
66 #include "time-util.h"
67 #include "user-util.h"
71 char **arg_types
= NULL
;
72 char **arg_states
= NULL
;
73 char **arg_properties
= NULL
;
75 enum dependency arg_dependency
= DEPENDENCY_FORWARD
;
76 const char *_arg_job_mode
= NULL
;
77 RuntimeScope arg_runtime_scope
= RUNTIME_SCOPE_SYSTEM
;
78 bool arg_wait
= false;
79 bool arg_no_block
= false;
80 int arg_legend
= -1; /* -1: true, unless --quiet is passed, 1: true */
81 PagerFlags arg_pager_flags
= 0;
82 bool arg_no_wtmp
= false;
83 bool arg_no_sync
= false;
84 bool arg_no_wall
= false;
85 bool arg_no_reload
= false;
86 BusPrintPropertyFlags arg_print_flags
= 0;
87 bool arg_show_types
= false;
88 int arg_check_inhibitors
= -1;
89 bool arg_dry_run
= false;
90 bool arg_quiet
= false;
91 bool arg_no_warn
= false;
92 bool arg_full
= false;
93 bool arg_recursive
= false;
94 bool arg_with_dependencies
= false;
95 bool arg_show_transaction
= false;
97 bool arg_ask_password
= false;
98 bool arg_runtime
= false;
99 UnitFilePresetMode arg_preset_mode
= UNIT_FILE_PRESET_FULL
;
100 char **arg_wall
= NULL
;
101 const char *arg_kill_whom
= NULL
;
102 int arg_signal
= SIGTERM
;
104 bool arg_kill_value_set
= false;
105 char *arg_root
= NULL
;
106 char *arg_image
= NULL
;
108 bool arg_stdin
= false;
109 const char *arg_reboot_argument
= NULL
;
110 enum action arg_action
= ACTION_SYSTEMCTL
;
111 BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
112 const char *arg_host
= NULL
;
113 unsigned arg_lines
= 10;
114 OutputMode arg_output
= OUTPUT_SHORT
;
115 bool arg_plain
= false;
116 bool arg_firmware_setup
= false;
117 usec_t arg_boot_loader_menu
= USEC_INFINITY
;
118 const char *arg_boot_loader_entry
= NULL
;
119 bool arg_now
= false;
120 bool arg_jobs_before
= false;
121 bool arg_jobs_after
= false;
122 char **arg_clean_what
= NULL
;
123 TimestampStyle arg_timestamp_style
= TIMESTAMP_PRETTY
;
124 bool arg_read_only
= false;
125 bool arg_mkdir
= false;
126 bool arg_marked
= false;
127 const char *arg_drop_in
= NULL
;
128 ImagePolicy
*arg_image_policy
= NULL
;
130 STATIC_DESTRUCTOR_REGISTER(arg_types
, strv_freep
);
131 STATIC_DESTRUCTOR_REGISTER(arg_states
, strv_freep
);
132 STATIC_DESTRUCTOR_REGISTER(arg_properties
, strv_freep
);
133 STATIC_DESTRUCTOR_REGISTER(_arg_job_mode
, unsetp
);
134 STATIC_DESTRUCTOR_REGISTER(arg_wall
, strv_freep
);
135 STATIC_DESTRUCTOR_REGISTER(arg_kill_whom
, unsetp
);
136 STATIC_DESTRUCTOR_REGISTER(arg_root
, freep
);
137 STATIC_DESTRUCTOR_REGISTER(arg_image
, freep
);
138 STATIC_DESTRUCTOR_REGISTER(arg_reboot_argument
, unsetp
);
139 STATIC_DESTRUCTOR_REGISTER(arg_host
, unsetp
);
140 STATIC_DESTRUCTOR_REGISTER(arg_boot_loader_entry
, unsetp
);
141 STATIC_DESTRUCTOR_REGISTER(arg_clean_what
, strv_freep
);
142 STATIC_DESTRUCTOR_REGISTER(arg_drop_in
, unsetp
);
143 STATIC_DESTRUCTOR_REGISTER(arg_image_policy
, image_policy_freep
);
145 static int systemctl_help(void) {
146 _cleanup_free_
char *link
= NULL
;
149 pager_open(arg_pager_flags
);
151 r
= terminal_urlify_man("systemctl", "1", &link
);
155 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
156 "%5$sQuery or send control commands to the system manager.%6$s\n"
157 "\n%3$sUnit Commands:%4$s\n"
158 " list-units [PATTERN...] List units currently in memory\n"
159 " list-automounts [PATTERN...] List automount units currently in memory,\n"
161 " list-paths [PATTERN...] List path units currently in memory,\n"
163 " list-sockets [PATTERN...] List socket units currently in memory,\n"
164 " ordered by address\n"
165 " list-timers [PATTERN...] List timer units currently in memory,\n"
166 " ordered by next elapse\n"
167 " is-active PATTERN... Check whether units are active\n"
168 " is-failed [PATTERN...] Check whether units are failed or\n"
169 " system is in degraded state\n"
170 " status [PATTERN...|PID...] Show runtime status of one or more units\n"
171 " show [PATTERN...|JOB...] Show properties of one or more\n"
172 " units/jobs or the manager\n"
173 " cat PATTERN... Show files and drop-ins of specified units\n"
174 " help PATTERN...|PID... Show manual for one or more units\n"
175 " list-dependencies [UNIT...] Recursively show units which are required\n"
176 " or wanted by the units or by which those\n"
177 " units are required or wanted\n"
178 " start UNIT... Start (activate) one or more units\n"
179 " stop UNIT... Stop (deactivate) one or more units\n"
180 " reload UNIT... Reload one or more units\n"
181 " restart UNIT... Start or restart one or more units\n"
182 " try-restart UNIT... Restart one or more units if active\n"
183 " reload-or-restart UNIT... Reload one or more units if possible,\n"
184 " otherwise start or restart\n"
185 " try-reload-or-restart UNIT... If active, reload one or more units,\n"
186 " if supported, otherwise restart\n"
187 " isolate UNIT Start one unit and stop all others\n"
188 " kill UNIT... Send signal to processes of a unit\n"
189 " clean UNIT... Clean runtime, cache, state, logs or\n"
190 " configuration of unit\n"
191 " freeze PATTERN... Freeze execution of unit processes\n"
192 " thaw PATTERN... Resume execution of a frozen unit\n"
193 " set-property UNIT PROPERTY=VALUE... Sets one or more properties of a unit\n"
194 " bind UNIT PATH [PATH] Bind-mount a path from the host into a\n"
195 " unit's namespace\n"
196 " mount-image UNIT PATH [PATH [OPTS]] Mount an image from the host into a\n"
197 " unit's namespace\n"
198 " service-log-level SERVICE [LEVEL] Get/set logging threshold for service\n"
199 " service-log-target SERVICE [TARGET] Get/set logging target for service\n"
200 " reset-failed [PATTERN...] Reset failed state for all, one, or more\n"
202 " whoami [PID...] Return unit caller or specified PIDs are\n"
204 "\n%3$sUnit File Commands:%4$s\n"
205 " list-unit-files [PATTERN...] List installed unit files\n"
206 " enable [UNIT...|PATH...] Enable one or more unit files\n"
207 " disable UNIT... Disable one or more unit files\n"
208 " reenable UNIT... Reenable one or more unit files\n"
209 " preset UNIT... Enable/disable one or more unit files\n"
210 " based on preset configuration\n"
211 " preset-all Enable/disable all unit files based on\n"
212 " preset configuration\n"
213 " is-enabled UNIT... Check whether unit files are enabled\n"
214 " mask UNIT... Mask one or more units\n"
215 " unmask UNIT... Unmask one or more units\n"
216 " link PATH... Link one or more units files into\n"
218 " revert UNIT... Revert one or more unit files to vendor\n"
220 " add-wants TARGET UNIT... Add 'Wants' dependency for the target\n"
221 " on specified one or more units\n"
222 " add-requires TARGET UNIT... Add 'Requires' dependency for the target\n"
223 " on specified one or more units\n"
224 " edit UNIT... Edit one or more unit files\n"
225 " get-default Get the name of the default target\n"
226 " set-default TARGET Set the default target\n"
227 "\n%3$sMachine Commands:%4$s\n"
228 " list-machines [PATTERN...] List local containers and host\n"
229 "\n%3$sJob Commands:%4$s\n"
230 " list-jobs [PATTERN...] List jobs\n"
231 " cancel [JOB...] Cancel all, one, or more jobs\n"
232 "\n%3$sEnvironment Commands:%4$s\n"
233 " show-environment Dump environment\n"
234 " set-environment VARIABLE=VALUE... Set one or more environment variables\n"
235 " unset-environment VARIABLE... Unset one or more environment variables\n"
236 " import-environment VARIABLE... Import all or some environment variables\n"
237 "\n%3$sManager State Commands:%4$s\n"
238 " daemon-reload Reload systemd manager configuration\n"
239 " daemon-reexec Reexecute systemd manager\n"
240 " log-level [LEVEL] Get/set logging threshold for manager\n"
241 " log-target [TARGET] Get/set logging target for manager\n"
242 " service-watchdogs [BOOL] Get/set service watchdog state\n"
243 "\n%3$sSystem Commands:%4$s\n"
244 " is-system-running Check whether system is fully running\n"
245 " default Enter system default mode\n"
246 " rescue Enter system rescue mode\n"
247 " emergency Enter system emergency mode\n"
248 " halt Shut down and halt the system\n"
249 " poweroff Shut down and power-off the system\n"
250 " reboot Shut down and reboot the system\n"
251 " kexec Shut down and reboot the system with kexec\n"
252 " soft-reboot Shut down and reboot userspace\n"
253 " exit [EXIT_CODE] Request user instance or container exit\n"
254 " switch-root [ROOT [INIT]] Change to a different root file system\n"
255 " sleep Put the system to sleep (through one of\n"
256 " the operations below)\n"
257 " suspend Suspend the system\n"
258 " hibernate Hibernate the system\n"
259 " hybrid-sleep Hibernate and suspend the system\n"
260 " suspend-then-hibernate Suspend the system, wake after a period of\n"
261 " time, and hibernate"
262 "\n%3$sOptions:%4$s\n"
263 " -h --help Show this help\n"
264 " --version Show package version\n"
265 " --system Connect to system manager\n"
266 " --user Connect to user service manager\n"
267 " -C --capsule=NAME Connect to service manager of specified capsule\n"
268 " -H --host=[USER@]HOST Operate on remote host\n"
269 " -M --machine=CONTAINER Operate on a local container\n"
270 " -t --type=TYPE List units of a particular type\n"
271 " --state=STATE List units with particular LOAD or SUB or ACTIVE state\n"
272 " --failed Shortcut for --state=failed\n"
273 " -p --property=NAME Show only properties by this name\n"
274 " -P NAME Equivalent to --value --property=NAME\n"
275 " -a --all Show all properties/all units currently in memory,\n"
276 " including dead/empty ones. To list all units installed\n"
277 " on the system, use 'list-unit-files' instead.\n"
278 " -l --full Don't ellipsize unit names on output\n"
279 " -r --recursive Show unit list of host and local containers\n"
280 " --reverse Show reverse dependencies with 'list-dependencies'\n"
281 " --before Show units ordered before with 'list-dependencies'\n"
282 " --after Show units ordered after with 'list-dependencies'\n"
283 " --with-dependencies Show unit dependencies with 'status', 'cat',\n"
284 " 'list-units', and 'list-unit-files'.\n"
285 " --job-mode=MODE Specify how to deal with already queued jobs, when\n"
286 " queueing a new job\n"
287 " -T --show-transaction When enqueuing a unit job, show full transaction\n"
288 " --show-types When showing sockets, explicitly show their type\n"
289 " --value When showing properties, only print the value\n"
290 " --check-inhibitors=MODE\n"
291 " Whether to check inhibitors before shutting down,\n"
292 " sleeping, or hibernating\n"
293 " -i Shortcut for --check-inhibitors=no\n"
294 " --kill-whom=WHOM Whom to send signal to\n"
295 " --kill-value=INT Signal value to enqueue\n"
296 " -s --signal=SIGNAL Which signal to send\n"
297 " --what=RESOURCES Which types of resources to remove\n"
298 " --now Start or stop unit after enabling or disabling it\n"
299 " --dry-run Only print what would be done\n"
300 " Currently supported by verbs: halt, poweroff, reboot,\n"
301 " kexec, soft-reboot, suspend, hibernate, \n"
302 " suspend-then-hibernate, hybrid-sleep, default,\n"
303 " rescue, emergency, and exit.\n"
304 " -q --quiet Suppress output\n"
305 " --no-warn Suppress several warnings shown by default\n"
306 " --wait For (re)start, wait until service stopped again\n"
307 " For is-system-running, wait until startup is completed\n"
308 " --no-block Do not wait until operation finished\n"
309 " --no-wall Don't send wall message before halt/power-off/reboot\n"
310 " --message=MESSAGE Specify human readable reason for system shutdown\n"
311 " --no-reload Don't reload daemon after en-/dis-abling unit files\n"
312 " --legend=BOOL Enable/disable the legend (column headers and hints)\n"
313 " --no-pager Do not pipe output into a pager\n"
314 " --no-ask-password Do not ask for system passwords\n"
315 " --global Edit/enable/disable/mask default user unit files\n"
317 " --runtime Edit/enable/disable/mask unit files temporarily until\n"
319 " -f --force When enabling unit files, override existing symlinks\n"
320 " When shutting down, execute action immediately\n"
321 " --preset-mode= Apply only enable, only disable, or all presets\n"
322 " --root=PATH Edit/enable/disable/mask unit files in the specified\n"
324 " --image=PATH Edit/enable/disable/mask unit files in the specified\n"
326 " --image-policy=POLICY\n"
327 " Specify disk image dissection policy\n"
328 " -n --lines=INTEGER Number of journal entries to show\n"
329 " -o --output=STRING Change journal output mode (short, short-precise,\n"
330 " short-iso, short-iso-precise, short-full,\n"
331 " short-monotonic, short-unix, short-delta,\n"
332 " verbose, export, json, json-pretty, json-sse, cat)\n"
333 " --firmware-setup Tell the firmware to show the setup menu on next boot\n"
334 " --boot-loader-menu=TIME\n"
335 " Boot into boot loader menu on next boot\n"
336 " --boot-loader-entry=NAME\n"
337 " Boot into a specific boot loader entry on next boot\n"
338 " --reboot-argument=ARG\n"
339 " Specify argument string to pass to reboot()\n"
340 " --plain Print unit dependencies as a list instead of a tree\n"
341 " --timestamp=FORMAT Change format of printed timestamps (pretty, unix,\n"
342 " us, utc, us+utc)\n"
343 " --read-only Create read-only bind mount\n"
344 " --mkdir Create directory before mounting, if missing\n"
345 " --marked Restart/reload previously marked units\n"
346 " --drop-in=NAME Edit unit files using the specified drop-in file name\n"
347 " --when=TIME Schedule halt/power-off/reboot/kexec action after\n"
348 " a certain timestamp\n"
349 " --stdin Read contents of edited file from stdin\n"
350 "\nSee the %2$s for details.\n",
351 program_invocation_short_name
,
361 static void help_types(void) {
363 puts("Available unit types:");
365 DUMP_STRING_TABLE(unit_type
, UnitType
, _UNIT_TYPE_MAX
);
368 static void help_states(void) {
370 puts("Available unit load states:");
371 DUMP_STRING_TABLE(unit_load_state
, UnitLoadState
, _UNIT_LOAD_STATE_MAX
);
374 puts("\nAvailable unit active states:");
375 DUMP_STRING_TABLE(unit_active_state
, UnitActiveState
, _UNIT_ACTIVE_STATE_MAX
);
378 puts("\nAvailable unit file states:");
379 DUMP_STRING_TABLE(unit_file_state
, UnitFileState
, _UNIT_FILE_STATE_MAX
);
382 puts("\nAvailable automount unit substates:");
383 DUMP_STRING_TABLE(automount_state
, AutomountState
, _AUTOMOUNT_STATE_MAX
);
386 puts("\nAvailable device unit substates:");
387 DUMP_STRING_TABLE(device_state
, DeviceState
, _DEVICE_STATE_MAX
);
390 puts("\nAvailable mount unit substates:");
391 DUMP_STRING_TABLE(mount_state
, MountState
, _MOUNT_STATE_MAX
);
394 puts("\nAvailable path unit substates:");
395 DUMP_STRING_TABLE(path_state
, PathState
, _PATH_STATE_MAX
);
398 puts("\nAvailable scope unit substates:");
399 DUMP_STRING_TABLE(scope_state
, ScopeState
, _SCOPE_STATE_MAX
);
402 puts("\nAvailable service unit substates:");
403 DUMP_STRING_TABLE(service_state
, ServiceState
, _SERVICE_STATE_MAX
);
406 puts("\nAvailable slice unit substates:");
407 DUMP_STRING_TABLE(slice_state
, SliceState
, _SLICE_STATE_MAX
);
410 puts("\nAvailable socket unit substates:");
411 DUMP_STRING_TABLE(socket_state
, SocketState
, _SOCKET_STATE_MAX
);
414 puts("\nAvailable swap unit substates:");
415 DUMP_STRING_TABLE(swap_state
, SwapState
, _SWAP_STATE_MAX
);
418 puts("\nAvailable target unit substates:");
419 DUMP_STRING_TABLE(target_state
, TargetState
, _TARGET_STATE_MAX
);
422 puts("\nAvailable timer unit substates:");
423 DUMP_STRING_TABLE(timer_state
, TimerState
, _TIMER_STATE_MAX
);
426 static int systemctl_parse_argv(int argc
, char *argv
[]) {
428 ARG_FAIL
= 0x100, /* compatibility only */
432 ARG_CHECK_INHIBITORS
,
435 ARG_IRREVERSIBLE
, /* compatibility only */
436 ARG_IGNORE_DEPENDENCIES
, /* compatibility only */
444 ARG_NO_LEGEND
, /* compatibility only */
461 ARG_BOOT_LOADER_MENU
,
462 ARG_BOOT_LOADER_ENTRY
,
465 ARG_WITH_DEPENDENCIES
,
479 static const struct option options
[] = {
480 { "help", no_argument
, NULL
, 'h' },
481 { "version", no_argument
, NULL
, ARG_VERSION
},
482 { "type", required_argument
, NULL
, 't' },
483 { "property", required_argument
, NULL
, 'p' },
484 { "all", no_argument
, NULL
, 'a' },
485 { "reverse", no_argument
, NULL
, ARG_REVERSE
},
486 { "after", no_argument
, NULL
, ARG_AFTER
},
487 { "before", no_argument
, NULL
, ARG_BEFORE
},
488 { "show-types", no_argument
, NULL
, ARG_SHOW_TYPES
},
489 { "failed", no_argument
, NULL
, ARG_FAILED
},
490 { "full", no_argument
, NULL
, 'l' },
491 { "job-mode", required_argument
, NULL
, ARG_JOB_MODE
},
492 { "fail", no_argument
, NULL
, ARG_FAIL
}, /* compatibility only */
493 { "irreversible", no_argument
, NULL
, ARG_IRREVERSIBLE
}, /* compatibility only */
494 { "ignore-dependencies", no_argument
, NULL
, ARG_IGNORE_DEPENDENCIES
}, /* compatibility only */
495 { "ignore-inhibitors", no_argument
, NULL
, 'i' }, /* compatibility only */
496 { "check-inhibitors", required_argument
, NULL
, ARG_CHECK_INHIBITORS
},
497 { "value", no_argument
, NULL
, ARG_VALUE
},
498 { "user", no_argument
, NULL
, ARG_USER
},
499 { "system", no_argument
, NULL
, ARG_SYSTEM
},
500 { "global", no_argument
, NULL
, ARG_GLOBAL
},
501 { "capsule", required_argument
, NULL
, 'C' },
502 { "wait", no_argument
, NULL
, ARG_WAIT
},
503 { "no-block", no_argument
, NULL
, ARG_NO_BLOCK
},
504 { "legend", required_argument
, NULL
, ARG_LEGEND
},
505 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
}, /* compatibility only */
506 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
507 { "no-wall", no_argument
, NULL
, ARG_NO_WALL
},
508 { "dry-run", no_argument
, NULL
, ARG_DRY_RUN
},
509 { "quiet", no_argument
, NULL
, 'q' },
510 { "no-warn", no_argument
, NULL
, ARG_NO_WARN
},
511 { "root", required_argument
, NULL
, ARG_ROOT
},
512 { "image", required_argument
, NULL
, ARG_IMAGE
},
513 { "image-policy", required_argument
, NULL
, ARG_IMAGE_POLICY
},
514 { "force", no_argument
, NULL
, 'f' },
515 { "no-reload", no_argument
, NULL
, ARG_NO_RELOAD
},
516 { "kill-whom", required_argument
, NULL
, ARG_KILL_WHOM
},
517 { "kill-value", required_argument
, NULL
, ARG_KILL_VALUE
},
518 { "signal", required_argument
, NULL
, 's' },
519 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
520 { "host", required_argument
, NULL
, 'H' },
521 { "machine", required_argument
, NULL
, 'M' },
522 { "runtime", no_argument
, NULL
, ARG_RUNTIME
},
523 { "lines", required_argument
, NULL
, 'n' },
524 { "output", required_argument
, NULL
, 'o' },
525 { "plain", no_argument
, NULL
, ARG_PLAIN
},
526 { "state", required_argument
, NULL
, ARG_STATE
},
527 { "recursive", no_argument
, NULL
, 'r' },
528 { "with-dependencies", no_argument
, NULL
, ARG_WITH_DEPENDENCIES
},
529 { "preset-mode", required_argument
, NULL
, ARG_PRESET_MODE
},
530 { "firmware-setup", no_argument
, NULL
, ARG_FIRMWARE_SETUP
},
531 { "boot-loader-menu", required_argument
, NULL
, ARG_BOOT_LOADER_MENU
},
532 { "boot-loader-entry", required_argument
, NULL
, ARG_BOOT_LOADER_ENTRY
},
533 { "now", no_argument
, NULL
, ARG_NOW
},
534 { "message", required_argument
, NULL
, ARG_MESSAGE
},
535 { "show-transaction", no_argument
, NULL
, 'T' },
536 { "what", required_argument
, NULL
, ARG_WHAT
},
537 { "reboot-argument", required_argument
, NULL
, ARG_REBOOT_ARG
},
538 { "timestamp", required_argument
, NULL
, ARG_TIMESTAMP_STYLE
},
539 { "read-only", no_argument
, NULL
, ARG_READ_ONLY
},
540 { "mkdir", no_argument
, NULL
, ARG_MKDIR
},
541 { "marked", no_argument
, NULL
, ARG_MARKED
},
542 { "drop-in", required_argument
, NULL
, ARG_DROP_IN
},
543 { "when", required_argument
, NULL
, ARG_WHEN
},
544 { "stdin", no_argument
, NULL
, ARG_STDIN
},
553 /* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */
554 arg_ask_password
= true;
556 while ((c
= getopt_long(argc
, argv
, "hC:t:p:P:alqfs:H:M:n:o:iTr.::", options
, NULL
)) >= 0)
561 return systemctl_help();
568 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
569 "--type= requires arguments.");
571 for (const char *p
= optarg
;;) {
572 _cleanup_free_
char *type
= NULL
;
574 r
= extract_first_word(&p
, &type
, ",", 0);
576 return log_error_errno(r
, "Failed to parse type: %s", optarg
);
580 if (streq(type
, "help")) {
585 if (unit_type_from_string(type
) >= 0) {
586 if (strv_consume(&arg_types
, TAKE_PTR(type
)) < 0)
591 /* It's much nicer to use --state= for load states, but let's support this in
592 * --types= too for compatibility with old versions */
593 if (unit_load_state_from_string(type
) >= 0) {
594 if (strv_consume(&arg_states
, TAKE_PTR(type
)) < 0)
599 log_error("Unknown unit type or load state '%s'.", type
);
600 return log_info_errno(SYNTHETIC_ERRNO(EINVAL
),
601 "Use -t help to see a list of allowed values.");
607 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
611 /* Make sure that if the empty property list was specified, we won't show any
613 if (isempty(optarg
) && !arg_properties
) {
614 arg_properties
= new0(char*, 1);
618 for (const char *p
= optarg
;;) {
619 _cleanup_free_
char *prop
= NULL
;
621 r
= extract_first_word(&p
, &prop
, ",", 0);
623 return log_error_errno(r
, "Failed to parse property: %s", optarg
);
627 if (strv_consume(&arg_properties
, TAKE_PTR(prop
)) < 0)
631 /* If the user asked for a particular property, show it, even if it is empty. */
632 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
637 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
642 arg_dependency
= DEPENDENCY_REVERSE
;
646 arg_dependency
= DEPENDENCY_AFTER
;
647 arg_jobs_after
= true;
651 arg_dependency
= DEPENDENCY_BEFORE
;
652 arg_jobs_before
= true;
656 arg_show_types
= true;
660 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
664 _arg_job_mode
= optarg
;
668 _arg_job_mode
= "fail";
671 case ARG_IRREVERSIBLE
:
672 _arg_job_mode
= "replace-irreversibly";
675 case ARG_IGNORE_DEPENDENCIES
:
676 _arg_job_mode
= "ignore-dependencies";
680 arg_runtime_scope
= RUNTIME_SCOPE_USER
;
684 arg_runtime_scope
= RUNTIME_SCOPE_SYSTEM
;
688 arg_runtime_scope
= RUNTIME_SCOPE_GLOBAL
;
692 r
= capsule_name_is_valid(optarg
);
694 return log_error_errno(r
, "Unable to validate capsule name '%s': %m", optarg
);
696 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid capsule name: %s", optarg
);
699 arg_transport
= BUS_TRANSPORT_CAPSULE
;
700 arg_runtime_scope
= RUNTIME_SCOPE_USER
;
716 r
= parse_boolean_argument("--legend", optarg
, NULL
);
723 arg_pager_flags
|= PAGER_DISABLE
;
731 r
= parse_path_argument(optarg
, false, &arg_root
);
737 r
= parse_path_argument(optarg
, false, &arg_image
);
742 case ARG_IMAGE_POLICY
:
743 r
= parse_image_policy_argument(optarg
, &arg_image_policy
);
753 if (strv_extend(&arg_states
, "failed") < 0)
775 arg_no_reload
= true;
779 arg_kill_whom
= optarg
;
782 case ARG_KILL_VALUE
: {
785 if (isempty(optarg
)) {
786 arg_kill_value_set
= false;
790 /* First, try to parse unsigned, so that we can support the prefixes 0x, 0o, 0b */
791 r
= safe_atou_full(optarg
, 0, &u
);
793 /* If this didn't work, try as signed integer, without those prefixes */
794 r
= safe_atoi(optarg
, &arg_kill_value
);
795 else if (u
> INT_MAX
)
798 arg_kill_value
= (int) u
;
800 return log_error_errno(r
, "Unable to parse signal queue value: %s", optarg
);
802 arg_kill_value_set
= true;
807 r
= parse_signal_argument(optarg
, &arg_signal
);
812 case ARG_NO_ASK_PASSWORD
:
813 arg_ask_password
= false;
817 arg_transport
= BUS_TRANSPORT_REMOTE
;
822 arg_transport
= BUS_TRANSPORT_MACHINE
;
831 if (safe_atou(optarg
, &arg_lines
) < 0)
832 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
833 "Failed to parse lines '%s'",
838 if (streq(optarg
, "help")) {
839 DUMP_STRING_TABLE(output_mode
, OutputMode
, _OUTPUT_MODE_MAX
);
843 arg_output
= output_mode_from_string(optarg
);
845 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
846 "Unknown output '%s'.",
849 if (OUTPUT_MODE_IS_JSON(arg_output
)) {
856 arg_check_inhibitors
= 0;
859 case ARG_CHECK_INHIBITORS
:
860 r
= parse_tristate_full(optarg
, "auto", &arg_check_inhibitors
);
862 return log_error_errno(r
, "Failed to parse --check-inhibitors= argument: %s", optarg
);
869 case ARG_FIRMWARE_SETUP
:
870 arg_firmware_setup
= true;
873 case ARG_BOOT_LOADER_MENU
:
875 r
= parse_sec(optarg
, &arg_boot_loader_menu
);
877 return log_error_errno(r
, "Failed to parse --boot-loader-menu= argument '%s': %m", optarg
);
881 case ARG_BOOT_LOADER_ENTRY
:
883 if (streq(optarg
, "help")) { /* Yes, this means, "help" is not a valid boot loader entry name we can deal with */
884 r
= help_boot_loader_entry();
891 arg_boot_loader_entry
= empty_to_null(optarg
);
896 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
897 "--state= requires arguments.");
899 for (const char *p
= optarg
;;) {
900 _cleanup_free_
char *s
= NULL
;
902 r
= extract_first_word(&p
, &s
, ",", 0);
904 return log_error_errno(r
, "Failed to parse state: %s", optarg
);
908 if (streq(s
, "help")) {
913 if (strv_consume(&arg_states
, TAKE_PTR(s
)) < 0)
920 return log_error_errno(SYNTHETIC_ERRNO(EPERM
),
921 "--recursive requires root privileges.");
923 arg_recursive
= true;
926 case ARG_PRESET_MODE
:
927 if (streq(optarg
, "help")) {
928 DUMP_STRING_TABLE(unit_file_preset_mode
, UnitFilePresetMode
, _UNIT_FILE_PRESET_MODE_MAX
);
932 arg_preset_mode
= unit_file_preset_mode_from_string(optarg
);
933 if (arg_preset_mode
< 0)
934 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
935 "Failed to parse preset mode: %s.", optarg
);
944 if (strv_extend(&arg_wall
, optarg
) < 0)
949 arg_show_transaction
= true;
952 case ARG_WITH_DEPENDENCIES
:
953 arg_with_dependencies
= true;
958 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "--what= requires arguments.");
960 for (const char *p
= optarg
;;) {
961 _cleanup_free_
char *k
= NULL
;
963 r
= extract_first_word(&p
, &k
, ",", 0);
965 return log_error_errno(r
, "Failed to parse directory type: %s", optarg
);
969 if (streq(k
, "help")) {
979 r
= strv_consume(&arg_clean_what
, TAKE_PTR(k
));
987 arg_reboot_argument
= optarg
;
990 case ARG_TIMESTAMP_STYLE
:
991 if (streq(optarg
, "help")) {
992 DUMP_STRING_TABLE(timestamp_style
, TimestampStyle
, _TIMESTAMP_STYLE_MAX
);
996 arg_timestamp_style
= timestamp_style_from_string(optarg
);
997 if (arg_timestamp_style
< 0)
998 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
999 "Invalid value: %s.", optarg
);
1004 arg_read_only
= true;
1020 arg_drop_in
= optarg
;
1024 if (streq(optarg
, "show")) {
1025 r
= logind_show_shutdown();
1026 if (r
< 0 && r
!= -ENODATA
)
1032 if (STR_IN_SET(optarg
, "", "cancel")) {
1033 arg_when
= USEC_INFINITY
;
1037 r
= parse_timestamp(optarg
, &arg_when
);
1039 return log_error_errno(r
, "Failed to parse --when= argument '%s': %m", optarg
);
1041 if (!timestamp_is_set(arg_when
))
1042 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1043 "Invalid timestamp '%s' specified for --when=.", optarg
);
1052 /* Output an error mimicking getopt, and print a hint afterwards */
1053 log_error("%s: invalid option -- '.'", program_invocation_name
);
1054 log_notice("Hint: to specify units starting with a dash, use \"--\":\n"
1055 " %s [OPTIONS...] COMMAND -- -.%s ...",
1056 program_invocation_name
, optarg
?: "mount");
1063 assert_not_reached();
1066 /* If we are in --user mode, there's no point in talking to PolicyKit or the infra to query system
1068 if (arg_runtime_scope
!= RUNTIME_SCOPE_SYSTEM
)
1069 arg_ask_password
= false;
1071 if (arg_transport
== BUS_TRANSPORT_REMOTE
&& arg_runtime_scope
!= RUNTIME_SCOPE_SYSTEM
)
1072 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1073 "Cannot access user instance remotely.");
1075 if (arg_wait
&& arg_no_block
)
1076 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1077 "--wait may not be combined with --no-block.");
1079 bool do_reload_or_restart
= streq_ptr(argv
[optind
], "reload-or-restart");
1081 if (!do_reload_or_restart
)
1082 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1083 "--marked may only be used with 'reload-or-restart'.");
1084 if (optind
+ 1 < argc
)
1085 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1086 "No additional arguments allowed with 'reload-or-restart --marked'.");
1088 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1089 "--marked --wait is not supported.");
1090 if (arg_show_transaction
)
1091 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1092 "--marked --show-transaction is not supported.");
1094 } else if (do_reload_or_restart
) {
1095 if (optind
+ 1 >= argc
)
1096 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1097 "List of units to restart/reload is required.");
1100 if (arg_image
&& arg_root
)
1101 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1102 "Please specify either --root= or --image=, the combination of both is not supported.");
1107 int systemctl_dispatch_parse_argv(int argc
, char *argv
[]) {
1111 if (invoked_as(argv
, "halt")) {
1112 arg_action
= ACTION_HALT
;
1113 return halt_parse_argv(argc
, argv
);
1115 } else if (invoked_as(argv
, "poweroff")) {
1116 arg_action
= ACTION_POWEROFF
;
1117 return halt_parse_argv(argc
, argv
);
1119 } else if (invoked_as(argv
, "reboot")) {
1120 arg_action
= ACTION_REBOOT
;
1121 return halt_parse_argv(argc
, argv
);
1123 } else if (invoked_as(argv
, "shutdown")) {
1124 arg_action
= ACTION_POWEROFF
;
1125 return shutdown_parse_argv(argc
, argv
);
1127 } else if (invoked_as(argv
, "init")) {
1129 /* Matches invocations as "init" as well as "telinit", which are synonymous when run
1130 * as PID != 1 on SysV.
1132 * On SysV "telinit" was the official command to communicate with PID 1, but "init" would
1133 * redirect itself to "telinit" if called with PID != 1. We follow the same logic here still,
1134 * though we add one level of indirection, as we implement "telinit" in "systemctl". Hence,
1135 * for us if you invoke "init" you get "systemd", but it will execve() "systemctl"
1136 * immediately with argv[] unmodified if PID is != 1. If you invoke "telinit" you directly
1137 * get "systemctl". In both cases we shall do the same thing, which is why we do
1138 * invoked_as(argv, "init") here, as a quick way to match both.
1140 * Also see redirect_telinit() in src/core/main.c. */
1142 arg_action
= _ACTION_INVALID
; /* telinit_parse_argv() will figure out the actual action we'll execute */
1143 return telinit_parse_argv(argc
, argv
);
1145 } else if (invoked_as(argv
, "runlevel")) {
1146 arg_action
= ACTION_RUNLEVEL
;
1147 return runlevel_parse_argv(argc
, argv
);
1150 arg_action
= ACTION_SYSTEMCTL
;
1151 return systemctl_parse_argv(argc
, argv
);
1154 #ifndef FUZZ_SYSTEMCTL_PARSE_ARGV
1155 static int systemctl_main(int argc
, char *argv
[]) {
1156 static const Verb verbs
[] = {
1157 { "list-units", VERB_ANY
, VERB_ANY
, VERB_DEFAULT
|VERB_ONLINE_ONLY
, verb_list_units
},
1158 { "list-unit-files", VERB_ANY
, VERB_ANY
, 0, verb_list_unit_files
},
1159 { "list-automounts", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_automounts
},
1160 { "list-paths", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_paths
},
1161 { "list-sockets", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_sockets
},
1162 { "list-timers", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_timers
},
1163 { "list-jobs", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_jobs
},
1164 { "list-machines", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_machines
},
1165 { "clear-jobs", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_trivial_method
},
1166 { "cancel", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_cancel
},
1167 { "start", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1168 { "stop", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1169 { "condstop", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
}, /* For compatibility with ALTLinux */
1170 { "reload", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1171 { "restart", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1172 { "try-restart", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1173 { "reload-or-restart", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1174 { "reload-or-try-restart", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
}, /* For compatibility with old systemctl <= 228 */
1175 { "try-reload-or-restart", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
},
1176 { "force-reload", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
}, /* For compatibility with SysV */
1177 { "condreload", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
}, /* For compatibility with ALTLinux */
1178 { "condrestart", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_start
}, /* For compatibility with RH */
1179 { "isolate", 2, 2, VERB_ONLINE_ONLY
, verb_start
},
1180 { "kill", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_kill
},
1181 { "clean", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_clean_or_freeze
},
1182 { "freeze", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_clean_or_freeze
},
1183 { "thaw", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_clean_or_freeze
},
1184 { "is-active", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_is_active
},
1185 { "check", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_is_active
}, /* deprecated alias of is-active */
1186 { "is-failed", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_is_failed
},
1187 { "show", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_show
},
1188 { "cat", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_cat
},
1189 { "status", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_show
},
1190 { "help", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_show
},
1191 { "daemon-reload", 1, 1, VERB_ONLINE_ONLY
, verb_daemon_reload
},
1192 { "daemon-reexec", 1, 1, VERB_ONLINE_ONLY
, verb_daemon_reload
},
1193 { "log-level", VERB_ANY
, 2, VERB_ONLINE_ONLY
, verb_log_setting
},
1194 { "log-target", VERB_ANY
, 2, VERB_ONLINE_ONLY
, verb_log_setting
},
1195 { "service-log-level", 2, 3, VERB_ONLINE_ONLY
, verb_service_log_setting
},
1196 { "service-log-target", 2, 3, VERB_ONLINE_ONLY
, verb_service_log_setting
},
1197 { "service-watchdogs", VERB_ANY
, 2, VERB_ONLINE_ONLY
, verb_service_watchdogs
},
1198 { "show-environment", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_show_environment
},
1199 { "set-environment", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_set_environment
},
1200 { "unset-environment", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_set_environment
},
1201 { "import-environment", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_import_environment
},
1202 { "halt", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1203 { "poweroff", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1204 { "reboot", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1205 { "kexec", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1206 { "soft-reboot", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1207 { "sleep", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1208 { "suspend", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1209 { "hibernate", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1210 { "hybrid-sleep", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1211 { "suspend-then-hibernate",VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1212 { "default", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_special
},
1213 { "rescue", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1214 { "emergency", VERB_ANY
, 1, VERB_ONLINE_ONLY
, verb_start_system_special
},
1215 { "exit", VERB_ANY
, 2, VERB_ONLINE_ONLY
, verb_start_special
},
1216 { "reset-failed", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_reset_failed
},
1217 { "enable", 2, VERB_ANY
, 0, verb_enable
},
1218 { "disable", 2, VERB_ANY
, 0, verb_enable
},
1219 { "is-enabled", 2, VERB_ANY
, 0, verb_is_enabled
},
1220 { "reenable", 2, VERB_ANY
, 0, verb_enable
},
1221 { "preset", 2, VERB_ANY
, 0, verb_enable
},
1222 { "preset-all", VERB_ANY
, 1, 0, verb_preset_all
},
1223 { "mask", 2, VERB_ANY
, 0, verb_enable
},
1224 { "unmask", 2, VERB_ANY
, 0, verb_enable
},
1225 { "link", 2, VERB_ANY
, 0, verb_enable
},
1226 { "revert", 2, VERB_ANY
, 0, verb_enable
},
1227 { "switch-root", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_switch_root
},
1228 { "list-dependencies", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_list_dependencies
},
1229 { "set-default", 2, 2, 0, verb_set_default
},
1230 { "get-default", VERB_ANY
, 1, 0, verb_get_default
},
1231 { "set-property", 3, VERB_ANY
, VERB_ONLINE_ONLY
, verb_set_property
},
1232 { "is-system-running", VERB_ANY
, 1, 0, verb_is_system_running
},
1233 { "add-wants", 3, VERB_ANY
, 0, verb_add_dependency
},
1234 { "add-requires", 3, VERB_ANY
, 0, verb_add_dependency
},
1235 { "edit", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_edit
},
1236 { "bind", 3, 4, VERB_ONLINE_ONLY
, verb_bind
},
1237 { "mount-image", 4, 5, VERB_ONLINE_ONLY
, verb_mount_image
},
1238 { "whoami", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, verb_whoami
},
1242 const Verb
*verb
= verbs_find_verb(argv
[optind
], verbs
);
1243 if (verb
&& (verb
->flags
& VERB_ONLINE_ONLY
) && arg_root
)
1244 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1245 "Verb '%s' cannot be used with --root= or --image=.",
1246 argv
[optind
] ?: verb
->verb
);
1248 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1251 static int run(int argc
, char *argv
[]) {
1252 _cleanup_(loop_device_unrefp
) LoopDevice
*loop_device
= NULL
;
1253 _cleanup_(umount_and_freep
) char *mounted_dir
= NULL
;
1256 setlocale(LC_ALL
, "");
1259 /* The journal merging logic potentially needs a lot of fds. */
1260 (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE
);
1264 r
= systemctl_dispatch_parse_argv(argc
, argv
);
1268 if (proc_mounted() == 0)
1269 log_full(arg_no_warn
? LOG_DEBUG
: LOG_WARNING
,
1270 "%s%s/proc/ is not mounted. This is not a supported mode of operation. Please fix\n"
1271 "your invocation environment to mount /proc/ and /sys/ properly. Proceeding anyway.\n"
1272 "Your mileage may vary.",
1273 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_WARNING_SIGN
) : "",
1274 emoji_enabled() ? " " : "");
1276 if (arg_action
!= ACTION_SYSTEMCTL
&& running_in_chroot() > 0) {
1278 log_info("Running in chroot, ignoring request.");
1283 /* systemctl_main() will print an error message for the bus connection, but only if it needs to */
1288 r
= mount_image_privately_interactively(
1291 DISSECT_IMAGE_GENERIC_ROOT
|
1292 DISSECT_IMAGE_REQUIRE_ROOT
|
1293 DISSECT_IMAGE_RELAX_VAR_CHECK
|
1294 DISSECT_IMAGE_VALIDATE_OS
|
1295 DISSECT_IMAGE_ALLOW_USERSPACE_VERITY
,
1297 /* ret_dir_fd= */ NULL
,
1302 arg_root
= strdup(mounted_dir
);
1307 switch (arg_action
) {
1309 case ACTION_SYSTEMCTL
:
1310 r
= systemctl_main(argc
, argv
);
1313 /* Legacy command aliases set arg_action. They provide some fallbacks, e.g. to tell sysvinit to
1314 * reboot after you have installed systemd binaries. */
1317 case ACTION_POWEROFF
:
1323 case ACTION_RUNLEVEL2
:
1324 case ACTION_RUNLEVEL3
:
1325 case ACTION_RUNLEVEL4
:
1326 case ACTION_RUNLEVEL5
:
1328 r
= start_with_fallback();
1333 r
= reload_with_fallback();
1336 case ACTION_CANCEL_SHUTDOWN
:
1337 r
= logind_cancel_shutdown();
1340 case ACTION_SHOW_SHUTDOWN
:
1341 r
= logind_show_shutdown();
1344 case ACTION_RUNLEVEL
:
1345 r
= runlevel_main();
1350 case ACTION_SUSPEND
:
1351 case ACTION_HIBERNATE
:
1352 case ACTION_HYBRID_SLEEP
:
1353 case ACTION_SUSPEND_THEN_HIBERNATE
:
1354 case ACTION_EMERGENCY
:
1355 case ACTION_DEFAULT
:
1356 /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in
1357 * arg_action. Fall through. */
1359 case _ACTION_INVALID
:
1361 assert_not_reached();
1367 /* Note that we return r here, not 0, so that we can implement the LSB-like return codes */
1371 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);