| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <signal.h> |
| 4 |
#include <unistd.h> |
| 5 |
|
| 6 |
#include "argv-util.h" |
| 7 |
#include "build.h" |
| 8 |
#include "bus-print-properties.h" |
| 9 |
#include "bus-util.h" |
| 10 |
#include "capsule-util.h" |
| 11 |
#include "extract-word.h" |
| 12 |
#include "format-table.h" |
| 13 |
#include "help-util.h" |
| 14 |
#include "image-policy.h" |
| 15 |
#include "install.h" |
| 16 |
#include "options.h" |
| 17 |
#include "output-mode.h" |
| 18 |
#include "pager.h" |
| 19 |
#include "parse-argument.h" |
| 20 |
#include "parse-util.h" |
| 21 |
#include "path-util.h" |
| 22 |
#include "static-destruct.h" |
| 23 |
#include "string-table.h" |
| 24 |
#include "string-util.h" |
| 25 |
#include "strv.h" |
| 26 |
#include "systemctl.h" |
| 27 |
#include "systemctl-compat-halt.h" |
| 28 |
#include "systemctl-compat-shutdown.h" |
| 29 |
#include "systemctl-logind.h" |
| 30 |
#include "time-util.h" |
| 31 |
#include "verbs.h" |
| 32 |
|
| 33 |
char **arg_types = NULL; |
| 34 |
char **arg_states = NULL; |
| 35 |
char **arg_properties = NULL; |
| 36 |
bool arg_all = false; |
| 37 |
enum dependency arg_dependency = DEPENDENCY_FORWARD; |
| 38 |
const char *_arg_job_mode = NULL; |
| 39 |
RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; |
| 40 |
bool arg_wait = false; |
| 41 |
bool arg_no_block = false; |
| 42 |
int arg_legend = -1; /* -1: true, unless --quiet is passed, 1: true */ |
| 43 |
PagerFlags arg_pager_flags = 0; |
| 44 |
bool arg_no_wtmp = false; |
| 45 |
bool arg_no_sync = false; |
| 46 |
bool arg_no_wall = false; |
| 47 |
bool arg_no_reload = false; |
| 48 |
BusPrintPropertyFlags arg_print_flags = 0; |
| 49 |
bool arg_show_types = false; |
| 50 |
int arg_check_inhibitors = -1; |
| 51 |
bool arg_dry_run = false; |
| 52 |
bool arg_quiet = false; |
| 53 |
bool arg_verbose = false; |
| 54 |
bool arg_no_warn = false; |
| 55 |
bool arg_full = false; |
| 56 |
bool arg_recursive = false; |
| 57 |
bool arg_with_dependencies = false; |
| 58 |
bool arg_show_transaction = false; |
| 59 |
int arg_force = 0; |
| 60 |
bool arg_ask_password = false; |
| 61 |
bool arg_runtime = false; |
| 62 |
UnitFilePresetMode arg_preset_mode = UNIT_FILE_PRESET_FULL; |
| 63 |
char **arg_wall = NULL; |
| 64 |
const char *arg_kill_whom = NULL; |
| 65 |
int arg_signal = SIGTERM; |
| 66 |
int arg_kill_value; |
| 67 |
bool arg_kill_value_set = false; |
| 68 |
char *arg_root = NULL; |
| 69 |
char *arg_image = NULL; |
| 70 |
usec_t arg_when = 0; |
| 71 |
bool arg_stdin = false; |
| 72 |
const char *arg_reboot_argument = NULL; |
| 73 |
char *arg_kernel_cmdline = NULL; |
| 74 |
enum action arg_action = ACTION_SYSTEMCTL; |
| 75 |
BusTransport arg_transport = BUS_TRANSPORT_LOCAL; |
| 76 |
const char *arg_host = NULL; |
| 77 |
unsigned arg_lines = 10; |
| 78 |
OutputMode arg_output = OUTPUT_SHORT; |
| 79 |
bool arg_plain = false; |
| 80 |
bool arg_firmware_setup = false; |
| 81 |
usec_t arg_boot_loader_menu = USEC_INFINITY; |
| 82 |
const char *arg_boot_loader_entry = NULL; |
| 83 |
bool arg_now = false; |
| 84 |
bool arg_jobs_before = false; |
| 85 |
bool arg_jobs_after = false; |
| 86 |
char **arg_clean_what = NULL; |
| 87 |
TimestampStyle arg_timestamp_style = TIMESTAMP_PRETTY; |
| 88 |
bool arg_read_only = false; |
| 89 |
bool arg_mkdir = false; |
| 90 |
bool arg_marked = false; |
| 91 |
const char *arg_drop_in = NULL; |
| 92 |
ImagePolicy *arg_image_policy = NULL; |
| 93 |
char *arg_kill_subgroup = NULL; |
| 94 |
|
| 95 |
STATIC_DESTRUCTOR_REGISTER(arg_types, strv_freep); |
| 96 |
STATIC_DESTRUCTOR_REGISTER(arg_states, strv_freep); |
| 97 |
STATIC_DESTRUCTOR_REGISTER(arg_properties, strv_freep); |
| 98 |
STATIC_DESTRUCTOR_REGISTER(_arg_job_mode, unsetp); |
| 99 |
STATIC_DESTRUCTOR_REGISTER(arg_wall, strv_freep); |
| 100 |
STATIC_DESTRUCTOR_REGISTER(arg_kill_whom, unsetp); |
| 101 |
STATIC_DESTRUCTOR_REGISTER(arg_root, freep); |
| 102 |
STATIC_DESTRUCTOR_REGISTER(arg_image, freep); |
| 103 |
STATIC_DESTRUCTOR_REGISTER(arg_reboot_argument, unsetp); |
| 104 |
STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline, freep); |
| 105 |
STATIC_DESTRUCTOR_REGISTER(arg_host, unsetp); |
| 106 |
STATIC_DESTRUCTOR_REGISTER(arg_boot_loader_entry, unsetp); |
| 107 |
STATIC_DESTRUCTOR_REGISTER(arg_clean_what, strv_freep); |
| 108 |
STATIC_DESTRUCTOR_REGISTER(arg_drop_in, unsetp); |
| 109 |
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); |
| 110 |
STATIC_DESTRUCTOR_REGISTER(arg_kill_subgroup, freep); |
| 111 |
|
| 112 |
static int systemctl_help(void) { |
| 113 |
static const char *const vgroups[] = { |
| 114 |
"Unit Commands", |
| 115 |
"Unit File Commands", |
| 116 |
"Machine Commands", |
| 117 |
"Job Commands", |
| 118 |
"Environment Commands", |
| 119 |
"Manager State Commands", |
| 120 |
"System Commands", |
| 121 |
}; |
| 122 |
|
| 123 |
Table *vtables[ELEMENTSOF(vgroups)] = {}; |
| 124 |
CLEANUP_ELEMENTS(vtables, table_unref_array_clear); |
| 125 |
_cleanup_(table_unrefp) Table *options_table = NULL; |
| 126 |
int r; |
| 127 |
|
| 128 |
for (size_t i = 0; i < ELEMENTSOF(vgroups); i++) { |
| 129 |
r = verbs_get_help_table_group(vgroups[i], &vtables[i]); |
| 130 |
if (r < 0) |
| 131 |
return r; |
| 132 |
} |
| 133 |
|
| 134 |
r = option_parser_get_help_table_ns("systemctl", &options_table); |
| 135 |
if (r < 0) |
| 136 |
return r; |
| 137 |
|
| 138 |
assert_cc(ELEMENTSOF(vtables) == 7); |
| 139 |
(void) table_sync_column_widths(0, options_table, |
| 140 |
vtables[0], vtables[1], vtables[2], vtables[3], |
| 141 |
vtables[4], vtables[5], vtables[6]); |
| 142 |
|
| 143 |
pager_open(arg_pager_flags); |
| 144 |
|
| 145 |
help_cmdline("[OPTIONS…] COMMAND …"); |
| 146 |
help_abstract("Query or send control commands to the system manager."); |
| 147 |
|
| 148 |
for (size_t i = 0; i < ELEMENTSOF(vgroups); i++) { |
| 149 |
help_section(vgroups[i]); |
| 150 |
r = table_print_or_warn(vtables[i]); |
| 151 |
if (r < 0) |
| 152 |
return r; |
| 153 |
} |
| 154 |
|
| 155 |
help_section("Options"); |
| 156 |
r = table_print_or_warn(options_table); |
| 157 |
if (r < 0) |
| 158 |
return r; |
| 159 |
|
| 160 |
help_man_page_reference("systemctl", "1"); |
| 161 |
|
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
static int parse_property_argument(const char *value, char ***properties) { |
| 166 |
int r; |
| 167 |
|
| 168 |
assert(value); |
| 169 |
assert(properties); |
| 170 |
|
| 171 |
if (isempty(value) && !*properties) { |
| 172 |
/* Make sure that if the empty property list was specified, we won't show any properties. */ |
| 173 |
*properties = strv_new(NULL); |
| 174 |
if (!*properties) |
| 175 |
return log_oom(); |
| 176 |
} else |
| 177 |
for (const char *p = value;;) { |
| 178 |
_cleanup_free_ char *prop = NULL; |
| 179 |
|
| 180 |
r = extract_first_word(&p, &prop, ",", /* flags= */ 0); |
| 181 |
if (r < 0) |
| 182 |
return log_error_errno(r, "Failed to parse property: '%s'", value); |
| 183 |
if (r == 0) |
| 184 |
break; |
| 185 |
|
| 186 |
if (strv_consume(properties, TAKE_PTR(prop)) < 0) |
| 187 |
return log_oom(); |
| 188 |
} |
| 189 |
|
| 190 |
return 0; |
| 191 |
} |
| 192 |
|
| 193 |
static int help_states(void) { |
| 194 |
if (arg_legend != 0) |
| 195 |
puts("Available unit load states:"); |
| 196 |
DUMP_STRING_TABLE(unit_load_state, UnitLoadState, _UNIT_LOAD_STATE_MAX); |
| 197 |
|
| 198 |
if (arg_legend != 0) |
| 199 |
puts("\nAvailable unit active states:"); |
| 200 |
DUMP_STRING_TABLE(unit_active_state, UnitActiveState, _UNIT_ACTIVE_STATE_MAX); |
| 201 |
|
| 202 |
if (arg_legend != 0) |
| 203 |
puts("\nAvailable unit file states:"); |
| 204 |
DUMP_STRING_TABLE(unit_file_state, UnitFileState, _UNIT_FILE_STATE_MAX); |
| 205 |
|
| 206 |
if (arg_legend != 0) |
| 207 |
puts("\nAvailable automount unit substates:"); |
| 208 |
DUMP_STRING_TABLE(automount_state, AutomountState, _AUTOMOUNT_STATE_MAX); |
| 209 |
|
| 210 |
if (arg_legend != 0) |
| 211 |
puts("\nAvailable device unit substates:"); |
| 212 |
DUMP_STRING_TABLE(device_state, DeviceState, _DEVICE_STATE_MAX); |
| 213 |
|
| 214 |
if (arg_legend != 0) |
| 215 |
puts("\nAvailable mount unit substates:"); |
| 216 |
DUMP_STRING_TABLE(mount_state, MountState, _MOUNT_STATE_MAX); |
| 217 |
|
| 218 |
if (arg_legend != 0) |
| 219 |
puts("\nAvailable path unit substates:"); |
| 220 |
DUMP_STRING_TABLE(path_state, PathState, _PATH_STATE_MAX); |
| 221 |
|
| 222 |
if (arg_legend != 0) |
| 223 |
puts("\nAvailable scope unit substates:"); |
| 224 |
DUMP_STRING_TABLE(scope_state, ScopeState, _SCOPE_STATE_MAX); |
| 225 |
|
| 226 |
if (arg_legend != 0) |
| 227 |
puts("\nAvailable service unit substates:"); |
| 228 |
DUMP_STRING_TABLE(service_state, ServiceState, _SERVICE_STATE_MAX); |
| 229 |
|
| 230 |
if (arg_legend != 0) |
| 231 |
puts("\nAvailable slice unit substates:"); |
| 232 |
DUMP_STRING_TABLE(slice_state, SliceState, _SLICE_STATE_MAX); |
| 233 |
|
| 234 |
if (arg_legend != 0) |
| 235 |
puts("\nAvailable socket unit substates:"); |
| 236 |
DUMP_STRING_TABLE(socket_state, SocketState, _SOCKET_STATE_MAX); |
| 237 |
|
| 238 |
if (arg_legend != 0) |
| 239 |
puts("\nAvailable swap unit substates:"); |
| 240 |
DUMP_STRING_TABLE(swap_state, SwapState, _SWAP_STATE_MAX); |
| 241 |
|
| 242 |
if (arg_legend != 0) |
| 243 |
puts("\nAvailable target unit substates:"); |
| 244 |
DUMP_STRING_TABLE(target_state, TargetState, _TARGET_STATE_MAX); |
| 245 |
|
| 246 |
if (arg_legend != 0) |
| 247 |
puts("\nAvailable timer unit substates:"); |
| 248 |
return DUMP_STRING_TABLE(timer_state, TimerState, _TIMER_STATE_MAX); |
| 249 |
} |
| 250 |
|
| 251 |
static int parse_states_argument(const char *value, char ***states) { |
| 252 |
int r; |
| 253 |
|
| 254 |
assert(value); |
| 255 |
assert(states); |
| 256 |
|
| 257 |
if (isempty(value)) { |
| 258 |
/* reset the setting */ |
| 259 |
*states = strv_free(*states); |
| 260 |
return 1; |
| 261 |
} |
| 262 |
|
| 263 |
for (const char *p = value;;) { |
| 264 |
_cleanup_free_ char *s = NULL; |
| 265 |
|
| 266 |
r = extract_first_word(&p, &s, ",", /* flags= */ 0); |
| 267 |
if (r < 0) |
| 268 |
return log_error_errno(r, "Failed to parse --state=: %m"); |
| 269 |
if (r == 0) |
| 270 |
break; |
| 271 |
|
| 272 |
if (streq(s, "help")) |
| 273 |
return help_states(); |
| 274 |
|
| 275 |
if (strv_consume(states, TAKE_PTR(s)) < 0) |
| 276 |
return log_oom(); |
| 277 |
} |
| 278 |
|
| 279 |
return 1; |
| 280 |
} |
| 281 |
|
| 282 |
static int help_types(void) { |
| 283 |
if (arg_legend != 0) |
| 284 |
puts("Available unit types:"); |
| 285 |
|
| 286 |
return DUMP_STRING_TABLE(unit_type, UnitType, _UNIT_TYPE_MAX); |
| 287 |
} |
| 288 |
|
| 289 |
static int parse_types_argument(const char *value, char ***types, char ***states) { |
| 290 |
int r; |
| 291 |
|
| 292 |
assert(value); |
| 293 |
assert(types); |
| 294 |
assert(states); |
| 295 |
|
| 296 |
if (isempty(value)) { |
| 297 |
/* reset the setting */ |
| 298 |
*types = strv_free(*types); |
| 299 |
return 1; |
| 300 |
} |
| 301 |
|
| 302 |
for (const char *p = value;;) { |
| 303 |
_cleanup_free_ char *type = NULL; |
| 304 |
|
| 305 |
r = extract_first_word(&p, &type, ",", /* flags= */ 0); |
| 306 |
if (r < 0) |
| 307 |
return log_error_errno(r, "Failed to parse -t/--type=: %m"); |
| 308 |
if (r == 0) |
| 309 |
break; |
| 310 |
|
| 311 |
if (streq(type, "help")) |
| 312 |
return help_types(); |
| 313 |
|
| 314 |
if (unit_type_from_string(type) >= 0) { |
| 315 |
if (strv_consume(types, TAKE_PTR(type)) < 0) |
| 316 |
return log_oom(); |
| 317 |
continue; |
| 318 |
} |
| 319 |
|
| 320 |
/* It's much nicer to use --state= for load states, but let's support this in |
| 321 |
* --types= too for compatibility with old versions */ |
| 322 |
if (unit_load_state_from_string(type) >= 0) { |
| 323 |
if (strv_consume(states, TAKE_PTR(type)) < 0) |
| 324 |
return log_oom(); |
| 325 |
continue; |
| 326 |
} |
| 327 |
|
| 328 |
log_error("Unknown unit type or load state '%s'.", type); |
| 329 |
return log_info_errno(SYNTHETIC_ERRNO(EINVAL), |
| 330 |
"Use -t help to see a list of allowed values."); |
| 331 |
} |
| 332 |
|
| 333 |
return 1; |
| 334 |
} |
| 335 |
|
| 336 |
static int parse_what_argument(const char *value, char ***clean_what) { |
| 337 |
int r; |
| 338 |
|
| 339 |
assert(value); |
| 340 |
assert(clean_what); |
| 341 |
|
| 342 |
if (isempty(value)) { |
| 343 |
/* reset the setting */ |
| 344 |
*clean_what = strv_free(*clean_what); |
| 345 |
return 1; |
| 346 |
} |
| 347 |
|
| 348 |
for (const char *p = value;;) { |
| 349 |
_cleanup_free_ char *k = NULL; |
| 350 |
|
| 351 |
r = extract_first_word(&p, &k, ",", /* flags= */ 0); |
| 352 |
if (r < 0) |
| 353 |
return log_error_errno(r, "Failed to parse --what=: %m"); |
| 354 |
if (r == 0) |
| 355 |
break; |
| 356 |
|
| 357 |
if (streq(k, "help")) { |
| 358 |
puts("runtime\n" |
| 359 |
"state\n" |
| 360 |
"cache\n" |
| 361 |
"logs\n" |
| 362 |
"configuration\n" |
| 363 |
"fdstore\n" |
| 364 |
"all"); |
| 365 |
return 0; |
| 366 |
} |
| 367 |
|
| 368 |
r = strv_consume(clean_what, TAKE_PTR(k)); |
| 369 |
if (r < 0) |
| 370 |
return log_oom(); |
| 371 |
} |
| 372 |
|
| 373 |
return 1; |
| 374 |
} |
| 375 |
|
| 376 |
static int systemctl_parse_argv(int argc, char *argv[], int log_level_shift, char ***remaining_args) { |
| 377 |
int r; |
| 378 |
|
| 379 |
assert(argc >= 0); |
| 380 |
assert(argv); |
| 381 |
|
| 382 |
/* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */ |
| 383 |
arg_ask_password = true; |
| 384 |
|
| 385 |
OptionParser opts = { |
| 386 |
argc, argv, |
| 387 |
.namespace = "systemctl", |
| 388 |
.log_level_shift = log_level_shift, |
| 389 |
}; |
| 390 |
|
| 391 |
FOREACH_OPTION_OR_RETURN(c, &opts) |
| 392 |
switch (c) { |
| 393 |
|
| 394 |
OPTION_NAMESPACE("systemctl"): {} |
| 395 |
|
| 396 |
OPTION_COMMON_HELP: |
| 397 |
return systemctl_help(); |
| 398 |
|
| 399 |
OPTION_COMMON_VERSION: |
| 400 |
return version(); |
| 401 |
|
| 402 |
OPTION_LONG("system", NULL, "Connect to the system service manager"): |
| 403 |
arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; |
| 404 |
break; |
| 405 |
|
| 406 |
OPTION_LONG("user", NULL, "Connect to the user service manager"): |
| 407 |
arg_runtime_scope = RUNTIME_SCOPE_USER; |
| 408 |
break; |
| 409 |
|
| 410 |
OPTION('C', "capsule", "NAME", "Connect to service manager of specified capsule"): |
| 411 |
r = capsule_name_is_valid(opts.arg); |
| 412 |
if (r < 0) |
| 413 |
return log_error_errno(r, "Unable to validate capsule name '%s': %m", opts.arg); |
| 414 |
if (r == 0) |
| 415 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid capsule name: %s", opts.arg); |
| 416 |
|
| 417 |
arg_host = opts.arg; |
| 418 |
arg_transport = BUS_TRANSPORT_CAPSULE; |
| 419 |
arg_runtime_scope = RUNTIME_SCOPE_USER; |
| 420 |
break; |
| 421 |
|
| 422 |
OPTION_COMMON_HOST: |
| 423 |
arg_transport = BUS_TRANSPORT_REMOTE; |
| 424 |
arg_host = opts.arg; |
| 425 |
break; |
| 426 |
|
| 427 |
OPTION_COMMON_MACHINE: |
| 428 |
r = parse_machine_argument(opts.arg, &arg_host, &arg_transport); |
| 429 |
if (r < 0) |
| 430 |
return r; |
| 431 |
break; |
| 432 |
|
| 433 |
OPTION('t', "type", "TYPE", "List units of a particular type"): |
| 434 |
r = parse_types_argument(opts.arg, &arg_types, &arg_states); |
| 435 |
if (r <= 0) |
| 436 |
return r; |
| 437 |
break; |
| 438 |
|
| 439 |
OPTION_LONG("state", "STATE", "List units with particular LOAD or SUB or ACTIVE state"): |
| 440 |
r = parse_states_argument(opts.arg, &arg_states); |
| 441 |
if (r <= 0) |
| 442 |
return r; |
| 443 |
break; |
| 444 |
|
| 445 |
OPTION_LONG("failed", NULL, "Shortcut for --state=failed"): |
| 446 |
if (strv_extend(&arg_states, "failed") < 0) |
| 447 |
return log_oom(); |
| 448 |
break; |
| 449 |
|
| 450 |
OPTION('p', "property", "NAME", "Show only properties by this name"): {} |
| 451 |
OPTION_SHORT('P', "NAME", "Equivalent to --value --property=NAME"): |
| 452 |
r = parse_property_argument(opts.arg, &arg_properties); |
| 453 |
if (r < 0) |
| 454 |
return r; |
| 455 |
|
| 456 |
/* If the user asked for a particular property, show it, even if it is empty. */ |
| 457 |
SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true); |
| 458 |
|
| 459 |
if (opts.opt->short_code == 'P') |
| 460 |
SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true); |
| 461 |
|
| 462 |
break; |
| 463 |
|
| 464 |
OPTION('a', "all", NULL, |
| 465 |
"Show all properties/all units currently in memory, including dead/empty ones. " |
| 466 |
"To list all units installed on the system, use 'list-unit-files' instead"): |
| 467 |
SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true); |
| 468 |
arg_all = true; |
| 469 |
break; |
| 470 |
|
| 471 |
OPTION('l', "full", NULL, "Don't ellipsize unit names on output"): |
| 472 |
arg_full = true; |
| 473 |
break; |
| 474 |
|
| 475 |
OPTION('r', "recursive", NULL, "Show unit list of host and local containers"): |
| 476 |
if (geteuid() != 0) |
| 477 |
return log_error_errno(SYNTHETIC_ERRNO(EPERM), |
| 478 |
"--recursive requires root privileges"); |
| 479 |
|
| 480 |
arg_recursive = true; |
| 481 |
break; |
| 482 |
|
| 483 |
OPTION_LONG("reverse", NULL, "Show reverse dependencies with 'list-dependencies'"): |
| 484 |
arg_dependency = DEPENDENCY_REVERSE; |
| 485 |
break; |
| 486 |
|
| 487 |
OPTION_LONG("before", NULL, "Show units ordered before with 'list-dependencies'"): |
| 488 |
arg_dependency = DEPENDENCY_BEFORE; |
| 489 |
arg_jobs_before = true; |
| 490 |
break; |
| 491 |
|
| 492 |
OPTION_LONG("after", NULL, "Show units ordered after with 'list-dependencies'"): |
| 493 |
arg_dependency = DEPENDENCY_AFTER; |
| 494 |
arg_jobs_after = true; |
| 495 |
break; |
| 496 |
|
| 497 |
OPTION_LONG("with-dependencies", NULL, |
| 498 |
"Show unit dependencies with 'status', 'cat', 'list-units', and 'list-unit-files'"): |
| 499 |
arg_with_dependencies = true; |
| 500 |
break; |
| 501 |
|
| 502 |
OPTION_LONG("job-mode", "MODE", |
| 503 |
"Specify how to deal with already queued jobs, when queueing a new job"): |
| 504 |
_arg_job_mode = opts.arg; |
| 505 |
break; |
| 506 |
|
| 507 |
OPTION('T', "show-transaction", NULL, "When enqueuing a unit job, show full transaction"): |
| 508 |
arg_show_transaction = true; |
| 509 |
break; |
| 510 |
|
| 511 |
OPTION_LONG("show-types", NULL, "When showing sockets, explicitly show their type"): |
| 512 |
arg_show_types = true; |
| 513 |
break; |
| 514 |
|
| 515 |
OPTION_LONG("value", NULL, "When showing properties, only print the value"): |
| 516 |
SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true); |
| 517 |
break; |
| 518 |
|
| 519 |
OPTION_LONG("check-inhibitors", "MODE", |
| 520 |
"Whether to check inhibitors before shutting down, sleeping, or hibernating"): |
| 521 |
r = parse_tristate_argument_with_auto("--check-inhibitors=", opts.arg, &arg_check_inhibitors); |
| 522 |
if (r < 0) |
| 523 |
return r; |
| 524 |
break; |
| 525 |
|
| 526 |
OPTION_LONG("ignore-inhibitors", NULL, /* help= */ NULL): {} |
| 527 |
|
| 528 |
OPTION_SHORT('i', NULL, "Shortcut for --check-inhibitors=no"): |
| 529 |
arg_check_inhibitors = 0; |
| 530 |
break; |
| 531 |
|
| 532 |
OPTION('s', "signal", "SIGNAL", "Which signal to send"): |
| 533 |
r = parse_signal_argument(opts.arg, &arg_signal); |
| 534 |
if (r <= 0) |
| 535 |
return r; |
| 536 |
break; |
| 537 |
|
| 538 |
OPTION_LONG("kill-whom", "WHOM", "Whom to send signal to"): |
| 539 |
arg_kill_whom = opts.arg; |
| 540 |
break; |
| 541 |
|
| 542 |
OPTION_LONG("kill-value", "INT", "Signal value to enqueue"): { |
| 543 |
unsigned u; |
| 544 |
|
| 545 |
if (isempty(opts.arg)) { |
| 546 |
arg_kill_value_set = false; |
| 547 |
return 0; |
| 548 |
} |
| 549 |
|
| 550 |
/* First, try to parse unsigned, so that we can support the prefixes 0x, 0o, 0b */ |
| 551 |
r = safe_atou_full(opts.arg, 0, &u); |
| 552 |
if (r < 0) |
| 553 |
/* If this didn't work, try as signed integer, without those prefixes */ |
| 554 |
r = safe_atoi(opts.arg, &arg_kill_value); |
| 555 |
else if (u > INT_MAX) |
| 556 |
r = -ERANGE; |
| 557 |
else |
| 558 |
arg_kill_value = (int) u; |
| 559 |
if (r < 0) |
| 560 |
return log_error_errno(r, "Unable to parse signal queue value: %s", opts.arg); |
| 561 |
|
| 562 |
arg_kill_value_set = true; |
| 563 |
break; |
| 564 |
} |
| 565 |
|
| 566 |
OPTION_LONG("kill-subgroup", "PATH", "Send signal to sub-control group only"): { |
| 567 |
if (empty_or_root(opts.arg)) { |
| 568 |
arg_kill_subgroup = mfree(arg_kill_subgroup); |
| 569 |
break; |
| 570 |
} |
| 571 |
|
| 572 |
_cleanup_free_ char *p = NULL; |
| 573 |
if (path_simplify_alloc(opts.arg, &p) < 0) |
| 574 |
return log_oom(); |
| 575 |
|
| 576 |
if (!path_is_safe(p)) |
| 577 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Control group sub-path '%s' is not valid.", p); |
| 578 |
|
| 579 |
free_and_replace(arg_kill_subgroup, p); |
| 580 |
break; |
| 581 |
} |
| 582 |
|
| 583 |
OPTION_LONG("what", "RESOURCES", "Which types of resources to remove"): |
| 584 |
r = parse_what_argument(opts.arg, &arg_clean_what); |
| 585 |
if (r <= 0) |
| 586 |
return r; |
| 587 |
break; |
| 588 |
|
| 589 |
OPTION_LONG("now", NULL, "Start or stop unit after enabling or disabling it"): |
| 590 |
arg_now = true; |
| 591 |
break; |
| 592 |
|
| 593 |
OPTION_LONG("dry-run", NULL, |
| 594 |
"Only print what would be done. Currently supported by verbs: halt, poweroff, " |
| 595 |
"reboot, kexec, soft-reboot, suspend, hibernate, suspend-then-hibernate, " |
| 596 |
"hybrid-sleep, default, rescue, emergency, and exit."): |
| 597 |
arg_dry_run = true; |
| 598 |
break; |
| 599 |
|
| 600 |
OPTION('q', "quiet", NULL, "Suppress output"): |
| 601 |
arg_quiet = true; |
| 602 |
|
| 603 |
if (arg_legend < 0) |
| 604 |
arg_legend = false; |
| 605 |
|
| 606 |
break; |
| 607 |
|
| 608 |
OPTION('v', "verbose", NULL, "Show unit logs while executing operation"): |
| 609 |
arg_verbose = true; |
| 610 |
break; |
| 611 |
|
| 612 |
OPTION_LONG("no-warn", NULL, "Suppress several warnings shown by default"): |
| 613 |
arg_no_warn = true; |
| 614 |
break; |
| 615 |
|
| 616 |
OPTION_LONG("wait", NULL, |
| 617 |
"For (re)start, wait until service stopped again. " |
| 618 |
"For is-system-running, wait until startup is completed. " |
| 619 |
"For kill, wait until service stopped."): |
| 620 |
arg_wait = true; |
| 621 |
break; |
| 622 |
|
| 623 |
OPTION_LONG("no-block", NULL, "Do not wait until operation finished"): |
| 624 |
arg_no_block = true; |
| 625 |
break; |
| 626 |
|
| 627 |
OPTION_LONG("no-wall", NULL, "Don't send wall message before halt/power-off/reboot"): |
| 628 |
arg_no_wall = true; |
| 629 |
break; |
| 630 |
|
| 631 |
OPTION_LONG("message", "MESSAGE", "Specify human-readable reason for system shutdown"): |
| 632 |
if (strv_extend(&arg_wall, opts.arg) < 0) |
| 633 |
return log_oom(); |
| 634 |
break; |
| 635 |
|
| 636 |
OPTION_LONG("no-reload", NULL, "Don't reload daemon after en-/dis-abling unit files"): |
| 637 |
arg_no_reload = true; |
| 638 |
break; |
| 639 |
|
| 640 |
OPTION_LONG("legend", "BOOL", "Enable/disable the legend (column headers and hints)"): |
| 641 |
r = parse_boolean_argument("--legend", opts.arg, NULL); |
| 642 |
if (r < 0) |
| 643 |
return r; |
| 644 |
arg_legend = r; |
| 645 |
break; |
| 646 |
|
| 647 |
OPTION_COMMON_NO_PAGER: |
| 648 |
arg_pager_flags |= PAGER_DISABLE; |
| 649 |
break; |
| 650 |
|
| 651 |
OPTION_COMMON_NO_ASK_PASSWORD: |
| 652 |
arg_ask_password = false; |
| 653 |
break; |
| 654 |
|
| 655 |
OPTION_LONG("global", NULL, "Edit/enable/disable/mask default user unit files globally"): |
| 656 |
arg_runtime_scope = RUNTIME_SCOPE_GLOBAL; |
| 657 |
break; |
| 658 |
|
| 659 |
OPTION_LONG("runtime", NULL, |
| 660 |
"Edit/enable/disable/mask unit files temporarily until next reboot"): |
| 661 |
arg_runtime = true; |
| 662 |
break; |
| 663 |
|
| 664 |
OPTION('f', "force", NULL, |
| 665 |
"When enabling unit files, override existing symlinks. " |
| 666 |
"When shutting down, execute action immediately."): |
| 667 |
arg_force++; |
| 668 |
break; |
| 669 |
|
| 670 |
OPTION_LONG("preset-mode", "MODE", "Apply only enable, only disable, or all presets"): |
| 671 |
if (streq(opts.arg, "help")) |
| 672 |
return DUMP_STRING_TABLE(unit_file_preset_mode, UnitFilePresetMode, _UNIT_FILE_PRESET_MODE_MAX); |
| 673 |
|
| 674 |
arg_preset_mode = unit_file_preset_mode_from_string(opts.arg); |
| 675 |
if (arg_preset_mode < 0) |
| 676 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 677 |
"Failed to parse preset mode: %s.", opts.arg); |
| 678 |
|
| 679 |
break; |
| 680 |
|
| 681 |
OPTION_LONG("root", "PATH", |
| 682 |
"Edit/enable/disable/mask unit files in the specified root directory"): |
| 683 |
r = parse_path_argument(opts.arg, false, &arg_root); |
| 684 |
if (r < 0) |
| 685 |
return r; |
| 686 |
break; |
| 687 |
|
| 688 |
OPTION_LONG("image", "PATH", |
| 689 |
"Edit/enable/disable/mask unit files in the specified disk image"): |
| 690 |
r = parse_path_argument(opts.arg, false, &arg_image); |
| 691 |
if (r < 0) |
| 692 |
return r; |
| 693 |
break; |
| 694 |
|
| 695 |
OPTION_LONG("image-policy", "POLICY", "Specify disk image dissection policy"): |
| 696 |
r = parse_image_policy_argument(opts.arg, &arg_image_policy); |
| 697 |
if (r < 0) |
| 698 |
return r; |
| 699 |
break; |
| 700 |
|
| 701 |
OPTION('n', "lines", "INTEGER", "Number of journal entries to show"): |
| 702 |
if (safe_atou(opts.arg, &arg_lines) < 0) |
| 703 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 704 |
"Failed to parse lines '%s'", |
| 705 |
opts.arg); |
| 706 |
break; |
| 707 |
|
| 708 |
OPTION('o', "output", "STRING", |
| 709 |
"Change journal output mode (short, short-precise, short-iso, short-iso-precise, " |
| 710 |
"short-full, short-monotonic, short-unix, short-delta, verbose, export, json, " |
| 711 |
"json-pretty, json-sse, cat)"): |
| 712 |
if (streq(opts.arg, "help")) |
| 713 |
return DUMP_STRING_TABLE(output_mode, OutputMode, _OUTPUT_MODE_MAX); |
| 714 |
|
| 715 |
arg_output = output_mode_from_string(opts.arg); |
| 716 |
if (arg_output < 0) |
| 717 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 718 |
"Unknown output '%s'.", |
| 719 |
opts.arg); |
| 720 |
|
| 721 |
if (OUTPUT_MODE_IS_JSON(arg_output)) { |
| 722 |
arg_legend = false; |
| 723 |
arg_plain = true; |
| 724 |
} |
| 725 |
break; |
| 726 |
|
| 727 |
OPTION_LONG("firmware-setup", NULL, "Tell the firmware to show the setup menu on next boot"): |
| 728 |
arg_firmware_setup = true; |
| 729 |
break; |
| 730 |
|
| 731 |
OPTION_LONG("boot-loader-menu", "TIME", "Boot into boot loader menu on next boot"): |
| 732 |
r = parse_sec(opts.arg, &arg_boot_loader_menu); |
| 733 |
if (r < 0) |
| 734 |
return log_error_errno(r, "Failed to parse --boot-loader-menu= argument '%s': %m", opts.arg); |
| 735 |
|
| 736 |
break; |
| 737 |
|
| 738 |
OPTION_LONG("boot-loader-entry", "NAME", |
| 739 |
"Boot into a specific boot loader entry on next boot"): |
| 740 |
if (streq(opts.arg, "help")) { /* Yes, this means, "help" is not a valid boot loader entry name we can deal with */ |
| 741 |
r = help_boot_loader_entry(); |
| 742 |
if (r < 0) |
| 743 |
return r; |
| 744 |
|
| 745 |
return 0; |
| 746 |
} |
| 747 |
|
| 748 |
arg_boot_loader_entry = empty_to_null(opts.arg); |
| 749 |
break; |
| 750 |
|
| 751 |
OPTION_LONG("reboot-argument", "ARG", "Specify argument string to pass to reboot()"): |
| 752 |
arg_reboot_argument = opts.arg; |
| 753 |
break; |
| 754 |
|
| 755 |
OPTION_LONG("kernel-cmdline", "CMDLINE", |
| 756 |
"Append to the kernel command line when loading the kernel " |
| 757 |
"from the booted boot loader entry"): |
| 758 |
if (isempty(opts.arg)) { |
| 759 |
arg_kernel_cmdline = mfree(arg_kernel_cmdline); |
| 760 |
break; |
| 761 |
} |
| 762 |
|
| 763 |
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS|STRING_ALLOW_BACKSLASHES|STRING_ALLOW_QUOTES)) |
| 764 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 765 |
"--kernel-cmdline= argument contains invalid characters: %s", opts.arg); |
| 766 |
|
| 767 |
r = free_and_strdup_warn(&arg_kernel_cmdline, opts.arg); |
| 768 |
if (r < 0) |
| 769 |
return r; |
| 770 |
break; |
| 771 |
|
| 772 |
OPTION_LONG("plain", NULL, "Print unit dependencies as a list instead of a tree"): |
| 773 |
arg_plain = true; |
| 774 |
break; |
| 775 |
|
| 776 |
OPTION_LONG("timestamp", "FORMAT", |
| 777 |
"Change format of printed timestamps (pretty, unix, us, utc, us+utc)"): |
| 778 |
if (streq(opts.arg, "help")) |
| 779 |
return DUMP_STRING_TABLE(timestamp_style, TimestampStyle, _TIMESTAMP_STYLE_MAX); |
| 780 |
|
| 781 |
arg_timestamp_style = timestamp_style_from_string(opts.arg); |
| 782 |
if (arg_timestamp_style < 0) |
| 783 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 784 |
"Invalid value: %s.", opts.arg); |
| 785 |
|
| 786 |
break; |
| 787 |
|
| 788 |
OPTION_LONG("read-only", NULL, "Create read-only bind mount"): |
| 789 |
arg_read_only = true; |
| 790 |
break; |
| 791 |
|
| 792 |
OPTION_LONG("mkdir", NULL, "Create directory before mounting, if missing"): |
| 793 |
arg_mkdir = true; |
| 794 |
break; |
| 795 |
|
| 796 |
OPTION_LONG("marked", NULL, "Restart/reload previously marked units"): |
| 797 |
arg_marked = true; |
| 798 |
break; |
| 799 |
|
| 800 |
OPTION_LONG("drop-in", "NAME", "Edit unit files using the specified drop-in file name"): |
| 801 |
arg_drop_in = opts.arg; |
| 802 |
break; |
| 803 |
|
| 804 |
OPTION_LONG("when", "TIME", |
| 805 |
"Schedule halt/power-off/reboot/kexec action after a certain timestamp"): |
| 806 |
if (streq(opts.arg, "show")) { |
| 807 |
arg_action = ACTION_SYSTEMCTL_SHOW_SHUTDOWN; |
| 808 |
return 1; |
| 809 |
} |
| 810 |
|
| 811 |
if (STR_IN_SET(opts.arg, "", "cancel")) { |
| 812 |
arg_action = ACTION_CANCEL_SHUTDOWN; |
| 813 |
return 1; |
| 814 |
} |
| 815 |
|
| 816 |
if (streq(opts.arg, "auto")) { |
| 817 |
arg_when = USEC_INFINITY; /* logind chooses on server side */ |
| 818 |
break; |
| 819 |
} |
| 820 |
|
| 821 |
r = parse_timestamp(opts.arg, &arg_when); |
| 822 |
if (r < 0) |
| 823 |
return log_error_errno(r, "Failed to parse --when= argument '%s': %m", opts.arg); |
| 824 |
|
| 825 |
if (!timestamp_is_set(arg_when)) |
| 826 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 827 |
"Invalid timestamp '%s' specified for --when=.", opts.arg); |
| 828 |
|
| 829 |
break; |
| 830 |
|
| 831 |
OPTION_LONG("stdin", NULL, "Read new contents of edited file from stdin"): |
| 832 |
arg_stdin = true; |
| 833 |
break; |
| 834 |
|
| 835 |
/* Compatibility-only options, not shown in --help. */ |
| 836 |
OPTION_LONG("fail", NULL, /* help= */ NULL): |
| 837 |
_arg_job_mode = "fail"; |
| 838 |
break; |
| 839 |
|
| 840 |
OPTION_LONG("irreversible", NULL, /* help= */ NULL): |
| 841 |
_arg_job_mode = "replace-irreversibly"; |
| 842 |
break; |
| 843 |
|
| 844 |
OPTION_LONG("ignore-dependencies", NULL, /* help= */ NULL): |
| 845 |
_arg_job_mode = "ignore-dependencies"; |
| 846 |
break; |
| 847 |
|
| 848 |
OPTION_LONG("no-legend", NULL, /* help= */ NULL): |
| 849 |
arg_legend = false; |
| 850 |
break; |
| 851 |
|
| 852 |
OPTION_SHORT_FLAGS(OPTION_OPTIONAL_ARG, '.', "ARG", /* help= */ NULL): |
| 853 |
/* Output an error mimicking getopt, and print a hint afterwards */ |
| 854 |
log_error("%s: invalid option -- '.'", program_invocation_name); |
| 855 |
log_notice("Hint: to specify units starting with a dash, use \"--\":\n" |
| 856 |
" %s [OPTIONS…] COMMAND -- -.%s …", |
| 857 |
program_invocation_name, opts.arg ?: "mount"); |
| 858 |
return -EINVAL; |
| 859 |
} |
| 860 |
|
| 861 |
/* If we are in --user mode, there's no point in talking to PolicyKit or the infra to query system |
| 862 |
* passwords */ |
| 863 |
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) |
| 864 |
arg_ask_password = false; |
| 865 |
|
| 866 |
if (arg_transport == BUS_TRANSPORT_REMOTE && arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) |
| 867 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 868 |
"Cannot access user instance remotely."); |
| 869 |
|
| 870 |
if (arg_transport == BUS_TRANSPORT_CAPSULE && arg_runtime_scope != RUNTIME_SCOPE_USER) |
| 871 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 872 |
"Cannot access system instance with --capsule=/-C."); |
| 873 |
|
| 874 |
if (arg_wait && arg_no_block) |
| 875 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 876 |
"--wait may not be combined with --no-block."); |
| 877 |
|
| 878 |
char **args = option_parser_get_args(&opts); |
| 879 |
size_t n_args = option_parser_get_n_args(&opts); |
| 880 |
|
| 881 |
bool do_reload_or_restart = streq_ptr(args[0], "reload-or-restart"); |
| 882 |
if (arg_marked) { |
| 883 |
if (!do_reload_or_restart) |
| 884 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 885 |
"--marked may only be used with 'reload-or-restart'."); |
| 886 |
if (n_args > 1) |
| 887 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 888 |
"No additional arguments allowed with 'reload-or-restart --marked'."); |
| 889 |
|
| 890 |
} else if (do_reload_or_restart) { |
| 891 |
if (n_args <= 1) |
| 892 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 893 |
"List of units to restart/reload is required."); |
| 894 |
} |
| 895 |
|
| 896 |
if (arg_image && arg_root) |
| 897 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 898 |
"Please specify either --root= or --image=, the combination of both is not supported."); |
| 899 |
|
| 900 |
if (remaining_args) |
| 901 |
*remaining_args = args; |
| 902 |
return 1; |
| 903 |
} |
| 904 |
|
| 905 |
int systemctl_dispatch_parse_argv(int argc, char *argv[], int log_level_shift, char ***remaining_args) { |
| 906 |
assert(argc >= 0); |
| 907 |
assert(argv); |
| 908 |
|
| 909 |
if (invoked_as(argv, "halt")) { |
| 910 |
arg_action = ACTION_HALT; |
| 911 |
return halt_parse_argv(argc, argv, log_level_shift); |
| 912 |
|
| 913 |
} else if (invoked_as(argv, "poweroff")) { |
| 914 |
arg_action = ACTION_POWEROFF; |
| 915 |
return halt_parse_argv(argc, argv, log_level_shift); |
| 916 |
|
| 917 |
} else if (invoked_as(argv, "reboot")) { |
| 918 |
arg_action = ACTION_REBOOT; |
| 919 |
return halt_parse_argv(argc, argv, log_level_shift); |
| 920 |
|
| 921 |
} else if (invoked_as(argv, "shutdown")) { |
| 922 |
arg_action = ACTION_POWEROFF; |
| 923 |
return shutdown_parse_argv(argc, argv, log_level_shift); |
| 924 |
|
| 925 |
} else { |
| 926 |
arg_action = ACTION_SYSTEMCTL; |
| 927 |
return systemctl_parse_argv(argc, argv, log_level_shift, remaining_args); |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
VERB_GROUP("Unit Commands"); |
| 932 |
|
| 933 |
VERB_SCOPE(, verb_list_units, "list-units", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, |
| 934 |
"List units currently in memory"); |
| 935 |
VERB_SCOPE(, verb_list_automounts, "list-automounts", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 936 |
"List automount units currently in memory, ordered by path"); |
| 937 |
VERB_SCOPE(, verb_list_paths, "list-paths", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 938 |
"List path units currently in memory, ordered by path"); |
| 939 |
VERB_SCOPE(, verb_list_sockets, "list-sockets", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 940 |
"List socket units currently in memory, ordered by address"); |
| 941 |
VERB_SCOPE(, verb_list_timers, "list-timers", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 942 |
"List timer units currently in memory, ordered by next elapse"); |
| 943 |
VERB_SCOPE(, verb_is_active, "is-active", "PATTERN…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 944 |
"Check whether units are active"); |
| 945 |
VERB_SCOPE(, verb_is_failed, "is-failed", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 946 |
"Check whether units are failed or system is in degraded state"); |
| 947 |
VERB_SCOPE(, verb_show, "status", "[PATTERN…|PID…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 948 |
"Show runtime status of one or more units"); |
| 949 |
VERB_SCOPE(, verb_show, "show", "[PATTERN…|JOB…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 950 |
"Show properties of one or more units/jobs or the manager"); |
| 951 |
VERB_SCOPE(, verb_cat, "cat", "PATTERN…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 952 |
"Show files and drop-ins of specified units"); |
| 953 |
VERB_SCOPE(, verb_show, "help", "PATTERN…|PID…", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 954 |
"Show manual for one or more units"); |
| 955 |
VERB_SCOPE(, verb_list_dependencies, "list-dependencies", "[UNIT…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 956 |
"Recursively show units which are required or wanted by the units " |
| 957 |
"or by which those units are required or wanted"); |
| 958 |
VERB_SCOPE(, verb_start, "start", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 959 |
"Start (activate) one or more units"); |
| 960 |
VERB_SCOPE(, verb_start, "stop", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 961 |
"Stop (deactivate) one or more units"); |
| 962 |
VERB_SCOPE(, verb_start, "reload", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 963 |
"Reload one or more units"); |
| 964 |
VERB_SCOPE(, verb_start, "restart", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 965 |
"Start or restart one or more units"); |
| 966 |
VERB_SCOPE(, verb_start, "try-restart", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 967 |
"Restart one or more units if active"); |
| 968 |
VERB_SCOPE(, verb_start, "enqueue-marked", NULL, 1, 1, VERB_ONLINE_ONLY, |
| 969 |
"Enqueue jobs for all marked units"); |
| 970 |
VERB_SCOPE(, verb_start, "reload-or-restart", "UNIT…", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 971 |
"Reload one or more units if possible, otherwise start or restart"); |
| 972 |
VERB_SCOPE(, verb_start, "try-reload-or-restart", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 973 |
"If active, reload one or more units, if supported, otherwise restart"); |
| 974 |
VERB_SCOPE(, verb_start, "isolate", "UNIT", 2, 2, VERB_ONLINE_ONLY, |
| 975 |
"Start one unit and stop all others"); |
| 976 |
VERB_SCOPE(, verb_kill, "kill", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 977 |
"Send signal to processes of a unit"); |
| 978 |
VERB_SCOPE(, verb_clean_or_freeze, "clean", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 979 |
"Clean runtime, cache, state, logs or configuration of unit"); |
| 980 |
VERB_SCOPE(, verb_clean_or_freeze, "freeze", "PATTERN…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 981 |
"Freeze execution of unit processes"); |
| 982 |
VERB_SCOPE(, verb_clean_or_freeze, "thaw", "PATTERN…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 983 |
"Resume execution of a frozen unit"); |
| 984 |
VERB_SCOPE(, verb_set_property, "set-property", "UNIT PROPERTY=VALUE…", 3, VERB_ANY, VERB_ONLINE_ONLY, |
| 985 |
"Sets one or more properties of a unit"); |
| 986 |
VERB_SCOPE(, verb_bind, "bind", "UNIT PATH [PATH]", 3, 4, VERB_ONLINE_ONLY, |
| 987 |
"Bind-mount a path from the host into a unit's namespace"); |
| 988 |
VERB_SCOPE(, verb_mount_image, "mount-image", "UNIT PATH [PATH [OPTS]]", 4, 5, VERB_ONLINE_ONLY, |
| 989 |
"Mount an image from the host into a unit's namespace"); |
| 990 |
VERB_SCOPE(, verb_service_log_setting, "service-log-level", "SERVICE [LEVEL]", 2, 3, VERB_ONLINE_ONLY, |
| 991 |
"Get/set logging threshold for service"); |
| 992 |
VERB_SCOPE(, verb_service_log_setting, "service-log-target", "SERVICE [TARGET]", 2, 3, VERB_ONLINE_ONLY, |
| 993 |
"Get/set logging target for service"); |
| 994 |
VERB_SCOPE(, verb_reset_failed, "reset-failed", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 995 |
"Reset failed state for all, one, or more units"); |
| 996 |
VERB_SCOPE(, verb_whoami, "whoami", "[PID…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 997 |
"Return unit caller or specified PIDs are part of"); |
| 998 |
|
| 999 |
VERB_GROUP("Unit File Commands"); |
| 1000 |
|
| 1001 |
VERB_SCOPE(, verb_list_unit_files, "list-unit-files", "[PATTERN…]", VERB_ANY, VERB_ANY, 0, |
| 1002 |
"List installed unit files"); |
| 1003 |
VERB_SCOPE(, verb_enable, "enable", "[UNIT…|PATH…]", 2, VERB_ANY, 0, |
| 1004 |
"Enable one or more unit files"); |
| 1005 |
VERB_SCOPE(, verb_enable, "disable", "UNIT…", 2, VERB_ANY, 0, |
| 1006 |
"Disable one or more unit files"); |
| 1007 |
VERB_SCOPE(, verb_enable, "reenable", "UNIT…", 2, VERB_ANY, 0, |
| 1008 |
"Reenable one or more unit files"); |
| 1009 |
VERB_SCOPE(, verb_enable, "preset", "UNIT…", 2, VERB_ANY, 0, |
| 1010 |
"Enable/disable one or more unit files based on preset configuration"); |
| 1011 |
VERB_SCOPE(, verb_preset_all, "preset-all", NULL, VERB_ANY, 1, 0, |
| 1012 |
"Enable/disable all unit files based on preset configuration"); |
| 1013 |
VERB_SCOPE(, verb_is_enabled, "is-enabled", "UNIT…", 2, VERB_ANY, 0, |
| 1014 |
"Check whether unit files are enabled"); |
| 1015 |
VERB_SCOPE(, verb_enable, "mask", "UNIT…", 2, VERB_ANY, 0, |
| 1016 |
"Mask one or more units"); |
| 1017 |
VERB_SCOPE(, verb_enable, "unmask", "UNIT…", 2, VERB_ANY, 0, |
| 1018 |
"Unmask one or more units"); |
| 1019 |
VERB_SCOPE(, verb_enable, "link", "PATH…", 2, VERB_ANY, 0, |
| 1020 |
"Link one or more units files into the search path"); |
| 1021 |
VERB_SCOPE(, verb_enable, "revert", "UNIT…", 2, VERB_ANY, 0, |
| 1022 |
"Revert one or more unit files to vendor version"); |
| 1023 |
VERB_SCOPE(, verb_add_dependency, "add-wants", "TARGET UNIT…", 3, VERB_ANY, 0, |
| 1024 |
"Add 'Wants' dependency for the target on specified one or more units"); |
| 1025 |
VERB_SCOPE(, verb_add_dependency, "add-requires", "TARGET UNIT…", 3, VERB_ANY, 0, |
| 1026 |
"Add 'Requires' dependency for the target on specified one or more units"); |
| 1027 |
VERB_SCOPE(, verb_edit, "edit", "UNIT…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 1028 |
"Edit one or more unit files"); |
| 1029 |
VERB_SCOPE(, verb_get_default, "get-default", NULL, VERB_ANY, 1, 0, |
| 1030 |
"Get the name of the default target"); |
| 1031 |
VERB_SCOPE(, verb_set_default, "set-default", "TARGET", 2, 2, 0, |
| 1032 |
"Set the default target"); |
| 1033 |
|
| 1034 |
VERB_GROUP("Machine Commands"); |
| 1035 |
|
| 1036 |
VERB_SCOPE(, verb_list_machines, "list-machines", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 1037 |
"List local containers and host"); |
| 1038 |
|
| 1039 |
VERB_GROUP("Job Commands"); |
| 1040 |
|
| 1041 |
VERB_SCOPE(, verb_list_jobs, "list-jobs", "[PATTERN…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 1042 |
"List jobs"); |
| 1043 |
VERB_SCOPE(, verb_cancel, "cancel", "[JOB…]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 1044 |
"Cancel all, one, or more jobs"); |
| 1045 |
|
| 1046 |
VERB_GROUP("Environment Commands"); |
| 1047 |
|
| 1048 |
VERB_SCOPE(, verb_show_environment, "show-environment", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1049 |
"Dump environment"); |
| 1050 |
VERB_SCOPE(, verb_set_environment, "set-environment", "VARIABLE=VALUE…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 1051 |
"Set one or more environment variables"); |
| 1052 |
VERB_SCOPE(, verb_set_environment, "unset-environment", "VARIABLE…", 2, VERB_ANY, VERB_ONLINE_ONLY, |
| 1053 |
"Unset one or more environment variables"); |
| 1054 |
VERB_SCOPE(, verb_import_environment, "import-environment", "VARIABLE…", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 1055 |
"Import all or some environment variables"); |
| 1056 |
|
| 1057 |
VERB_GROUP("Manager State Commands"); |
| 1058 |
|
| 1059 |
VERB_SCOPE(, verb_daemon_reload, "daemon-reload", NULL, 1, 1, VERB_ONLINE_ONLY, |
| 1060 |
"Reload systemd manager configuration"); |
| 1061 |
VERB_SCOPE(, verb_daemon_reload, "daemon-reexec", NULL, 1, 1, VERB_ONLINE_ONLY, |
| 1062 |
"Reexecute systemd manager"); |
| 1063 |
VERB_SCOPE(, verb_log_setting, "log-level", "[LEVEL]", VERB_ANY, 2, VERB_ONLINE_ONLY, |
| 1064 |
"Get/set logging threshold for manager"); |
| 1065 |
VERB_SCOPE(, verb_log_setting, "log-target", "[TARGET]", VERB_ANY, 2, VERB_ONLINE_ONLY, |
| 1066 |
"Get/set logging target for manager"); |
| 1067 |
VERB_SCOPE(, verb_service_watchdogs, "service-watchdogs", "[BOOL]", VERB_ANY, 2, VERB_ONLINE_ONLY, |
| 1068 |
"Get/set service watchdog state"); |
| 1069 |
|
| 1070 |
VERB_GROUP("System Commands"); |
| 1071 |
|
| 1072 |
VERB_SCOPE(, verb_is_system_running, "is-system-running", NULL, VERB_ANY, 1, 0, |
| 1073 |
"Check whether system is fully running"); |
| 1074 |
VERB_SCOPE(, verb_start_special, "default", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1075 |
"Enter system default mode"); |
| 1076 |
VERB_SCOPE(, verb_start_system_special, "rescue", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1077 |
"Enter system rescue mode"); |
| 1078 |
VERB_SCOPE(, verb_start_system_special, "emergency", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1079 |
"Enter system emergency mode"); |
| 1080 |
VERB_SCOPE(, verb_start_system_special, "halt", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1081 |
"Shut down and halt the system"); |
| 1082 |
VERB_SCOPE(, verb_start_system_special, "poweroff", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1083 |
"Shut down and power-off the system"); |
| 1084 |
VERB_SCOPE(, verb_start_system_special, "reboot", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1085 |
"Shut down and reboot the system"); |
| 1086 |
VERB_SCOPE(, verb_start_system_special, "kexec", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1087 |
"Shut down and reboot the system with kexec"); |
| 1088 |
VERB_SCOPE(, verb_start_system_special, "soft-reboot", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1089 |
"Shut down and reboot userspace"); |
| 1090 |
VERB_SCOPE(, verb_start_special, "exit", "[EXIT_CODE]", VERB_ANY, 2, VERB_ONLINE_ONLY, |
| 1091 |
"Request user instance or container exit"); |
| 1092 |
VERB_SCOPE(, verb_switch_root, "switch-root", "[ROOT [INIT]]", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, |
| 1093 |
"Change to a different root file system"); |
| 1094 |
VERB_SCOPE(, verb_start_system_special, "sleep", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1095 |
"Put the system to sleep (through one of the operations below)"); |
| 1096 |
VERB_SCOPE(, verb_start_system_special, "suspend", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1097 |
"Suspend the system"); |
| 1098 |
VERB_SCOPE(, verb_start_system_special, "hibernate", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1099 |
"Hibernate the system"); |
| 1100 |
VERB_SCOPE(, verb_start_system_special, "hybrid-sleep", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1101 |
"Hibernate and suspend the system"); |
| 1102 |
VERB_SCOPE(, verb_start_system_special, "suspend-then-hibernate", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, |
| 1103 |
"Suspend the system, wake after a period of time, and hibernate"); |
| 1104 |
|
| 1105 |
/* Compatibility aliases / deprecated verbs hidden from --help. */ |
| 1106 |
VERB_SCOPE(, verb_trivial_method, "clear-jobs", NULL, VERB_ANY, 1, VERB_ONLINE_ONLY, /* help= */ NULL); /* systemctl < 4 */ |
| 1107 |
VERB_SCOPE(, verb_start, "condstop", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* ALTLinux */ |
| 1108 |
VERB_SCOPE(, verb_start, "reload-or-try-restart", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* systemctl <= 228 */ |
| 1109 |
VERB_SCOPE(, verb_start, "force-reload", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* SysV */ |
| 1110 |
VERB_SCOPE(, verb_start, "condreload", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* ALTLinux */ |
| 1111 |
VERB_SCOPE(, verb_start, "condrestart", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* RH */ |
| 1112 |
VERB_SCOPE(, verb_is_active, "check", NULL, 2, VERB_ANY, VERB_ONLINE_ONLY, /* help= */ NULL); /* deprecated alias of is-active */ |
| 1113 |
|
| 1114 |
int systemctl_main(char **args) { |
| 1115 |
assert((uintptr_t) __start_SYSTEMD_VERBS % sizeof(void*) == 0); |
| 1116 |
const Verb *verb = verbs_find_verb(args[0], __start_SYSTEMD_VERBS, __stop_SYSTEMD_VERBS); |
| 1117 |
|
| 1118 |
if (verb && (verb->flags & VERB_ONLINE_ONLY) && arg_root) |
| 1119 |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |
| 1120 |
"Verb '%s' cannot be used with --root= or --image=.", |
| 1121 |
args[0] ?: verb->verb); |
| 1122 |
|
| 1123 |
return dispatch_verb(args, NULL); |
| 1124 |
} |