summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-show.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
commitefeb864cb547a2cbf96dc0053a8bdb4d9190b364 (patch)
treec0b83368f18be983fcc763200c4c24d633244588 /src/systemctl/systemctl-show.c
parentReleasing progress-linux version 255.5-1~progress7.99u1. (diff)
downloadsystemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.tar.xz
systemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/systemctl/systemctl-show.c')
-rw-r--r--src/systemctl/systemctl-show.c143
1 files changed, 31 insertions, 112 deletions
diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c
index 5d1eb49..2fdf321 100644
--- a/src/systemctl/systemctl-show.c
+++ b/src/systemctl/systemctl-show.c
@@ -196,6 +196,8 @@ typedef struct UnitStatusInfo {
uint64_t runtime_max_sec;
+ sd_id128_t invocation_id;
+
bool need_daemon_reload;
bool transient;
@@ -204,7 +206,7 @@ typedef struct UnitStatusInfo {
pid_t control_pid;
const char *status_text;
const char *pid_file;
- bool running:1;
+ bool running;
int status_errno;
uint32_t fd_store_max;
@@ -468,6 +470,9 @@ static void print_status_info(
} else
printf("\n");
+ if (!sd_id128_is_null(i->invocation_id))
+ printf(" Invocation: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(i->invocation_id));
+
STRV_FOREACH(t, i->triggered_by) {
UnitActiveState state = _UNIT_ACTIVE_STATE_INVALID;
@@ -703,17 +708,18 @@ static void print_status_info(
if (i->n_fd_store > 0 || i->fd_store_max > 0)
printf(" FD Store: %u%s (limit: %u)%s\n", i->n_fd_store, ansi_grey(), i->fd_store_max, ansi_normal());
+ bool show_memory_peak = i->memory_peak != CGROUP_LIMIT_MAX,
+ show_memory_swap_peak = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX);
+
if (i->memory_current != UINT64_MAX) {
printf(" Memory: %s", FORMAT_BYTES(i->memory_current));
- /* Only show current swap if it ever was non-zero or is currently non-zero. In both cases
- memory_swap_peak will be non-zero (and not CGROUP_LIMIT_MAX).
- Only show the available memory if it was artificially limited. */
- bool show_memory_swap = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX),
- show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX),
- show_memory_available = i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX;
- if (i->memory_peak != CGROUP_LIMIT_MAX ||
- show_memory_swap ||
+ bool show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX),
+ /* Only show the available memory if it was artificially limited. */
+ show_memory_available = i->memory_available != CGROUP_LIMIT_MAX &&
+ (i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX);
+ if (show_memory_peak ||
+ show_memory_swap_peak || /* We don't need to check memory_swap_current, as if peak is 0 that must also be 0 */
show_memory_zswap_current ||
show_memory_available ||
i->memory_min > 0 ||
@@ -722,7 +728,6 @@ static void print_status_info(
i->memory_max != CGROUP_LIMIT_MAX || i->startup_memory_max != CGROUP_LIMIT_MAX ||
i->memory_swap_max != CGROUP_LIMIT_MAX || i->startup_memory_swap_max != CGROUP_LIMIT_MAX ||
i->memory_zswap_max != CGROUP_LIMIT_MAX || i->startup_memory_zswap_max != CGROUP_LIMIT_MAX ||
- i->memory_available != CGROUP_LIMIT_MAX ||
i->memory_limit != CGROUP_LIMIT_MAX) {
const char *prefix = "";
@@ -779,11 +784,11 @@ static void print_status_info(
printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available));
prefix = " ";
}
- if (i->memory_peak != CGROUP_LIMIT_MAX) {
+ if (show_memory_peak) {
printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak));
prefix = " ";
}
- if (show_memory_swap) {
+ if (show_memory_swap_peak) {
printf("%sswap: %s swap peak: %s", prefix,
FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak));
prefix = " ";
@@ -795,6 +800,14 @@ static void print_status_info(
printf(")");
}
printf("\n");
+
+ } else if (show_memory_peak) {
+ printf(" Mem peak: %s", FORMAT_BYTES(i->memory_peak));
+
+ if (show_memory_swap_peak)
+ printf(" (swap: %s)", FORMAT_BYTES(i->memory_swap_peak));
+
+ putchar('\n');
}
if (i->cpu_usage_nsec != UINT64_MAX)
@@ -834,10 +847,9 @@ static void print_status_info(
i->id,
i->log_namespace,
arg_output,
- 0,
+ /* n_columns = */ 0,
i->inactive_exit_timestamp_monotonic,
arg_lines,
- getuid(),
get_output_flags() | OUTPUT_BEGIN_NEWLINE,
SD_JOURNAL_LOCAL_ONLY,
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM,
@@ -922,11 +934,7 @@ static int map_listen(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus
while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0) {
- r = strv_extend(p, type);
- if (r < 0)
- return r;
-
- r = strv_extend(p, path);
+ r = strv_extend_many(p, type, path);
if (r < 0)
return r;
}
@@ -2025,8 +2033,9 @@ static int show_one(
{ "InactiveExitTimestampMonotonic", "t", NULL, offsetof(UnitStatusInfo, inactive_exit_timestamp_monotonic) },
{ "ActiveEnterTimestamp", "t", NULL, offsetof(UnitStatusInfo, active_enter_timestamp) },
{ "ActiveExitTimestamp", "t", NULL, offsetof(UnitStatusInfo, active_exit_timestamp) },
- { "RuntimeMaxUSec", "t", NULL, offsetof(UnitStatusInfo, runtime_max_sec) },
{ "InactiveEnterTimestamp", "t", NULL, offsetof(UnitStatusInfo, inactive_enter_timestamp) },
+ { "RuntimeMaxUSec", "t", NULL, offsetof(UnitStatusInfo, runtime_max_sec) },
+ { "InvocationID", "s", bus_map_id128, offsetof(UnitStatusInfo, invocation_id) },
{ "NeedDaemonReload", "b", NULL, offsetof(UnitStatusInfo, need_daemon_reload) },
{ "Transient", "b", NULL, offsetof(UnitStatusInfo, transient) },
{ "ExecMainPID", "u", NULL, offsetof(UnitStatusInfo, main_pid) },
@@ -2194,96 +2203,6 @@ static int show_one(
return 0;
}
-static int get_unit_dbus_path_by_pid_fallback(
- sd_bus *bus,
- uint32_t pid,
- char **ret_path,
- char **ret_unit) {
-
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_free_ char *path = NULL, *unit = NULL;
- char *p;
- int r;
-
- assert(bus);
- assert(ret_path);
- assert(ret_unit);
-
- r = bus_call_method(bus, bus_systemd_mgr, "GetUnitByPID", &error, &reply, "u", pid);
- if (r < 0)
- return log_error_errno(r, "Failed to get unit for PID %"PRIu32": %s", pid, bus_error_message(&error, r));
-
- r = sd_bus_message_read(reply, "o", &p);
- if (r < 0)
- return bus_log_parse_error(r);
-
- path = strdup(p);
- if (!path)
- return log_oom();
-
- r = unit_name_from_dbus_path(path, &unit);
- if (r < 0)
- return log_oom();
-
- *ret_unit = TAKE_PTR(unit);
- *ret_path = TAKE_PTR(path);
-
- return 0;
-}
-
-static int get_unit_dbus_path_by_pid(
- sd_bus *bus,
- uint32_t pid,
- char **ret_path,
- char **ret_unit) {
-
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_free_ char *path = NULL, *unit = NULL;
- _cleanup_close_ int pidfd = -EBADF;
- char *p, *u;
- int r;
-
- assert(bus);
- assert(ret_path);
- assert(ret_unit);
-
- /* First, try to send a PIDFD across the wire, so that we can pin the process and there's no race
- * condition possible while we wait for the D-Bus reply. If we either don't have PIDFD support in
- * the kernel or the new D-Bus method is not available, then fallback to the older method that
- * sends the numeric PID. */
-
- pidfd = pidfd_open(pid, 0);
- if (pidfd < 0 && (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)))
- return get_unit_dbus_path_by_pid_fallback(bus, pid, ret_path, ret_unit);
- if (pidfd < 0)
- return log_error_errno(errno, "Failed to open PID %"PRIu32": %m", pid);
-
- r = bus_call_method(bus, bus_systemd_mgr, "GetUnitByPIDFD", &error, &reply, "h", pidfd);
- if (r < 0 && sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD))
- return get_unit_dbus_path_by_pid_fallback(bus, pid, ret_path, ret_unit);
- if (r < 0)
- return log_error_errno(r, "Failed to get unit for PID %"PRIu32": %s", pid, bus_error_message(&error, r));
-
- r = sd_bus_message_read(reply, "os", &p, &u);
- if (r < 0)
- return bus_log_parse_error(r);
-
- path = strdup(p);
- if (!path)
- return log_oom();
-
- unit = strdup(u);
- if (!unit)
- return log_oom();
-
- *ret_unit = TAKE_PTR(unit);
- *ret_path = TAKE_PTR(path);
-
- return 0;
-}
-
static int show_all(
sd_bus *bus,
SystemctlShowMode show_mode,
@@ -2455,9 +2374,9 @@ int verb_show(int argc, char *argv[], void *userdata) {
} else {
/* Interpret as PID */
- r = get_unit_dbus_path_by_pid(bus, id, &path, &unit);
+ r = lookup_unit_by_pidref(bus, (pid_t) id, &unit, &path);
if (r < 0) {
- ret = r;
+ RET_GATHER(ret, r);
continue;
}
}