]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
7e4249b9 | 2 | |
7e4249b9 | 3 | #include <getopt.h> |
daf71ef6 | 4 | #include <locale.h> |
03a7b521 | 5 | #include <unistd.h> |
81527be1 | 6 | |
f459b602 | 7 | #include "sd-daemon.h" |
daf71ef6 | 8 | |
d6b4d1c7 | 9 | #include "build.h" |
daf71ef6 | 10 | #include "bus-util.h" |
8aa3894e | 11 | #include "dissect-image.h" |
03a7b521 | 12 | #include "install.h" |
d1405af3 | 13 | #include "main-func.h" |
8aa3894e | 14 | #include "mount-util.h" |
daf71ef6 | 15 | #include "output-mode.h" |
03a7b521 | 16 | #include "pager.h" |
86beb213 | 17 | #include "parse-argument.h" |
03a7b521 | 18 | #include "path-util.h" |
294bf0c3 | 19 | #include "pretty-print.h" |
2306d177 | 20 | #include "process-util.h" |
ede5a78f | 21 | #include "reboot-util.h" |
78f22b97 | 22 | #include "rlimit-util.h" |
592705f2 | 23 | #include "sigbus.h" |
24882e06 | 24 | #include "signal-util.h" |
0f958c8d | 25 | #include "stat-util.h" |
8559e61d | 26 | #include "string-table.h" |
daf71ef6 LP |
27 | #include "systemctl-add-dependency.h" |
28 | #include "systemctl-cancel-job.h" | |
29 | #include "systemctl-clean-or-freeze.h" | |
30 | #include "systemctl-compat-halt.h" | |
31 | #include "systemctl-compat-runlevel.h" | |
32 | #include "systemctl-compat-shutdown.h" | |
33 | #include "systemctl-compat-telinit.h" | |
34 | #include "systemctl-daemon-reload.h" | |
35 | #include "systemctl-edit.h" | |
36 | #include "systemctl-enable.h" | |
37 | #include "systemctl-is-active.h" | |
38 | #include "systemctl-is-enabled.h" | |
39 | #include "systemctl-is-system-running.h" | |
40 | #include "systemctl-kill.h" | |
41 | #include "systemctl-list-dependencies.h" | |
42 | #include "systemctl-list-jobs.h" | |
43 | #include "systemctl-list-machines.h" | |
44 | #include "systemctl-list-unit-files.h" | |
45 | #include "systemctl-list-units.h" | |
46 | #include "systemctl-log-setting.h" | |
47 | #include "systemctl-logind.h" | |
5e8deb94 | 48 | #include "systemctl-mount.h" |
daf71ef6 LP |
49 | #include "systemctl-preset-all.h" |
50 | #include "systemctl-reset-failed.h" | |
51 | #include "systemctl-service-watchdogs.h" | |
52 | #include "systemctl-set-default.h" | |
53 | #include "systemctl-set-environment.h" | |
54 | #include "systemctl-set-property.h" | |
55 | #include "systemctl-show.h" | |
56 | #include "systemctl-start-special.h" | |
57 | #include "systemctl-start-unit.h" | |
58 | #include "systemctl-switch-root.h" | |
59 | #include "systemctl-sysv-compat.h" | |
60 | #include "systemctl-trivial-method.h" | |
61 | #include "systemctl-util.h" | |
c86a9508 | 62 | #include "systemctl-whoami.h" |
daf71ef6 | 63 | #include "systemctl.h" |
03a7b521 | 64 | #include "terminal-util.h" |
daf71ef6 | 65 | #include "time-util.h" |
e449de87 | 66 | #include "verbs.h" |
7f4b3c5e | 67 | #include "virt.h" |
7e4249b9 | 68 | |
daf71ef6 LP |
69 | char **arg_types = NULL; |
70 | char **arg_states = NULL; | |
71 | char **arg_properties = NULL; | |
72 | bool arg_all = false; | |
73 | enum dependency arg_dependency = DEPENDENCY_FORWARD; | |
a88f9dba | 74 | const char *_arg_job_mode = NULL; |
4870133b | 75 | RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; |
daf71ef6 LP |
76 | bool arg_wait = false; |
77 | bool arg_no_block = false; | |
6906da26 | 78 | int arg_legend = -1; /* -1: true, unless --quiet is passed, 1: true */ |
daf71ef6 LP |
79 | PagerFlags arg_pager_flags = 0; |
80 | bool arg_no_wtmp = false; | |
81 | bool arg_no_sync = false; | |
82 | bool arg_no_wall = false; | |
83 | bool arg_no_reload = false; | |
255b1fc8 | 84 | BusPrintPropertyFlags arg_print_flags = 0; |
daf71ef6 | 85 | bool arg_show_types = false; |
4327574f | 86 | int arg_check_inhibitors = -1; |
daf71ef6 LP |
87 | bool arg_dry_run = false; |
88 | bool arg_quiet = false; | |
108d35ac | 89 | bool arg_no_warn = false; |
daf71ef6 LP |
90 | bool arg_full = false; |
91 | bool arg_recursive = false; | |
92 | bool arg_with_dependencies = false; | |
93 | bool arg_show_transaction = false; | |
94 | int arg_force = 0; | |
95 | bool arg_ask_password = false; | |
96 | bool arg_runtime = false; | |
97 | UnitFilePresetMode arg_preset_mode = UNIT_FILE_PRESET_FULL; | |
98 | char **arg_wall = NULL; | |
4ccde410 | 99 | const char *arg_kill_whom = NULL; |
daf71ef6 | 100 | int arg_signal = SIGTERM; |
d06e6199 LP |
101 | int arg_kill_value; |
102 | bool arg_kill_value_set = false; | |
daf71ef6 | 103 | char *arg_root = NULL; |
8aa3894e | 104 | char *arg_image = NULL; |
daf71ef6 | 105 | usec_t arg_when = 0; |
329050c5 | 106 | bool arg_stdin = false; |
daf71ef6 LP |
107 | const char *arg_reboot_argument = NULL; |
108 | enum action arg_action = ACTION_SYSTEMCTL; | |
109 | BusTransport arg_transport = BUS_TRANSPORT_LOCAL; | |
110 | const char *arg_host = NULL; | |
111 | unsigned arg_lines = 10; | |
112 | OutputMode arg_output = OUTPUT_SHORT; | |
113 | bool arg_plain = false; | |
114 | bool arg_firmware_setup = false; | |
115 | usec_t arg_boot_loader_menu = USEC_INFINITY; | |
116 | const char *arg_boot_loader_entry = NULL; | |
117 | bool arg_now = false; | |
118 | bool arg_jobs_before = false; | |
119 | bool arg_jobs_after = false; | |
120 | char **arg_clean_what = NULL; | |
121 | TimestampStyle arg_timestamp_style = TIMESTAMP_PRETTY; | |
5e8deb94 LB |
122 | bool arg_read_only = false; |
123 | bool arg_mkdir = false; | |
c9615f73 | 124 | bool arg_marked = false; |
f206809b | 125 | const char *arg_drop_in = NULL; |
84be0c71 | 126 | ImagePolicy *arg_image_policy = NULL; |
e8630e69 | 127 | |
61ff45db LP |
128 | STATIC_DESTRUCTOR_REGISTER(arg_types, strv_freep); |
129 | STATIC_DESTRUCTOR_REGISTER(arg_states, strv_freep); | |
130 | STATIC_DESTRUCTOR_REGISTER(arg_properties, strv_freep); | |
a88f9dba | 131 | STATIC_DESTRUCTOR_REGISTER(_arg_job_mode, unsetp); |
6b42227e | 132 | STATIC_DESTRUCTOR_REGISTER(arg_wall, strv_freep); |
4ccde410 | 133 | STATIC_DESTRUCTOR_REGISTER(arg_kill_whom, unsetp); |
6b42227e | 134 | STATIC_DESTRUCTOR_REGISTER(arg_root, freep); |
8aa3894e | 135 | STATIC_DESTRUCTOR_REGISTER(arg_image, freep); |
a88f9dba ZJS |
136 | STATIC_DESTRUCTOR_REGISTER(arg_reboot_argument, unsetp); |
137 | STATIC_DESTRUCTOR_REGISTER(arg_host, unsetp); | |
138 | STATIC_DESTRUCTOR_REGISTER(arg_boot_loader_entry, unsetp); | |
d81bc51f | 139 | STATIC_DESTRUCTOR_REGISTER(arg_clean_what, strv_freep); |
f206809b | 140 | STATIC_DESTRUCTOR_REGISTER(arg_drop_in, unsetp); |
84be0c71 | 141 | STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); |
4fbd7192 | 142 | |
daf71ef6 LP |
143 | static int systemctl_help(void) { |
144 | _cleanup_free_ char *link = NULL; | |
4fbd7192 LP |
145 | int r; |
146 | ||
384c2c32 | 147 | pager_open(arg_pager_flags); |
4fbd7192 | 148 | |
daf71ef6 LP |
149 | r = terminal_urlify_man("systemctl", "1", &link); |
150 | if (r < 0) | |
151 | return log_oom(); | |
4fbd7192 | 152 | |
daf71ef6 LP |
153 | printf("%1$s [OPTIONS...] COMMAND ...\n\n" |
154 | "%5$sQuery or send control commands to the system manager.%6$s\n" | |
155 | "\n%3$sUnit Commands:%4$s\n" | |
156 | " list-units [PATTERN...] List units currently in memory\n" | |
ed462ea3 DT |
157 | " list-automounts [PATTERN...] List automount units currently in memory,\n" |
158 | " ordered by path\n" | |
5fb5f49b DT |
159 | " list-paths [PATTERN...] List path units currently in memory,\n" |
160 | " ordered by path\n" | |
daf71ef6 LP |
161 | " list-sockets [PATTERN...] List socket units currently in memory,\n" |
162 | " ordered by address\n" | |
163 | " list-timers [PATTERN...] List timer units currently in memory,\n" | |
164 | " ordered by next elapse\n" | |
165 | " is-active PATTERN... Check whether units are active\n" | |
2ee34616 MY |
166 | " is-failed [PATTERN...] Check whether units are failed or\n" |
167 | " system is in degraded state\n" | |
daf71ef6 LP |
168 | " status [PATTERN...|PID...] Show runtime status of one or more units\n" |
169 | " show [PATTERN...|JOB...] Show properties of one or more\n" | |
170 | " units/jobs or the manager\n" | |
171 | " cat PATTERN... Show files and drop-ins of specified units\n" | |
172 | " help PATTERN...|PID... Show manual for one or more units\n" | |
173 | " list-dependencies [UNIT...] Recursively show units which are required\n" | |
174 | " or wanted by the units or by which those\n" | |
175 | " units are required or wanted\n" | |
176 | " start UNIT... Start (activate) one or more units\n" | |
177 | " stop UNIT... Stop (deactivate) one or more units\n" | |
178 | " reload UNIT... Reload one or more units\n" | |
179 | " restart UNIT... Start or restart one or more units\n" | |
180 | " try-restart UNIT... Restart one or more units if active\n" | |
181 | " reload-or-restart UNIT... Reload one or more units if possible,\n" | |
182 | " otherwise start or restart\n" | |
183 | " try-reload-or-restart UNIT... If active, reload one or more units,\n" | |
184 | " if supported, otherwise restart\n" | |
185 | " isolate UNIT Start one unit and stop all others\n" | |
186 | " kill UNIT... Send signal to processes of a unit\n" | |
187 | " clean UNIT... Clean runtime, cache, state, logs or\n" | |
188 | " configuration of unit\n" | |
189 | " freeze PATTERN... Freeze execution of unit processes\n" | |
190 | " thaw PATTERN... Resume execution of a frozen unit\n" | |
191 | " set-property UNIT PROPERTY=VALUE... Sets one or more properties of a unit\n" | |
5e8deb94 LB |
192 | " bind UNIT PATH [PATH] Bind-mount a path from the host into a\n" |
193 | " unit's namespace\n" | |
6faecbd3 LB |
194 | " mount-image UNIT PATH [PATH [OPTS]] Mount an image from the host into a\n" |
195 | " unit's namespace\n" | |
daf71ef6 LP |
196 | " service-log-level SERVICE [LEVEL] Get/set logging threshold for service\n" |
197 | " service-log-target SERVICE [TARGET] Get/set logging target for service\n" | |
198 | " reset-failed [PATTERN...] Reset failed state for all, one, or more\n" | |
c86a9508 LP |
199 | " units\n" |
200 | " whoami [PID...] Return unit caller or specified PIDs are\n" | |
201 | " part of\n" | |
daf71ef6 LP |
202 | "\n%3$sUnit File Commands:%4$s\n" |
203 | " list-unit-files [PATTERN...] List installed unit files\n" | |
204 | " enable [UNIT...|PATH...] Enable one or more unit files\n" | |
205 | " disable UNIT... Disable one or more unit files\n" | |
206 | " reenable UNIT... Reenable one or more unit files\n" | |
207 | " preset UNIT... Enable/disable one or more unit files\n" | |
208 | " based on preset configuration\n" | |
209 | " preset-all Enable/disable all unit files based on\n" | |
210 | " preset configuration\n" | |
211 | " is-enabled UNIT... Check whether unit files are enabled\n" | |
212 | " mask UNIT... Mask one or more units\n" | |
213 | " unmask UNIT... Unmask one or more units\n" | |
214 | " link PATH... Link one or more units files into\n" | |
215 | " the search path\n" | |
216 | " revert UNIT... Revert one or more unit files to vendor\n" | |
217 | " version\n" | |
218 | " add-wants TARGET UNIT... Add 'Wants' dependency for the target\n" | |
219 | " on specified one or more units\n" | |
220 | " add-requires TARGET UNIT... Add 'Requires' dependency for the target\n" | |
221 | " on specified one or more units\n" | |
222 | " edit UNIT... Edit one or more unit files\n" | |
223 | " get-default Get the name of the default target\n" | |
224 | " set-default TARGET Set the default target\n" | |
225 | "\n%3$sMachine Commands:%4$s\n" | |
226 | " list-machines [PATTERN...] List local containers and host\n" | |
227 | "\n%3$sJob Commands:%4$s\n" | |
228 | " list-jobs [PATTERN...] List jobs\n" | |
229 | " cancel [JOB...] Cancel all, one, or more jobs\n" | |
230 | "\n%3$sEnvironment Commands:%4$s\n" | |
231 | " show-environment Dump environment\n" | |
232 | " set-environment VARIABLE=VALUE... Set one or more environment variables\n" | |
233 | " unset-environment VARIABLE... Unset one or more environment variables\n" | |
32854f70 | 234 | " import-environment VARIABLE... Import all or some environment variables\n" |
daf71ef6 LP |
235 | "\n%3$sManager State Commands:%4$s\n" |
236 | " daemon-reload Reload systemd manager configuration\n" | |
237 | " daemon-reexec Reexecute systemd manager\n" | |
238 | " log-level [LEVEL] Get/set logging threshold for manager\n" | |
239 | " log-target [TARGET] Get/set logging target for manager\n" | |
240 | " service-watchdogs [BOOL] Get/set service watchdog state\n" | |
241 | "\n%3$sSystem Commands:%4$s\n" | |
242 | " is-system-running Check whether system is fully running\n" | |
243 | " default Enter system default mode\n" | |
244 | " rescue Enter system rescue mode\n" | |
245 | " emergency Enter system emergency mode\n" | |
246 | " halt Shut down and halt the system\n" | |
247 | " poweroff Shut down and power-off the system\n" | |
248 | " reboot Shut down and reboot the system\n" | |
249 | " kexec Shut down and reboot the system with kexec\n" | |
34f21ff6 | 250 | " soft-reboot Shut down and reboot userspace\n" |
daf71ef6 | 251 | " exit [EXIT_CODE] Request user instance or container exit\n" |
5ae89ef3 | 252 | " switch-root [ROOT [INIT]] Change to a different root file system\n" |
daf71ef6 LP |
253 | " suspend Suspend the system\n" |
254 | " hibernate Hibernate the system\n" | |
255 | " hybrid-sleep Hibernate and suspend the system\n" | |
256 | " suspend-then-hibernate Suspend the system, wake after a period of\n" | |
257 | " time, and hibernate" | |
258 | "\n%3$sOptions:%4$s\n" | |
259 | " -h --help Show this help\n" | |
260 | " --version Show package version\n" | |
261 | " --system Connect to system manager\n" | |
262 | " --user Connect to user service manager\n" | |
263 | " -H --host=[USER@]HOST Operate on remote host\n" | |
264 | " -M --machine=CONTAINER Operate on a local container\n" | |
265 | " -t --type=TYPE List units of a particular type\n" | |
266 | " --state=STATE List units with particular LOAD or SUB or ACTIVE state\n" | |
267 | " --failed Shortcut for --state=failed\n" | |
268 | " -p --property=NAME Show only properties by this name\n" | |
269 | " -P NAME Equivalent to --value --property=NAME\n" | |
270 | " -a --all Show all properties/all units currently in memory,\n" | |
271 | " including dead/empty ones. To list all units installed\n" | |
272 | " on the system, use 'list-unit-files' instead.\n" | |
273 | " -l --full Don't ellipsize unit names on output\n" | |
274 | " -r --recursive Show unit list of host and local containers\n" | |
275 | " --reverse Show reverse dependencies with 'list-dependencies'\n" | |
276 | " --with-dependencies Show unit dependencies with 'status', 'cat',\n" | |
277 | " 'list-units', and 'list-unit-files'.\n" | |
278 | " --job-mode=MODE Specify how to deal with already queued jobs, when\n" | |
279 | " queueing a new job\n" | |
280 | " -T --show-transaction When enqueuing a unit job, show full transaction\n" | |
281 | " --show-types When showing sockets, explicitly show their type\n" | |
282 | " --value When showing properties, only print the value\n" | |
4327574f | 283 | " --check-inhibitors=MODE\n" |
5b69a7c5 ZJS |
284 | " Whether to check inhibitors before shutting down,\n" |
285 | " sleeping, or hibernating\n" | |
4327574f | 286 | " -i Shortcut for --check-inhibitors=no\n" |
4ccde410 | 287 | " --kill-whom=WHOM Whom to send signal to\n" |
d06e6199 | 288 | " --kill-value=INT Signal value to enqueue\n" |
daf71ef6 LP |
289 | " -s --signal=SIGNAL Which signal to send\n" |
290 | " --what=RESOURCES Which types of resources to remove\n" | |
291 | " --now Start or stop unit after enabling or disabling it\n" | |
292 | " --dry-run Only print what would be done\n" | |
293 | " Currently supported by verbs: halt, poweroff, reboot,\n" | |
34f21ff6 LP |
294 | " kexec, soft-reboot, suspend, hibernate, \n" |
295 | " suspend-then-hibernate, hybrid-sleep, default,\n" | |
296 | " rescue, emergency, and exit.\n" | |
daf71ef6 | 297 | " -q --quiet Suppress output\n" |
91dfb74e | 298 | " --no-warn Suppress several warnings shown by default\n" |
daf71ef6 LP |
299 | " --wait For (re)start, wait until service stopped again\n" |
300 | " For is-system-running, wait until startup is completed\n" | |
301 | " --no-block Do not wait until operation finished\n" | |
302 | " --no-wall Don't send wall message before halt/power-off/reboot\n" | |
303 | " --no-reload Don't reload daemon after en-/dis-abling unit files\n" | |
6906da26 | 304 | " --legend=BOOL Enable/disable the legend (column headers and hints)\n" |
daf71ef6 LP |
305 | " --no-pager Do not pipe output into a pager\n" |
306 | " --no-ask-password Do not ask for system passwords\n" | |
4218f81d EP |
307 | " --global Edit/enable/disable/mask default user unit files\n" |
308 | " globally\n" | |
309 | " --runtime Edit/enable/disable/mask unit files temporarily until\n" | |
310 | " next reboot\n" | |
daf71ef6 LP |
311 | " -f --force When enabling unit files, override existing symlinks\n" |
312 | " When shutting down, execute action immediately\n" | |
313 | " --preset-mode= Apply only enable, only disable, or all presets\n" | |
4218f81d EP |
314 | " --root=PATH Edit/enable/disable/mask unit files in the specified\n" |
315 | " root directory\n" | |
8aa3894e | 316 | " --image=PATH Edit/enable/disable/mask unit files in the specified\n" |
84be0c71 LP |
317 | " disk image\n" |
318 | " --image-policy=POLICY\n" | |
319 | " Specify disk image dissection policy\n" | |
daf71ef6 LP |
320 | " -n --lines=INTEGER Number of journal entries to show\n" |
321 | " -o --output=STRING Change journal output mode (short, short-precise,\n" | |
322 | " short-iso, short-iso-precise, short-full,\n" | |
893bcd3d | 323 | " short-monotonic, short-unix, short-delta,\n" |
daf71ef6 LP |
324 | " verbose, export, json, json-pretty, json-sse, cat)\n" |
325 | " --firmware-setup Tell the firmware to show the setup menu on next boot\n" | |
326 | " --boot-loader-menu=TIME\n" | |
327 | " Boot into boot loader menu on next boot\n" | |
328 | " --boot-loader-entry=NAME\n" | |
329 | " Boot into a specific boot loader entry on next boot\n" | |
330 | " --plain Print unit dependencies as a list instead of a tree\n" | |
b58b4a9f FS |
331 | " --timestamp=FORMAT Change format of printed timestamps (pretty, unix,\n" |
332 | " us, utc, us+utc)\n" | |
5e8deb94 | 333 | " --read-only Create read-only bind mount\n" |
6faecbd3 | 334 | " --mkdir Create directory before mounting, if missing\n" |
c9615f73 | 335 | " --marked Restart/reload previously marked units\n" |
f206809b | 336 | " --drop-in=NAME Edit unit files using the specified drop-in file name\n" |
1433e1f9 MY |
337 | " --when=TIME Schedule halt/power-off/reboot/kexec action after\n" |
338 | " a certain timestamp\n" | |
329050c5 | 339 | " --stdin Read contents of edited file from stdin\n" |
bc556335 DDM |
340 | "\nSee the %2$s for details.\n", |
341 | program_invocation_short_name, | |
342 | link, | |
343 | ansi_underline(), | |
344 | ansi_normal(), | |
345 | ansi_highlight(), | |
346 | ansi_normal()); | |
4fbd7192 | 347 | |
4fbd7192 LP |
348 | return 0; |
349 | } | |
350 | ||
daf71ef6 | 351 | static void help_types(void) { |
6906da26 | 352 | if (arg_legend != 0) |
daf71ef6 | 353 | puts("Available unit types:"); |
501fc174 | 354 | |
daf71ef6 | 355 | DUMP_STRING_TABLE(unit_type, UnitType, _UNIT_TYPE_MAX); |
3c756001 LP |
356 | } |
357 | ||
daf71ef6 | 358 | static void help_states(void) { |
6906da26 | 359 | if (arg_legend != 0) |
daf71ef6 LP |
360 | puts("Available unit load states:"); |
361 | DUMP_STRING_TABLE(unit_load_state, UnitLoadState, _UNIT_LOAD_STATE_MAX); | |
22f4096c | 362 | |
6906da26 | 363 | if (arg_legend != 0) |
daf71ef6 LP |
364 | puts("\nAvailable unit active states:"); |
365 | DUMP_STRING_TABLE(unit_active_state, UnitActiveState, _UNIT_ACTIVE_STATE_MAX); | |
22f4096c | 366 | |
6906da26 | 367 | if (arg_legend != 0) |
daf71ef6 LP |
368 | puts("\nAvailable unit file states:"); |
369 | DUMP_STRING_TABLE(unit_file_state, UnitFileState, _UNIT_FILE_STATE_MAX); | |
22f4096c | 370 | |
6906da26 | 371 | if (arg_legend != 0) |
daf71ef6 LP |
372 | puts("\nAvailable automount unit substates:"); |
373 | DUMP_STRING_TABLE(automount_state, AutomountState, _AUTOMOUNT_STATE_MAX); | |
22f4096c | 374 | |
6906da26 | 375 | if (arg_legend != 0) |
daf71ef6 LP |
376 | puts("\nAvailable device unit substates:"); |
377 | DUMP_STRING_TABLE(device_state, DeviceState, _DEVICE_STATE_MAX); | |
4f16c1f4 | 378 | |
6906da26 | 379 | if (arg_legend != 0) |
daf71ef6 LP |
380 | puts("\nAvailable mount unit substates:"); |
381 | DUMP_STRING_TABLE(mount_state, MountState, _MOUNT_STATE_MAX); | |
729e3769 | 382 | |
6906da26 | 383 | if (arg_legend != 0) |
daf71ef6 LP |
384 | puts("\nAvailable path unit substates:"); |
385 | DUMP_STRING_TABLE(path_state, PathState, _PATH_STATE_MAX); | |
729e3769 | 386 | |
6906da26 | 387 | if (arg_legend != 0) |
daf71ef6 LP |
388 | puts("\nAvailable scope unit substates:"); |
389 | DUMP_STRING_TABLE(scope_state, ScopeState, _SCOPE_STATE_MAX); | |
729e3769 | 390 | |
6906da26 | 391 | if (arg_legend != 0) |
daf71ef6 LP |
392 | puts("\nAvailable service unit substates:"); |
393 | DUMP_STRING_TABLE(service_state, ServiceState, _SERVICE_STATE_MAX); | |
729e3769 | 394 | |
6906da26 | 395 | if (arg_legend != 0) |
daf71ef6 LP |
396 | puts("\nAvailable slice unit substates:"); |
397 | DUMP_STRING_TABLE(slice_state, SliceState, _SLICE_STATE_MAX); | |
b41b9d2a | 398 | |
6906da26 | 399 | if (arg_legend != 0) |
daf71ef6 LP |
400 | puts("\nAvailable socket unit substates:"); |
401 | DUMP_STRING_TABLE(socket_state, SocketState, _SOCKET_STATE_MAX); | |
729e3769 | 402 | |
6906da26 | 403 | if (arg_legend != 0) |
daf71ef6 LP |
404 | puts("\nAvailable swap unit substates:"); |
405 | DUMP_STRING_TABLE(swap_state, SwapState, _SWAP_STATE_MAX); | |
16484a8a | 406 | |
6906da26 | 407 | if (arg_legend != 0) |
daf71ef6 LP |
408 | puts("\nAvailable target unit substates:"); |
409 | DUMP_STRING_TABLE(target_state, TargetState, _TARGET_STATE_MAX); | |
16484a8a | 410 | |
6906da26 | 411 | if (arg_legend != 0) |
daf71ef6 LP |
412 | puts("\nAvailable timer unit substates:"); |
413 | DUMP_STRING_TABLE(timer_state, TimerState, _TIMER_STATE_MAX); | |
16484a8a ZJS |
414 | } |
415 | ||
daf71ef6 LP |
416 | static int systemctl_parse_argv(int argc, char *argv[]) { |
417 | enum { | |
6906da26 | 418 | ARG_FAIL = 0x100, /* compatibility only */ |
daf71ef6 LP |
419 | ARG_REVERSE, |
420 | ARG_AFTER, | |
421 | ARG_BEFORE, | |
4327574f | 422 | ARG_CHECK_INHIBITORS, |
daf71ef6 LP |
423 | ARG_DRY_RUN, |
424 | ARG_SHOW_TYPES, | |
6906da26 ZJS |
425 | ARG_IRREVERSIBLE, /* compatibility only */ |
426 | ARG_IGNORE_DEPENDENCIES, /* compatibility only */ | |
daf71ef6 LP |
427 | ARG_VALUE, |
428 | ARG_VERSION, | |
429 | ARG_USER, | |
430 | ARG_SYSTEM, | |
431 | ARG_GLOBAL, | |
432 | ARG_NO_BLOCK, | |
6906da26 ZJS |
433 | ARG_LEGEND, |
434 | ARG_NO_LEGEND, /* compatibility only */ | |
daf71ef6 LP |
435 | ARG_NO_PAGER, |
436 | ARG_NO_WALL, | |
437 | ARG_ROOT, | |
8aa3894e | 438 | ARG_IMAGE, |
06e78680 | 439 | ARG_IMAGE_POLICY, |
daf71ef6 | 440 | ARG_NO_RELOAD, |
4ccde410 | 441 | ARG_KILL_WHOM, |
d06e6199 | 442 | ARG_KILL_VALUE, |
daf71ef6 LP |
443 | ARG_NO_ASK_PASSWORD, |
444 | ARG_FAILED, | |
445 | ARG_RUNTIME, | |
446 | ARG_PLAIN, | |
447 | ARG_STATE, | |
448 | ARG_JOB_MODE, | |
449 | ARG_PRESET_MODE, | |
450 | ARG_FIRMWARE_SETUP, | |
451 | ARG_BOOT_LOADER_MENU, | |
452 | ARG_BOOT_LOADER_ENTRY, | |
453 | ARG_NOW, | |
454 | ARG_MESSAGE, | |
455 | ARG_WITH_DEPENDENCIES, | |
456 | ARG_WAIT, | |
457 | ARG_WHAT, | |
458 | ARG_REBOOT_ARG, | |
459 | ARG_TIMESTAMP_STYLE, | |
5e8deb94 LB |
460 | ARG_READ_ONLY, |
461 | ARG_MKDIR, | |
c9615f73 | 462 | ARG_MARKED, |
108d35ac | 463 | ARG_NO_WARN, |
f206809b | 464 | ARG_DROP_IN, |
1433e1f9 | 465 | ARG_WHEN, |
329050c5 | 466 | ARG_STDIN, |
daf71ef6 | 467 | }; |
1238ee09 | 468 | |
daf71ef6 LP |
469 | static const struct option options[] = { |
470 | { "help", no_argument, NULL, 'h' }, | |
471 | { "version", no_argument, NULL, ARG_VERSION }, | |
472 | { "type", required_argument, NULL, 't' }, | |
473 | { "property", required_argument, NULL, 'p' }, | |
474 | { "all", no_argument, NULL, 'a' }, | |
475 | { "reverse", no_argument, NULL, ARG_REVERSE }, | |
476 | { "after", no_argument, NULL, ARG_AFTER }, | |
477 | { "before", no_argument, NULL, ARG_BEFORE }, | |
478 | { "show-types", no_argument, NULL, ARG_SHOW_TYPES }, | |
40a49f12 | 479 | { "failed", no_argument, NULL, ARG_FAILED }, |
daf71ef6 LP |
480 | { "full", no_argument, NULL, 'l' }, |
481 | { "job-mode", required_argument, NULL, ARG_JOB_MODE }, | |
482 | { "fail", no_argument, NULL, ARG_FAIL }, /* compatibility only */ | |
483 | { "irreversible", no_argument, NULL, ARG_IRREVERSIBLE }, /* compatibility only */ | |
484 | { "ignore-dependencies", no_argument, NULL, ARG_IGNORE_DEPENDENCIES }, /* compatibility only */ | |
4327574f FS |
485 | { "ignore-inhibitors", no_argument, NULL, 'i' }, /* compatibility only */ |
486 | { "check-inhibitors", required_argument, NULL, ARG_CHECK_INHIBITORS }, | |
daf71ef6 LP |
487 | { "value", no_argument, NULL, ARG_VALUE }, |
488 | { "user", no_argument, NULL, ARG_USER }, | |
489 | { "system", no_argument, NULL, ARG_SYSTEM }, | |
490 | { "global", no_argument, NULL, ARG_GLOBAL }, | |
491 | { "wait", no_argument, NULL, ARG_WAIT }, | |
492 | { "no-block", no_argument, NULL, ARG_NO_BLOCK }, | |
6906da26 ZJS |
493 | { "legend", required_argument, NULL, ARG_LEGEND }, |
494 | { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, /* compatibility only */ | |
daf71ef6 LP |
495 | { "no-pager", no_argument, NULL, ARG_NO_PAGER }, |
496 | { "no-wall", no_argument, NULL, ARG_NO_WALL }, | |
497 | { "dry-run", no_argument, NULL, ARG_DRY_RUN }, | |
498 | { "quiet", no_argument, NULL, 'q' }, | |
108d35ac | 499 | { "no-warn", no_argument, NULL, ARG_NO_WARN }, |
daf71ef6 | 500 | { "root", required_argument, NULL, ARG_ROOT }, |
8aa3894e | 501 | { "image", required_argument, NULL, ARG_IMAGE }, |
06e78680 | 502 | { "image-policy", required_argument, NULL, ARG_IMAGE_POLICY }, |
daf71ef6 LP |
503 | { "force", no_argument, NULL, 'f' }, |
504 | { "no-reload", no_argument, NULL, ARG_NO_RELOAD }, | |
4ccde410 | 505 | { "kill-whom", required_argument, NULL, ARG_KILL_WHOM }, |
d06e6199 | 506 | { "kill-value", required_argument, NULL, ARG_KILL_VALUE }, |
daf71ef6 LP |
507 | { "signal", required_argument, NULL, 's' }, |
508 | { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, | |
509 | { "host", required_argument, NULL, 'H' }, | |
510 | { "machine", required_argument, NULL, 'M' }, | |
511 | { "runtime", no_argument, NULL, ARG_RUNTIME }, | |
512 | { "lines", required_argument, NULL, 'n' }, | |
513 | { "output", required_argument, NULL, 'o' }, | |
514 | { "plain", no_argument, NULL, ARG_PLAIN }, | |
515 | { "state", required_argument, NULL, ARG_STATE }, | |
516 | { "recursive", no_argument, NULL, 'r' }, | |
517 | { "with-dependencies", no_argument, NULL, ARG_WITH_DEPENDENCIES }, | |
518 | { "preset-mode", required_argument, NULL, ARG_PRESET_MODE }, | |
519 | { "firmware-setup", no_argument, NULL, ARG_FIRMWARE_SETUP }, | |
520 | { "boot-loader-menu", required_argument, NULL, ARG_BOOT_LOADER_MENU }, | |
521 | { "boot-loader-entry", required_argument, NULL, ARG_BOOT_LOADER_ENTRY }, | |
522 | { "now", no_argument, NULL, ARG_NOW }, | |
523 | { "message", required_argument, NULL, ARG_MESSAGE }, | |
524 | { "show-transaction", no_argument, NULL, 'T' }, | |
525 | { "what", required_argument, NULL, ARG_WHAT }, | |
526 | { "reboot-argument", required_argument, NULL, ARG_REBOOT_ARG }, | |
527 | { "timestamp", required_argument, NULL, ARG_TIMESTAMP_STYLE }, | |
5e8deb94 LB |
528 | { "read-only", no_argument, NULL, ARG_READ_ONLY }, |
529 | { "mkdir", no_argument, NULL, ARG_MKDIR }, | |
c9615f73 | 530 | { "marked", no_argument, NULL, ARG_MARKED }, |
f206809b | 531 | { "drop-in", required_argument, NULL, ARG_DROP_IN }, |
1433e1f9 | 532 | { "when", required_argument, NULL, ARG_WHEN }, |
329050c5 | 533 | { "stdin", no_argument, NULL, ARG_STDIN }, |
daf71ef6 LP |
534 | {} |
535 | }; | |
1238ee09 | 536 | |
daf71ef6 | 537 | int c, r; |
d309c1c3 | 538 | |
daf71ef6 LP |
539 | assert(argc >= 0); |
540 | assert(argv); | |
d309c1c3 | 541 | |
daf71ef6 LP |
542 | /* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */ |
543 | arg_ask_password = true; | |
d309c1c3 | 544 | |
daf71ef6 | 545 | while ((c = getopt_long(argc, argv, "ht:p:P:alqfs:H:M:n:o:iTr.::", options, NULL)) >= 0) |
57ab2eab | 546 | |
daf71ef6 | 547 | switch (c) { |
9ef15026 | 548 | |
daf71ef6 LP |
549 | case 'h': |
550 | return systemctl_help(); | |
85d9b598 | 551 | |
daf71ef6 LP |
552 | case ARG_VERSION: |
553 | return version(); | |
e9c387c8 | 554 | |
76e5e267 | 555 | case 't': |
d81bc51f | 556 | if (isempty(optarg)) |
daf71ef6 LP |
557 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
558 | "--type= requires arguments."); | |
d81bc51f | 559 | |
76e5e267 | 560 | for (const char *p = optarg;;) { |
daf71ef6 | 561 | _cleanup_free_ char *type = NULL; |
d81bc51f | 562 | |
daf71ef6 | 563 | r = extract_first_word(&p, &type, ",", 0); |
d81bc51f | 564 | if (r < 0) |
daf71ef6 | 565 | return log_error_errno(r, "Failed to parse type: %s", optarg); |
d81bc51f LP |
566 | if (r == 0) |
567 | break; | |
568 | ||
daf71ef6 LP |
569 | if (streq(type, "help")) { |
570 | help_types(); | |
d81bc51f LP |
571 | return 0; |
572 | } | |
573 | ||
daf71ef6 LP |
574 | if (unit_type_from_string(type) >= 0) { |
575 | if (strv_consume(&arg_types, TAKE_PTR(type)) < 0) | |
576 | return log_oom(); | |
577 | continue; | |
578 | } | |
579 | ||
580 | /* It's much nicer to use --state= for load states, but let's support this in | |
581 | * --types= too for compatibility with old versions */ | |
582 | if (unit_load_state_from_string(type) >= 0) { | |
583 | if (strv_consume(&arg_states, TAKE_PTR(type)) < 0) | |
584 | return log_oom(); | |
585 | continue; | |
586 | } | |
587 | ||
588 | log_error("Unknown unit type or load state '%s'.", type); | |
589 | return log_info_errno(SYNTHETIC_ERRNO(EINVAL), | |
590 | "Use -t help to see a list of allowed values."); | |
d81bc51f LP |
591 | } |
592 | ||
593 | break; | |
d81bc51f | 594 | |
daf71ef6 | 595 | case 'P': |
255b1fc8 | 596 | SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true); |
daf71ef6 | 597 | _fallthrough_; |
dae710be | 598 | |
daf71ef6 LP |
599 | case 'p': |
600 | /* Make sure that if the empty property list was specified, we won't show any | |
601 | properties. */ | |
602 | if (isempty(optarg) && !arg_properties) { | |
603 | arg_properties = new0(char*, 1); | |
604 | if (!arg_properties) | |
605 | return log_oom(); | |
76e5e267 ZJS |
606 | } else |
607 | for (const char *p = optarg;;) { | |
daf71ef6 | 608 | _cleanup_free_ char *prop = NULL; |
46ad9c53 | 609 | |
daf71ef6 LP |
610 | r = extract_first_word(&p, &prop, ",", 0); |
611 | if (r < 0) | |
612 | return log_error_errno(r, "Failed to parse property: %s", optarg); | |
613 | if (r == 0) | |
614 | break; | |
46ad9c53 | 615 | |
daf71ef6 LP |
616 | if (strv_consume(&arg_properties, TAKE_PTR(prop)) < 0) |
617 | return log_oom(); | |
618 | } | |
2e7e19ca | 619 | |
daf71ef6 | 620 | /* If the user asked for a particular property, show it, even if it is empty. */ |
255b1fc8 | 621 | SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true); |
7e4249b9 | 622 | |
daf71ef6 | 623 | break; |
7e4249b9 | 624 | |
daf71ef6 | 625 | case 'a': |
255b1fc8 | 626 | SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true); |
daf71ef6 LP |
627 | arg_all = true; |
628 | break; | |
a8f11321 | 629 | |
daf71ef6 LP |
630 | case ARG_REVERSE: |
631 | arg_dependency = DEPENDENCY_REVERSE; | |
632 | break; | |
93a08841 | 633 | |
daf71ef6 LP |
634 | case ARG_AFTER: |
635 | arg_dependency = DEPENDENCY_AFTER; | |
636 | arg_jobs_after = true; | |
637 | break; | |
7e4249b9 | 638 | |
daf71ef6 LP |
639 | case ARG_BEFORE: |
640 | arg_dependency = DEPENDENCY_BEFORE; | |
641 | arg_jobs_before = true; | |
642 | break; | |
e4b61340 | 643 | |
daf71ef6 LP |
644 | case ARG_SHOW_TYPES: |
645 | arg_show_types = true; | |
646 | break; | |
e4b61340 | 647 | |
daf71ef6 | 648 | case ARG_VALUE: |
255b1fc8 | 649 | SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true); |
daf71ef6 | 650 | break; |
e4b61340 | 651 | |
daf71ef6 | 652 | case ARG_JOB_MODE: |
a88f9dba | 653 | _arg_job_mode = optarg; |
daf71ef6 | 654 | break; |
e4b61340 | 655 | |
daf71ef6 | 656 | case ARG_FAIL: |
a88f9dba | 657 | _arg_job_mode = "fail"; |
daf71ef6 | 658 | break; |
e4b61340 | 659 | |
daf71ef6 | 660 | case ARG_IRREVERSIBLE: |
a88f9dba | 661 | _arg_job_mode = "replace-irreversibly"; |
daf71ef6 | 662 | break; |
e4b61340 | 663 | |
daf71ef6 | 664 | case ARG_IGNORE_DEPENDENCIES: |
a88f9dba | 665 | _arg_job_mode = "ignore-dependencies"; |
daf71ef6 | 666 | break; |
e4b61340 | 667 | |
daf71ef6 | 668 | case ARG_USER: |
4870133b | 669 | arg_runtime_scope = RUNTIME_SCOPE_USER; |
e4b61340 LP |
670 | break; |
671 | ||
daf71ef6 | 672 | case ARG_SYSTEM: |
4870133b | 673 | arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; |
e4b61340 LP |
674 | break; |
675 | ||
daf71ef6 | 676 | case ARG_GLOBAL: |
4870133b | 677 | arg_runtime_scope = RUNTIME_SCOPE_GLOBAL; |
e4b61340 LP |
678 | break; |
679 | ||
daf71ef6 LP |
680 | case ARG_WAIT: |
681 | arg_wait = true; | |
e4b61340 LP |
682 | break; |
683 | ||
daf71ef6 LP |
684 | case ARG_NO_BLOCK: |
685 | arg_no_block = true; | |
e4b61340 LP |
686 | break; |
687 | ||
daf71ef6 | 688 | case ARG_NO_LEGEND: |
6906da26 ZJS |
689 | arg_legend = false; |
690 | break; | |
691 | ||
692 | case ARG_LEGEND: | |
693 | r = parse_boolean_argument("--legend", optarg, NULL); | |
694 | if (r < 0) | |
695 | return r; | |
696 | arg_legend = r; | |
e4b61340 LP |
697 | break; |
698 | ||
daf71ef6 LP |
699 | case ARG_NO_PAGER: |
700 | arg_pager_flags |= PAGER_DISABLE; | |
f3f054f0 TB |
701 | break; |
702 | ||
514f4ef5 LP |
703 | case ARG_NO_WALL: |
704 | arg_no_wall = true; | |
705 | break; | |
706 | ||
daf71ef6 | 707 | case ARG_ROOT: |
614b022c | 708 | r = parse_path_argument(optarg, false, &arg_root); |
daf71ef6 LP |
709 | if (r < 0) |
710 | return r; | |
e4b61340 LP |
711 | break; |
712 | ||
8aa3894e RP |
713 | case ARG_IMAGE: |
714 | r = parse_path_argument(optarg, false, &arg_image); | |
715 | if (r < 0) | |
716 | return r; | |
717 | break; | |
718 | ||
06e78680 YW |
719 | case ARG_IMAGE_POLICY: |
720 | r = parse_image_policy_argument(optarg, &arg_image_policy); | |
721 | if (r < 0) | |
722 | return r; | |
723 | break; | |
724 | ||
daf71ef6 LP |
725 | case 'l': |
726 | arg_full = true; | |
727 | break; | |
e4b61340 | 728 | |
daf71ef6 LP |
729 | case ARG_FAILED: |
730 | if (strv_extend(&arg_states, "failed") < 0) | |
731 | return log_oom(); | |
e4b61340 | 732 | |
daf71ef6 | 733 | break; |
e4b61340 | 734 | |
daf71ef6 LP |
735 | case ARG_DRY_RUN: |
736 | arg_dry_run = true; | |
737 | break; | |
e4b61340 | 738 | |
daf71ef6 LP |
739 | case 'q': |
740 | arg_quiet = true; | |
6906da26 ZJS |
741 | |
742 | if (arg_legend < 0) | |
743 | arg_legend = false; | |
744 | ||
daf71ef6 | 745 | break; |
e4b61340 | 746 | |
daf71ef6 LP |
747 | case 'f': |
748 | arg_force++; | |
749 | break; | |
e4b61340 | 750 | |
daf71ef6 LP |
751 | case ARG_NO_RELOAD: |
752 | arg_no_reload = true; | |
753 | break; | |
e4b61340 | 754 | |
4ccde410 ZJS |
755 | case ARG_KILL_WHOM: |
756 | arg_kill_whom = optarg; | |
daf71ef6 | 757 | break; |
e4b61340 | 758 | |
d06e6199 LP |
759 | case ARG_KILL_VALUE: { |
760 | unsigned u; | |
761 | ||
762 | if (isempty(optarg)) { | |
763 | arg_kill_value_set = false; | |
764 | return 0; | |
765 | } | |
766 | ||
767 | /* First, try to parse unsigned, so that we can support the prefixes 0x, 0o, 0b */ | |
768 | r = safe_atou_full(optarg, 0, &u); | |
769 | if (r < 0) | |
770 | /* If this didn't work, try as signed integer, without those prefixes */ | |
771 | r = safe_atoi(optarg, &arg_kill_value); | |
772 | else if (u > INT_MAX) | |
773 | r = -ERANGE; | |
774 | else | |
775 | arg_kill_value = (int) u; | |
776 | if (r < 0) | |
777 | return log_error_errno(r, "Unable to parse signal queue value: %s", optarg); | |
778 | ||
779 | arg_kill_value_set = true; | |
780 | break; | |
781 | } | |
782 | ||
daf71ef6 | 783 | case 's': |
86beb213 ZJS |
784 | r = parse_signal_argument(optarg, &arg_signal); |
785 | if (r <= 0) | |
786 | return r; | |
daf71ef6 | 787 | break; |
e4b61340 | 788 | |
daf71ef6 LP |
789 | case ARG_NO_ASK_PASSWORD: |
790 | arg_ask_password = false; | |
791 | break; | |
e4b61340 LP |
792 | |
793 | case 'H': | |
daf71ef6 LP |
794 | arg_transport = BUS_TRANSPORT_REMOTE; |
795 | arg_host = optarg; | |
e4b61340 LP |
796 | break; |
797 | ||
daf71ef6 LP |
798 | case 'M': |
799 | arg_transport = BUS_TRANSPORT_MACHINE; | |
800 | arg_host = optarg; | |
e4b61340 LP |
801 | break; |
802 | ||
daf71ef6 LP |
803 | case ARG_RUNTIME: |
804 | arg_runtime = true; | |
e4b61340 LP |
805 | break; |
806 | ||
daf71ef6 LP |
807 | case 'n': |
808 | if (safe_atou(optarg, &arg_lines) < 0) | |
809 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
810 | "Failed to parse lines '%s'", | |
811 | optarg); | |
04ebb595 LP |
812 | break; |
813 | ||
daf71ef6 LP |
814 | case 'o': |
815 | if (streq(optarg, "help")) { | |
816 | DUMP_STRING_TABLE(output_mode, OutputMode, _OUTPUT_MODE_MAX); | |
817 | return 0; | |
818 | } | |
819 | ||
820 | arg_output = output_mode_from_string(optarg); | |
821 | if (arg_output < 0) | |
822 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
823 | "Unknown output '%s'.", | |
824 | optarg); | |
825 | ||
826 | if (OUTPUT_MODE_IS_JSON(arg_output)) { | |
6906da26 | 827 | arg_legend = false; |
daf71ef6 LP |
828 | arg_plain = true; |
829 | } | |
e4b61340 LP |
830 | break; |
831 | ||
daf71ef6 | 832 | case 'i': |
4327574f FS |
833 | arg_check_inhibitors = 0; |
834 | break; | |
835 | ||
836 | case ARG_CHECK_INHIBITORS: | |
b71a721f LP |
837 | r = parse_tristate_full(optarg, "auto", &arg_check_inhibitors); |
838 | if (r < 0) | |
839 | return log_error_errno(r, "Failed to parse --check-inhibitors= argument: %s", optarg); | |
e4b61340 LP |
840 | break; |
841 | ||
daf71ef6 LP |
842 | case ARG_PLAIN: |
843 | arg_plain = true; | |
514f4ef5 LP |
844 | break; |
845 | ||
daf71ef6 LP |
846 | case ARG_FIRMWARE_SETUP: |
847 | arg_firmware_setup = true; | |
e4b61340 LP |
848 | break; |
849 | ||
daf71ef6 | 850 | case ARG_BOOT_LOADER_MENU: |
f6144808 | 851 | |
daf71ef6 LP |
852 | r = parse_sec(optarg, &arg_boot_loader_menu); |
853 | if (r < 0) | |
854 | return log_error_errno(r, "Failed to parse --boot-loader-menu= argument '%s': %m", optarg); | |
e4b61340 | 855 | |
daf71ef6 | 856 | break; |
e4b61340 | 857 | |
daf71ef6 | 858 | case ARG_BOOT_LOADER_ENTRY: |
e4b61340 | 859 | |
daf71ef6 LP |
860 | if (streq(optarg, "help")) { /* Yes, this means, "help" is not a valid boot loader entry name we can deal with */ |
861 | r = help_boot_loader_entry(); | |
862 | if (r < 0) | |
863 | return r; | |
e4b61340 | 864 | |
daf71ef6 LP |
865 | return 0; |
866 | } | |
e4b61340 | 867 | |
daf71ef6 LP |
868 | arg_boot_loader_entry = empty_to_null(optarg); |
869 | break; | |
e4b61340 | 870 | |
76e5e267 | 871 | case ARG_STATE: |
daf71ef6 LP |
872 | if (isempty(optarg)) |
873 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
874 | "--state= requires arguments."); | |
e4b61340 | 875 | |
76e5e267 | 876 | for (const char *p = optarg;;) { |
daf71ef6 | 877 | _cleanup_free_ char *s = NULL; |
e4b61340 | 878 | |
daf71ef6 LP |
879 | r = extract_first_word(&p, &s, ",", 0); |
880 | if (r < 0) | |
881 | return log_error_errno(r, "Failed to parse state: %s", optarg); | |
882 | if (r == 0) | |
883 | break; | |
e4b61340 | 884 | |
daf71ef6 LP |
885 | if (streq(s, "help")) { |
886 | help_states(); | |
887 | return 0; | |
888 | } | |
e4b61340 | 889 | |
daf71ef6 LP |
890 | if (strv_consume(&arg_states, TAKE_PTR(s)) < 0) |
891 | return log_oom(); | |
892 | } | |
893 | break; | |
e4b61340 | 894 | |
daf71ef6 LP |
895 | case 'r': |
896 | if (geteuid() != 0) | |
897 | return log_error_errno(SYNTHETIC_ERRNO(EPERM), | |
898 | "--recursive requires root privileges."); | |
899 | ||
900 | arg_recursive = true; | |
514f4ef5 LP |
901 | break; |
902 | ||
daf71ef6 LP |
903 | case ARG_PRESET_MODE: |
904 | if (streq(optarg, "help")) { | |
b364c4de | 905 | DUMP_STRING_TABLE(unit_file_preset_mode, UnitFilePresetMode, _UNIT_FILE_PRESET_MODE_MAX); |
daf71ef6 LP |
906 | return 0; |
907 | } | |
e4b61340 | 908 | |
daf71ef6 LP |
909 | arg_preset_mode = unit_file_preset_mode_from_string(optarg); |
910 | if (arg_preset_mode < 0) | |
911 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
912 | "Failed to parse preset mode: %s.", optarg); | |
e4b61340 | 913 | |
daf71ef6 | 914 | break; |
e4b61340 | 915 | |
daf71ef6 LP |
916 | case ARG_NOW: |
917 | arg_now = true; | |
918 | break; | |
e4b61340 | 919 | |
daf71ef6 LP |
920 | case ARG_MESSAGE: |
921 | if (strv_extend(&arg_wall, optarg) < 0) | |
922 | return log_oom(); | |
923 | break; | |
e4b61340 | 924 | |
daf71ef6 LP |
925 | case 'T': |
926 | arg_show_transaction = true; | |
e4b61340 LP |
927 | break; |
928 | ||
daf71ef6 LP |
929 | case ARG_WITH_DEPENDENCIES: |
930 | arg_with_dependencies = true; | |
931 | break; | |
e4b61340 | 932 | |
76e5e267 | 933 | case ARG_WHAT: |
daf71ef6 LP |
934 | if (isempty(optarg)) |
935 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--what= requires arguments."); | |
e4b61340 | 936 | |
76e5e267 | 937 | for (const char *p = optarg;;) { |
daf71ef6 | 938 | _cleanup_free_ char *k = NULL; |
e4b61340 | 939 | |
daf71ef6 LP |
940 | r = extract_first_word(&p, &k, ",", 0); |
941 | if (r < 0) | |
942 | return log_error_errno(r, "Failed to parse directory type: %s", optarg); | |
943 | if (r == 0) | |
944 | break; | |
e4b61340 | 945 | |
daf71ef6 LP |
946 | if (streq(k, "help")) { |
947 | puts("runtime\n" | |
948 | "state\n" | |
949 | "cache\n" | |
950 | "logs\n" | |
4fb8f1e8 LP |
951 | "configuration\n" |
952 | "fdstore"); | |
daf71ef6 LP |
953 | return 0; |
954 | } | |
e4b61340 | 955 | |
daf71ef6 LP |
956 | r = strv_consume(&arg_clean_what, TAKE_PTR(k)); |
957 | if (r < 0) | |
958 | return log_oom(); | |
959 | } | |
e4b61340 | 960 | |
daf71ef6 | 961 | break; |
e4b61340 | 962 | |
daf71ef6 LP |
963 | case ARG_REBOOT_ARG: |
964 | arg_reboot_argument = optarg; | |
965 | break; | |
966 | ||
967 | case ARG_TIMESTAMP_STYLE: | |
968 | if (streq(optarg, "help")) { | |
969 | DUMP_STRING_TABLE(timestamp_style, TimestampStyle, _TIMESTAMP_STYLE_MAX); | |
970 | return 0; | |
971 | } | |
972 | ||
973 | arg_timestamp_style = timestamp_style_from_string(optarg); | |
974 | if (arg_timestamp_style < 0) | |
975 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
976 | "Invalid value: %s.", optarg); | |
977 | ||
978 | break; | |
e4b61340 | 979 | |
5e8deb94 LB |
980 | case ARG_READ_ONLY: |
981 | arg_read_only = true; | |
982 | break; | |
983 | ||
984 | case ARG_MKDIR: | |
985 | arg_mkdir = true; | |
986 | break; | |
987 | ||
c9615f73 ZJS |
988 | case ARG_MARKED: |
989 | arg_marked = true; | |
990 | break; | |
991 | ||
108d35ac MY |
992 | case ARG_NO_WARN: |
993 | arg_no_warn = true; | |
994 | break; | |
995 | ||
f206809b MY |
996 | case ARG_DROP_IN: |
997 | arg_drop_in = optarg; | |
998 | break; | |
999 | ||
1433e1f9 MY |
1000 | case ARG_WHEN: |
1001 | if (streq(optarg, "show")) { | |
1002 | r = logind_show_shutdown(); | |
1003 | if (r < 0 && r != -ENODATA) | |
1004 | return r; | |
1005 | ||
1006 | return 0; | |
1007 | } | |
1008 | ||
1009 | if (STR_IN_SET(optarg, "", "cancel")) { | |
1010 | arg_when = USEC_INFINITY; | |
1011 | break; | |
1012 | } | |
1013 | ||
1014 | r = parse_timestamp(optarg, &arg_when); | |
1015 | if (r < 0) | |
1016 | return log_error_errno(r, "Failed to parse --when= argument '%s': %m", optarg); | |
1017 | ||
1018 | if (!timestamp_is_set(arg_when)) | |
1019 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1020 | "Invalid timestamp '%s' specified for --when=.", optarg); | |
1021 | ||
1022 | break; | |
1023 | ||
329050c5 ZJS |
1024 | case ARG_STDIN: |
1025 | arg_stdin = true; | |
1026 | break; | |
1027 | ||
daf71ef6 LP |
1028 | case '.': |
1029 | /* Output an error mimicking getopt, and print a hint afterwards */ | |
1030 | log_error("%s: invalid option -- '.'", program_invocation_name); | |
1031 | log_notice("Hint: to specify units starting with a dash, use \"--\":\n" | |
1032 | " %s [OPTIONS...] COMMAND -- -.%s ...", | |
1033 | program_invocation_name, optarg ?: "mount"); | |
1034 | _fallthrough_; | |
e4b61340 LP |
1035 | |
1036 | case '?': | |
1037 | return -EINVAL; | |
1038 | ||
1039 | default: | |
04499a70 | 1040 | assert_not_reached(); |
e4b61340 | 1041 | } |
e4b61340 | 1042 | |
966f3a24 LP |
1043 | /* If we are in --user mode, there's no point in talking to PolicyKit or the infra to query system |
1044 | * passwords */ | |
4870133b | 1045 | if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) |
966f3a24 LP |
1046 | arg_ask_password = false; |
1047 | ||
4870133b | 1048 | if (arg_transport == BUS_TRANSPORT_REMOTE && arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) |
daf71ef6 LP |
1049 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
1050 | "Cannot access user instance remotely."); | |
1051 | ||
1052 | if (arg_wait && arg_no_block) | |
baaa35ad | 1053 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
daf71ef6 | 1054 | "--wait may not be combined with --no-block."); |
e4b61340 | 1055 | |
c9615f73 ZJS |
1056 | bool do_reload_or_restart = streq_ptr(argv[optind], "reload-or-restart"); |
1057 | if (arg_marked) { | |
1058 | if (!do_reload_or_restart) | |
1059 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1060 | "--marked may only be used with 'reload-or-restart'."); | |
1061 | if (optind + 1 < argc) | |
1062 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1063 | "No additional arguments allowed with 'reload-or-restart --marked'."); | |
1064 | if (arg_wait) | |
1065 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1066 | "--marked --wait is not supported."); | |
1067 | if (arg_show_transaction) | |
1068 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1069 | "--marked --show-transaction is not supported."); | |
1070 | ||
1071 | } else if (do_reload_or_restart) { | |
1072 | if (optind + 1 >= argc) | |
1073 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
1074 | "List of units to restart/reload is required."); | |
1075 | } | |
1076 | ||
8aa3894e | 1077 | if (arg_image && arg_root) |
329050c5 ZJS |
1078 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
1079 | "Please specify either --root= or --image=, the combination of both is not supported."); | |
8aa3894e | 1080 | |
e4b61340 LP |
1081 | return 1; |
1082 | } | |
1083 | ||
5fd87823 | 1084 | int systemctl_dispatch_parse_argv(int argc, char *argv[]) { |
e4b61340 LP |
1085 | assert(argc >= 0); |
1086 | assert(argv); | |
1087 | ||
2306d177 | 1088 | if (invoked_as(argv, "halt")) { |
d41a9e4f ZJS |
1089 | arg_action = ACTION_HALT; |
1090 | return halt_parse_argv(argc, argv); | |
1091 | ||
2306d177 | 1092 | } else if (invoked_as(argv, "poweroff")) { |
d41a9e4f ZJS |
1093 | arg_action = ACTION_POWEROFF; |
1094 | return halt_parse_argv(argc, argv); | |
1095 | ||
2306d177 | 1096 | } else if (invoked_as(argv, "reboot")) { |
665a3d6d | 1097 | arg_action = ACTION_REBOOT; |
d41a9e4f ZJS |
1098 | return halt_parse_argv(argc, argv); |
1099 | ||
2306d177 | 1100 | } else if (invoked_as(argv, "shutdown")) { |
d41a9e4f ZJS |
1101 | arg_action = ACTION_POWEROFF; |
1102 | return shutdown_parse_argv(argc, argv); | |
1103 | ||
2306d177 | 1104 | } else if (invoked_as(argv, "init")) { |
d41a9e4f ZJS |
1105 | |
1106 | /* Matches invocations as "init" as well as "telinit", which are synonymous when run | |
1107 | * as PID != 1 on SysV. | |
1108 | * | |
1109 | * On SysV "telinit" was the official command to communicate with PID 1, but "init" would | |
1110 | * redirect itself to "telinit" if called with PID != 1. We follow the same logic here still, | |
1111 | * though we add one level of indirection, as we implement "telinit" in "systemctl". Hence, | |
1112 | * for us if you invoke "init" you get "systemd", but it will execve() "systemctl" | |
1113 | * immediately with argv[] unmodified if PID is != 1. If you invoke "telinit" you directly | |
1114 | * get "systemctl". In both cases we shall do the same thing, which is why we do | |
2306d177 | 1115 | * invoked_as(argv, "init") here, as a quick way to match both. |
d41a9e4f ZJS |
1116 | * |
1117 | * Also see redirect_telinit() in src/core/main.c. */ | |
1118 | ||
1119 | if (sd_booted() > 0) { | |
1120 | arg_action = _ACTION_INVALID; | |
1121 | return telinit_parse_argv(argc, argv); | |
1122 | } else { | |
1123 | /* Hmm, so some other init system is running, we need to forward this request to it. | |
1124 | */ | |
1125 | arg_action = ACTION_TELINIT; | |
1126 | return 1; | |
e4b61340 | 1127 | } |
d41a9e4f | 1128 | |
2306d177 | 1129 | } else if (invoked_as(argv, "runlevel")) { |
d41a9e4f ZJS |
1130 | arg_action = ACTION_RUNLEVEL; |
1131 | return runlevel_parse_argv(argc, argv); | |
e4b61340 LP |
1132 | } |
1133 | ||
1134 | arg_action = ACTION_SYSTEMCTL; | |
1135 | return systemctl_parse_argv(argc, argv); | |
1136 | } | |
1137 | ||
5fd87823 | 1138 | #ifndef FUZZ_SYSTEMCTL_PARSE_ARGV |
e449de87 | 1139 | static int systemctl_main(int argc, char *argv[]) { |
e449de87 | 1140 | static const Verb verbs[] = { |
32baf64d LP |
1141 | { "list-units", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, verb_list_units }, |
1142 | { "list-unit-files", VERB_ANY, VERB_ANY, 0, verb_list_unit_files }, | |
ed462ea3 | 1143 | { "list-automounts", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_automounts }, |
5fb5f49b | 1144 | { "list-paths", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_paths }, |
32baf64d LP |
1145 | { "list-sockets", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_sockets }, |
1146 | { "list-timers", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_timers }, | |
1147 | { "list-jobs", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_jobs }, | |
1148 | { "list-machines", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_machines }, | |
1149 | { "clear-jobs", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_trivial_method }, | |
1150 | { "cancel", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_cancel }, | |
1151 | { "start", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1152 | { "stop", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1153 | { "condstop", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with ALTLinux */ | |
1154 | { "reload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1155 | { "restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1156 | { "try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1157 | { "reload-or-restart", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1158 | { "reload-or-try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with old systemctl <= 228 */ | |
1159 | { "try-reload-or-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, | |
1160 | { "force-reload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with SysV */ | |
1161 | { "condreload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with ALTLinux */ | |
1162 | { "condrestart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with RH */ | |
1163 | { "isolate", 2, 2, VERB_ONLINE_ONLY, verb_start }, | |
1164 | { "kill", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_kill }, | |
1165 | { "clean", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, | |
1166 | { "freeze", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, | |
1167 | { "thaw", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, | |
1168 | { "is-active", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_is_active }, | |
1169 | { "check", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_is_active }, /* deprecated alias of is-active */ | |
2ee34616 | 1170 | { "is-failed", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_is_failed }, |
32baf64d LP |
1171 | { "show", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, |
1172 | { "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_cat }, | |
1173 | { "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, | |
1174 | { "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, | |
623461c1 LP |
1175 | { "daemon-reload", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, |
1176 | { "daemon-reexec", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, | |
32baf64d LP |
1177 | { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, |
1178 | { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, | |
1179 | { "service-log-level", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting }, | |
1180 | { "service-log-target", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting }, | |
1181 | { "service-watchdogs", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_service_watchdogs }, | |
1182 | { "show-environment", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_show_environment }, | |
1183 | { "set-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_set_environment }, | |
1184 | { "unset-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_set_environment }, | |
1185 | { "import-environment", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_import_environment }, | |
1186 | { "halt", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1187 | { "poweroff", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
31853609 | 1188 | { "reboot", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, |
32baf64d | 1189 | { "kexec", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, |
34f21ff6 | 1190 | { "soft-reboot", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, |
32baf64d LP |
1191 | { "suspend", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, |
1192 | { "hibernate", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1193 | { "hybrid-sleep", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1194 | { "suspend-then-hibernate",VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1195 | { "default", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_special }, | |
1196 | { "rescue", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1197 | { "emergency", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, | |
1198 | { "exit", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_start_special }, | |
1199 | { "reset-failed", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_reset_failed }, | |
1200 | { "enable", 2, VERB_ANY, 0, verb_enable }, | |
1201 | { "disable", 2, VERB_ANY, 0, verb_enable }, | |
1202 | { "is-enabled", 2, VERB_ANY, 0, verb_is_enabled }, | |
1203 | { "reenable", 2, VERB_ANY, 0, verb_enable }, | |
1204 | { "preset", 2, VERB_ANY, 0, verb_enable }, | |
1205 | { "preset-all", VERB_ANY, 1, 0, verb_preset_all }, | |
1206 | { "mask", 2, VERB_ANY, 0, verb_enable }, | |
1207 | { "unmask", 2, VERB_ANY, 0, verb_enable }, | |
1208 | { "link", 2, VERB_ANY, 0, verb_enable }, | |
1209 | { "revert", 2, VERB_ANY, 0, verb_enable }, | |
5ae89ef3 | 1210 | { "switch-root", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_switch_root }, |
32baf64d LP |
1211 | { "list-dependencies", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_dependencies }, |
1212 | { "set-default", 2, 2, 0, verb_set_default }, | |
1213 | { "get-default", VERB_ANY, 1, 0, verb_get_default }, | |
1214 | { "set-property", 3, VERB_ANY, VERB_ONLINE_ONLY, verb_set_property }, | |
1215 | { "is-system-running", VERB_ANY, 1, 0, verb_is_system_running }, | |
1216 | { "add-wants", 3, VERB_ANY, 0, verb_add_dependency }, | |
1217 | { "add-requires", 3, VERB_ANY, 0, verb_add_dependency }, | |
1218 | { "edit", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_edit }, | |
1219 | { "bind", 3, 4, VERB_ONLINE_ONLY, verb_bind }, | |
1220 | { "mount-image", 4, 5, VERB_ONLINE_ONLY, verb_mount_image }, | |
c86a9508 | 1221 | { "whoami", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_whoami }, |
d08e75ed | 1222 | {} |
e449de87 | 1223 | }; |
7e4249b9 | 1224 | |
4cb1015e ZJS |
1225 | const Verb *verb = verbs_find_verb(argv[optind], verbs); |
1226 | if (verb && (verb->flags & VERB_ONLINE_ONLY) && arg_root) | |
1227 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
8aa3894e | 1228 | "Verb '%s' cannot be used with --root= or --image=.", |
4cb1015e ZJS |
1229 | argv[optind] ?: verb->verb); |
1230 | ||
e449de87 | 1231 | return dispatch_verb(argc, argv, verbs, NULL); |
e4b61340 LP |
1232 | } |
1233 | ||
f2a3de01 | 1234 | static int run(int argc, char *argv[]) { |
8aa3894e | 1235 | _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL; |
a4b3e942 | 1236 | _cleanup_(umount_and_freep) char *mounted_dir = NULL; |
f459b602 | 1237 | int r; |
e4b61340 | 1238 | |
a9cdc94f | 1239 | setlocale(LC_ALL, ""); |
158fdd53 | 1240 | log_setup(); |
1abaf488 LP |
1241 | |
1242 | /* The journal merging logic potentially needs a lot of fds. */ | |
1243 | (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); | |
1244 | ||
592705f2 | 1245 | sigbus_install(); |
e4b61340 | 1246 | |
5fd87823 | 1247 | r = systemctl_dispatch_parse_argv(argc, argv); |
f459b602 | 1248 | if (r <= 0) |
e4b61340 | 1249 | goto finish; |
7e4249b9 | 1250 | |
0f958c8d | 1251 | if (proc_mounted() == 0) |
91dfb74e YW |
1252 | log_full(arg_no_warn ? LOG_DEBUG : LOG_WARNING, |
1253 | "%s%s/proc/ is not mounted. This is not a supported mode of operation. Please fix\n" | |
1254 | "your invocation environment to mount /proc/ and /sys/ properly. Proceeding anyway.\n" | |
1255 | "Your mileage may vary.", | |
1256 | emoji_enabled() ? special_glyph(SPECIAL_GLYPH_WARNING_SIGN) : "", | |
1257 | emoji_enabled() ? " " : ""); | |
0f958c8d | 1258 | |
040524b4 | 1259 | if (arg_action != ACTION_SYSTEMCTL && running_in_chroot() > 0) { |
60675884 LP |
1260 | if (!arg_quiet) |
1261 | log_info("Running in chroot, ignoring request."); | |
f459b602 | 1262 | r = 0; |
82e23ddd LP |
1263 | goto finish; |
1264 | } | |
1265 | ||
daf71ef6 | 1266 | /* systemctl_main() will print an error message for the bus connection, but only if it needs to */ |
e4b61340 | 1267 | |
8aa3894e RP |
1268 | if (arg_image) { |
1269 | assert(!arg_root); | |
1270 | ||
1271 | r = mount_image_privately_interactively( | |
1272 | arg_image, | |
84be0c71 | 1273 | arg_image_policy, |
8aa3894e RP |
1274 | DISSECT_IMAGE_GENERIC_ROOT | |
1275 | DISSECT_IMAGE_REQUIRE_ROOT | | |
1276 | DISSECT_IMAGE_RELAX_VAR_CHECK | | |
1277 | DISSECT_IMAGE_VALIDATE_OS, | |
1278 | &mounted_dir, | |
a133d2c3 | 1279 | /* ret_dir_fd= */ NULL, |
8aa3894e RP |
1280 | &loop_device); |
1281 | if (r < 0) | |
1282 | return r; | |
1283 | ||
1284 | arg_root = strdup(mounted_dir); | |
1285 | if (!arg_root) | |
1286 | return log_oom(); | |
1287 | } | |
1288 | ||
e4b61340 LP |
1289 | switch (arg_action) { |
1290 | ||
22f4096c | 1291 | case ACTION_SYSTEMCTL: |
e449de87 | 1292 | r = systemctl_main(argc, argv); |
e4b61340 | 1293 | break; |
e4b61340 | 1294 | |
daf71ef6 LP |
1295 | /* Legacy command aliases set arg_action. They provide some fallbacks, e.g. to tell sysvinit to |
1296 | * reboot after you have installed systemd binaries. */ | |
081dc638 | 1297 | |
e4b61340 LP |
1298 | case ACTION_HALT: |
1299 | case ACTION_POWEROFF: | |
1300 | case ACTION_REBOOT: | |
5622dde3 | 1301 | case ACTION_KEXEC: |
4fbd7192 | 1302 | r = halt_main(); |
e4b61340 LP |
1303 | break; |
1304 | ||
e4b61340 LP |
1305 | case ACTION_RUNLEVEL2: |
1306 | case ACTION_RUNLEVEL3: | |
1307 | case ACTION_RUNLEVEL4: | |
1308 | case ACTION_RUNLEVEL5: | |
1309 | case ACTION_RESCUE: | |
4fbd7192 | 1310 | r = start_with_fallback(); |
e4b61340 | 1311 | break; |
7e4249b9 | 1312 | |
e4b61340 LP |
1313 | case ACTION_RELOAD: |
1314 | case ACTION_REEXEC: | |
4fbd7192 | 1315 | r = reload_with_fallback(); |
e4b61340 LP |
1316 | break; |
1317 | ||
949d9ce9 | 1318 | case ACTION_CANCEL_SHUTDOWN: |
2cf05793 | 1319 | r = logind_cancel_shutdown(); |
f6144808 LP |
1320 | break; |
1321 | ||
a9c3cc8d LN |
1322 | case ACTION_SHOW_SHUTDOWN: |
1323 | r = logind_show_shutdown(); | |
1324 | break; | |
1325 | ||
eb22ac37 | 1326 | case ACTION_RUNLEVEL: |
4f16c1f4 LP |
1327 | r = runlevel_main(); |
1328 | break; | |
1329 | ||
ea71b460 ZJS |
1330 | case ACTION_TELINIT: |
1331 | r = exec_telinit(argv); | |
1332 | break; | |
1333 | ||
081dc638 AJ |
1334 | case ACTION_EXIT: |
1335 | case ACTION_SUSPEND: | |
1336 | case ACTION_HIBERNATE: | |
1337 | case ACTION_HYBRID_SLEEP: | |
e68c79db | 1338 | case ACTION_SUSPEND_THEN_HIBERNATE: |
081dc638 AJ |
1339 | case ACTION_EMERGENCY: |
1340 | case ACTION_DEFAULT: | |
36556f6e ZJS |
1341 | /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in |
1342 | * arg_action. Fall through. */ | |
081dc638 | 1343 | |
f459b602 | 1344 | case _ACTION_INVALID: |
e4b61340 | 1345 | default: |
04499a70 | 1346 | assert_not_reached(); |
e4b61340 | 1347 | } |
7e4249b9 LP |
1348 | |
1349 | finish: | |
cf647b69 LP |
1350 | release_busses(); |
1351 | ||
d1405af3 ZJS |
1352 | /* Note that we return r here, not 0, so that we can implement the LSB-like return codes */ |
1353 | return r; | |
7e4249b9 | 1354 | } |
d1405af3 ZJS |
1355 | |
1356 | DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); | |
5fd87823 | 1357 | #endif |