From: Zbigniew Jędrzejewski-Szmek Date: Sun, 22 May 2022 12:32:55 +0000 (+0200) Subject: systemctl: make show/status honour --state and --type X-Git-Tag: v252-rc1~927 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a6e334649d4bdff0c6f664e98666b2223aa21a8b;p=thirdparty%2Fsystemd.git systemctl: make show/status honour --state and --type This makes the interface more flexible, by allowing the same filtering for show and status as is done for list-units. Fixes #23207. --- diff --git a/man/systemctl.xml b/man/systemctl.xml index 963eb9ec3ad..63ea80a4536 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -188,13 +188,15 @@ Sun 2017-02-26 20:57:49 EST 2h 3min left Sun 2017-02-26 11:56:36 EST 6h ago status PATTERN…|PID…] - Show terse runtime status information about one or - more units, followed by most recent log data from the - journal. If no units are specified, show system status. If - combined with , also show the status of - all units (subject to limitations specified with - ). If a PID is passed, show information - about the unit the process belongs to. + Show runtime status information about the whole system or about one or more units followed + by most recent log data from the journal. If no positional arguments are specified, and no unit + filter is given with , , or + , shows the status of the whole system. If combined with + , follows that with the status of all units. If positional arguments are + specified, each positional argument is treated as either a unit name to show, or a glob pattern + to show units whose names match that pattern, or a PID to show the unit containing that PID. When + , , or are used, units + are additionally filtered by the TYPE and ACTIVE state. This function is intended to generate human-readable output. If you are looking for computer-parsable output, @@ -1621,18 +1623,13 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err - The argument should be a comma-separated list of unit - types such as and - . - - - If one of the arguments is a unit type, when listing - units, limit display to certain unit types. Otherwise, units - of all types will be shown. + The argument is a comma-separated list of unit types such as and + . When units are listed with list-units, + show, or status, only units of the specified types will be + shown. By default, units of all types are shown. - As a special case, if one of the arguments is - , a list of allowed values will be - printed and the program will exit. + As a special case, if one of the arguments is , a list of allowed values + will be printed and the program will exit. @@ -1640,14 +1637,13 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err - The argument should be a comma-separated list of unit - LOAD, SUB, or ACTIVE states. When listing units, show only - those in the specified states. Use - to show only failed units. - - As a special case, if one of the arguments is - , a list of allowed values will be - printed and the program will exit. + The argument is a comma-separated list of unit LOAD, SUB, or ACTIVE states. When listing + units with list-units, show, or status, + show only those in the specified states. Use or + to show only failed units. + + As a special case, if one of the arguments is , a list of allowed values + will be printed and the program will exit. diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 1c0b0027347..cc7abca6df8 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -2070,6 +2070,7 @@ static int get_unit_dbus_path_by_pid( static int show_all( sd_bus *bus, + SystemctlShowMode show_mode, bool *new_line, bool *ellipsized) { @@ -2095,7 +2096,7 @@ static int show_all( if (!p) return log_oom(); - r = show_one(bus, p, u->id, SYSTEMCTL_SHOW_STATUS, new_line, ellipsized); + r = show_one(bus, p, u->id, show_mode, new_line, ellipsized); if (r < 0) return r; if (r > 0 && ret == 0) @@ -2196,17 +2197,28 @@ int verb_show(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); - /* If no argument is specified inspect the manager itself */ - if (show_mode == SYSTEMCTL_SHOW_PROPERTIES && argc <= 1) - return show_one(bus, "/org/freedesktop/systemd1", NULL, show_mode, &new_line, &ellipsized); - - if (show_mode == SYSTEMCTL_SHOW_STATUS && argc <= 1) { + if (argc <= 1) { + /* If no argument or filter is specified inspect the manager itself: + * systemctl status → we show status of the manager + * systemctl status --all → status of the manager + status of all units + * systemctl status --state=… → status of units in listed states + * systemctl status --type=… → status of units of listed types + * systemctl status --failed → status of failed units, mirroring systemctl list-units --failed + */ + + if (!arg_states && !arg_types) { + if (show_mode == SYSTEMCTL_SHOW_PROPERTIES) + r = show_one(bus, "/org/freedesktop/systemd1", NULL, show_mode, &new_line, &ellipsized); + else + r = show_system_status(bus); + if (r < 0) + return r; - show_system_status(bus); - new_line = true; + new_line = true; + } - if (arg_all) - ret = show_all(bus, &new_line, &ellipsized); + if (arg_all || arg_states || arg_types) + ret = show_all(bus, show_mode, &new_line, &ellipsized); } else { _cleanup_free_ char **patterns = NULL;