systemctl: describe the halt/poweroff/reboot/shutdown compat commands
The custom halt_help() and shutdown_help() are replaced by COMMAND() descriptions (one per command name, halt/poweroff/reboot sharing the "halt" option namespace), and --introspect-cli is added to both parsers. halt/poweroff/reboot now each reference their own man page name.
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
#include "sd-daemon.h"
|
#include "sd-daemon.h"
|
||||||
|
#include "sd-json.h"
|
||||||
|
|
||||||
#include "ansi-color.h"
|
#include "ansi-color.h"
|
||||||
#include "format-table.h"
|
|
||||||
#include "help-util.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "options.h"
|
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
#include "reboot-util.h"
|
#include "reboot-util.h"
|
||||||
#include "systemctl.h"
|
#include "systemctl.h"
|
||||||
@@ -15,40 +13,35 @@
|
|||||||
#include "systemctl-start-unit.h"
|
#include "systemctl-start-unit.h"
|
||||||
#include "systemctl-util.h"
|
#include "systemctl-util.h"
|
||||||
#include "utmp-wtmp.h"
|
#include "utmp-wtmp.h"
|
||||||
|
#include "verbs.h"
|
||||||
|
|
||||||
static int halt_help(void) {
|
COMMAND(
|
||||||
_cleanup_(table_unrefp) Table *options = NULL;
|
"halt\0",
|
||||||
int r;
|
"Halt the system.",
|
||||||
|
.footer = "This is a compatibility interface, please use the more powerful "
|
||||||
|
"'systemctl halt' command instead.",
|
||||||
|
.man_pages = "halt.8\0",
|
||||||
|
.option_namespace = "halt",
|
||||||
|
);
|
||||||
|
|
||||||
r = option_parser_get_help_table_ns("halt", &options);
|
COMMAND(
|
||||||
if (r < 0)
|
"poweroff\0",
|
||||||
return r;
|
"Power off the system.",
|
||||||
|
.footer = "This is a compatibility interface, please use the more powerful "
|
||||||
|
"'systemctl poweroff' command instead.",
|
||||||
|
.man_pages = "poweroff.8\0",
|
||||||
|
.option_namespace = "halt",
|
||||||
|
);
|
||||||
|
|
||||||
/* Note: if you are tempted to add new command line switches here, please do not. Let this
|
COMMAND(
|
||||||
* compatibility command rest in peace. Its interface is not even owned by us as much as it is by
|
"reboot\0",
|
||||||
* sysvinit. If you add something new, add it to "systemctl halt", "systemctl reboot", "systemctl
|
"Reboot the system.",
|
||||||
* poweroff" instead. */
|
.argspec = "[ARG]\0",
|
||||||
|
.footer = "This is a compatibility interface, please use the more powerful "
|
||||||
help_cmdline(arg_action == ACTION_REBOOT ? "[OPTIONS…] [ARG]" : "[OPTIONS…]");
|
"'systemctl reboot' command instead.",
|
||||||
help_abstract(arg_action == ACTION_REBOOT ? "Reboot the system." :
|
.man_pages = "reboot.8\0",
|
||||||
arg_action == ACTION_POWEROFF ? "Power off the system." :
|
.option_namespace = "halt",
|
||||||
"Halt the system.");
|
);
|
||||||
|
|
||||||
help_section("Options");
|
|
||||||
r = table_print_or_warn(options);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
printf("\n%sThis is a compatibility interface, please use the more powerful 'systemctl %s' command instead.%s\n",
|
|
||||||
ansi_highlight_red(),
|
|
||||||
arg_action == ACTION_REBOOT ? "reboot" :
|
|
||||||
arg_action == ACTION_POWEROFF ? "poweroff" :
|
|
||||||
"halt",
|
|
||||||
ansi_normal());
|
|
||||||
|
|
||||||
help_man_page_reference("halt", "8");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int halt_parse_argv(int argc, char *argv[], int log_level_shift) {
|
int halt_parse_argv(int argc, char *argv[], int log_level_shift) {
|
||||||
int r;
|
int r;
|
||||||
@@ -62,13 +55,20 @@ int halt_parse_argv(int argc, char *argv[], int log_level_shift) {
|
|||||||
.log_level_shift = log_level_shift,
|
.log_level_shift = log_level_shift,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Note: if you are tempted to add new command line switches here, please do not. Let this
|
||||||
|
* compatibility command rest in peace. Its interface is not even owned by us as much as it
|
||||||
|
* is by sysvinit. If you add something new, add it to "systemctl halt", "systemctl
|
||||||
|
* reboot", "systemctl poweroff" instead. */
|
||||||
|
|
||||||
FOREACH_OPTION_OR_RETURN(c, &opts)
|
FOREACH_OPTION_OR_RETURN(c, &opts)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
OPTION_NAMESPACE("halt"): {}
|
OPTION_NAMESPACE("halt"): {}
|
||||||
|
|
||||||
OPTION_LONG("help", NULL, "Show this help"):
|
OPTION_LONG("help", NULL, "Show this help"):
|
||||||
return halt_help();
|
return command_print_help_full(
|
||||||
|
action_table[arg_action].verb,
|
||||||
|
/* footer_ansi_seq= */ ansi_highlight_red());
|
||||||
|
|
||||||
OPTION_LONG("halt", NULL, "Halt the machine"):
|
OPTION_LONG("halt", NULL, "Halt the machine"):
|
||||||
arg_action = ACTION_HALT;
|
arg_action = ACTION_HALT;
|
||||||
@@ -108,6 +108,9 @@ int halt_parse_argv(int argc, char *argv[], int log_level_shift) {
|
|||||||
OPTION_SHORT('h', NULL, /* help= */ NULL):
|
OPTION_SHORT('h', NULL, /* help= */ NULL):
|
||||||
/* Compatibility nops */
|
/* Compatibility nops */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
OPTION_COMMON_INTROSPECT_CLI:
|
||||||
|
return introspect_cli(SD_JSON_FORMAT_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **args = option_parser_get_args(&opts);
|
char **args = option_parser_get_args(&opts);
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
|
#include "sd-json.h"
|
||||||
|
|
||||||
#include "ansi-color.h"
|
#include "ansi-color.h"
|
||||||
#include "format-table.h"
|
|
||||||
#include "help-util.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "options.h"
|
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "reboot-util.h"
|
#include "reboot-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
@@ -12,35 +11,17 @@
|
|||||||
#include "systemctl.h"
|
#include "systemctl.h"
|
||||||
#include "systemctl-compat-shutdown.h"
|
#include "systemctl-compat-shutdown.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
|
#include "verbs.h"
|
||||||
|
|
||||||
static int shutdown_help(void) {
|
COMMAND(
|
||||||
_cleanup_(table_unrefp) Table *options = NULL;
|
"shutdown\0",
|
||||||
int r;
|
"Shut down the system.",
|
||||||
|
.argspec = "[TIME] [WALL…]\0",
|
||||||
r = option_parser_get_help_table_ns("shutdown", &options);
|
.footer = "This is a compatibility interface, please use the more powerful 'systemctl halt', "
|
||||||
if (r < 0)
|
"'systemctl poweroff', 'systemctl reboot' commands instead.",
|
||||||
return r;
|
.man_pages = "shutdown.8\0",
|
||||||
|
.option_namespace = "shutdown",
|
||||||
/* Note: if you are tempted to add new command line switches here, please do not. Let this
|
);
|
||||||
* compatibility command rest in peace. Its interface is not even owned by us as much as it is by
|
|
||||||
* sysvinit. If you add something new, add it to "systemctl halt", "systemctl reboot", "systemctl
|
|
||||||
* poweroff" instead. */
|
|
||||||
|
|
||||||
help_cmdline("[OPTIONS…] [TIME] [WALL…]");
|
|
||||||
help_abstract("Shut down the system.");
|
|
||||||
|
|
||||||
help_section("Options");
|
|
||||||
r = table_print_or_warn(options);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
printf("\n%sThis is a compatibility interface, please use the more powerful 'systemctl halt',\n"
|
|
||||||
"'systemctl poweroff', 'systemctl reboot' commands instead.%s\n",
|
|
||||||
ansi_highlight_red(), ansi_normal());
|
|
||||||
|
|
||||||
help_man_page_reference("shutdown", "8");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int parse_shutdown_time_spec(const char *t, usec_t *ret) {
|
static int parse_shutdown_time_spec(const char *t, usec_t *ret) {
|
||||||
int r;
|
int r;
|
||||||
@@ -128,13 +109,20 @@ int shutdown_parse_argv(int argc, char *argv[], int log_level_shift) {
|
|||||||
.log_level_shift = log_level_shift,
|
.log_level_shift = log_level_shift,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Note: if you are tempted to add new command line switches here, please do not. Let this
|
||||||
|
* compatibility command rest in peace. Its interface is not even owned by us as much as it
|
||||||
|
* is by sysvinit. If you add something new, add it to "systemctl halt", "systemctl
|
||||||
|
* reboot", "systemctl poweroff" instead. */
|
||||||
|
|
||||||
FOREACH_OPTION_OR_RETURN(c, &opts)
|
FOREACH_OPTION_OR_RETURN(c, &opts)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
OPTION_NAMESPACE("shutdown"): {}
|
OPTION_NAMESPACE("shutdown"): {}
|
||||||
|
|
||||||
OPTION_LONG("help", NULL, "Show this help"):
|
OPTION_LONG("help", NULL, "Show this help"):
|
||||||
return shutdown_help();
|
return command_print_help_full(
|
||||||
|
"shutdown",
|
||||||
|
/* footer_ansi_seq= */ ansi_highlight_red());
|
||||||
|
|
||||||
OPTION('H', "halt", NULL, "Halt the machine"):
|
OPTION('H', "halt", NULL, "Halt the machine"):
|
||||||
arg_action = ACTION_HALT;
|
arg_action = ACTION_HALT;
|
||||||
@@ -182,6 +170,9 @@ int shutdown_parse_argv(int argc, char *argv[], int log_level_shift) {
|
|||||||
OPTION_SHORT('F', NULL, /* help= */ NULL): {}
|
OPTION_SHORT('F', NULL, /* help= */ NULL): {}
|
||||||
OPTION_SHORT('t', "ARG", /* help= */ NULL):
|
OPTION_SHORT('t', "ARG", /* help= */ NULL):
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
OPTION_COMMON_INTROSPECT_CLI:
|
||||||
|
return introspect_cli(SD_JSON_FORMAT_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **args = option_parser_get_args(&opts);
|
char **args = option_parser_get_args(&opts);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ INTROSPECTABLE=(
|
|||||||
coredumpctl
|
coredumpctl
|
||||||
dmi_memory_id
|
dmi_memory_id
|
||||||
fido_id
|
fido_id
|
||||||
|
halt
|
||||||
homectl
|
homectl
|
||||||
hostnamectl
|
hostnamectl
|
||||||
importctl
|
importctl
|
||||||
@@ -30,9 +31,12 @@ INTROSPECTABLE=(
|
|||||||
networkctl
|
networkctl
|
||||||
oomctl
|
oomctl
|
||||||
portablectl
|
portablectl
|
||||||
|
poweroff
|
||||||
|
reboot
|
||||||
resolvectl
|
resolvectl
|
||||||
run0
|
run0
|
||||||
scsi_id
|
scsi_id
|
||||||
|
shutdown
|
||||||
storagectl
|
storagectl
|
||||||
systemctl
|
systemctl
|
||||||
systemd-ac-power
|
systemd-ac-power
|
||||||
@@ -138,7 +142,9 @@ for i in "${INTROSPECTABLE[@]}"; do
|
|||||||
$i --intro | grep -e --help
|
$i --intro | grep -e --help
|
||||||
|
|
||||||
# If the tool has a "help" verb, it must work too
|
# If the tool has a "help" verb, it must work too
|
||||||
if $i --introspect-cli | jq -e 'any(.commands[]; (.verbs // []) | any(.names[0] == "help"))' >/dev/null; then
|
if $i --introspect-cli | jq -e --arg name "$i" \
|
||||||
|
'any(.commands[]; any(.names[]; . == $name) and ((.verbs // []) | any(.names[0] == "help")))' \
|
||||||
|
>/dev/null; then
|
||||||
# 'systemctl help' shows unit manuals
|
# 'systemctl help' shows unit manuals
|
||||||
[[ "$i" == systemctl ]] && continue
|
[[ "$i" == systemctl ]] && continue
|
||||||
|
|
||||||
@@ -172,3 +178,6 @@ systemd-mstack --introspect-cli | jq -e \
|
|||||||
|
|
||||||
systemd-run --introspect-cli | jq -e \
|
systemd-run --introspect-cli | jq -e \
|
||||||
'[.commands[].names[0]] | sort == ["run0", "systemd-run"]'
|
'[.commands[].names[0]] | sort == ["run0", "systemd-run"]'
|
||||||
|
|
||||||
|
systemctl --introspect-cli | jq -e \
|
||||||
|
'[.commands[].names[0]] | sort == ["halt", "poweroff", "reboot", "shutdown", "systemctl"]'
|
||||||
|
|||||||
Reference in New Issue
Block a user