mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
systemctl: refactor show()
v2, don't leave in unused function
This commit is contained in:
parent
6a44e50f4c
commit
f74294c1da
@ -3604,16 +3604,13 @@ static int show_one(
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_one_by_pid(
|
static int get_unit_dbus_path_by_pid(
|
||||||
const char *verb,
|
|
||||||
sd_bus *bus,
|
sd_bus *bus,
|
||||||
uint32_t pid,
|
uint32_t pid,
|
||||||
bool *new_line,
|
char **unit) {
|
||||||
bool *ellipsized) {
|
|
||||||
|
|
||||||
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
|
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
|
||||||
const char *path = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = sd_bus_call_method(
|
r = sd_bus_call_method(
|
||||||
@ -3630,11 +3627,11 @@ static int show_one_by_pid(
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sd_bus_message_read(reply, "o", &path);
|
r = sd_bus_message_read(reply, "o", unit);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return bus_log_parse_error(r);
|
return bus_log_parse_error(r);
|
||||||
|
|
||||||
return show_one(verb, bus, path, false, new_line, ellipsized);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_all(
|
static int show_all(
|
||||||
@ -3702,41 +3699,34 @@ static int show(sd_bus *bus, char **args) {
|
|||||||
ret = show_all(args[0], bus, false, &new_line, &ellipsized);
|
ret = show_all(args[0], bus, false, &new_line, &ellipsized);
|
||||||
else
|
else
|
||||||
STRV_FOREACH(name, args+1) {
|
STRV_FOREACH(name, args+1) {
|
||||||
|
_cleanup_free_ char *unit = NULL;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
||||||
if (safe_atou32(*name, &id) < 0) {
|
if (safe_atou32(*name, &id) < 0) {
|
||||||
_cleanup_free_ char *p = NULL, *n = NULL;
|
_cleanup_free_ char *n = NULL;
|
||||||
/* Interpret as unit name */
|
/* Interpret as unit name */
|
||||||
|
|
||||||
n = unit_name_mangle(*name);
|
n = unit_name_mangle(*name);
|
||||||
if (!n)
|
if (!n)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
p = unit_dbus_path_from_name(n);
|
unit = unit_dbus_path_from_name(n);
|
||||||
if (!p)
|
if (!unit)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
|
|
||||||
if (r != 0)
|
|
||||||
ret = r;
|
|
||||||
|
|
||||||
} else if (show_properties) {
|
} else if (show_properties) {
|
||||||
_cleanup_free_ char *p = NULL;
|
|
||||||
|
|
||||||
/* Interpret as job id */
|
/* Interpret as job id */
|
||||||
if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0)
|
if (asprintf(&unit, "/org/freedesktop/systemd1/job/%u", id) < 0)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
r = show_one(args[0], bus, p, show_properties, &new_line, &ellipsized);
|
|
||||||
if (r != 0)
|
|
||||||
ret = r;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Interpret as PID */
|
/* Interpret as PID */
|
||||||
r = show_one_by_pid(args[0], bus, id, &new_line, &ellipsized);
|
r = get_unit_dbus_path_by_pid(bus, id, &unit);
|
||||||
if (r != 0)
|
if (r < 0)
|
||||||
ret = r;
|
ret = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ellipsized && !arg_quiet)
|
if (ellipsized && !arg_quiet)
|
||||||
|
Loading…
Reference in New Issue
Block a user