summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-04-27 14:22:34 +0900
committerLennart Poettering <lennart@poettering.net>2021-04-28 17:36:09 +0200
commit255b1fc8a3055a7d59946a0fc483ee3885740398 (patch)
tree7c7d5ee14440f44c5fcbc548c9e8953e8834f8a5 /src/systemctl
parentfeb10c665f8cdd8bd1cc12a4584910ad702c1b5a (diff)
downloadsystemd-255b1fc8a3055a7d59946a0fc483ee3885740398.tar.gz
bus-print-property: introduce BusPrintPropertyFlags
Follow-ups for 1ceaad69378272c64da4ecaab0d59ebb7a92ca0a.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-show.c95
-rw-r--r--src/systemctl/systemctl.c9
-rw-r--r--src/systemctl/systemctl.h3
3 files changed, 52 insertions, 55 deletions
diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c
index 37b1672d5d..912c07a044 100644
--- a/src/systemctl/systemctl-show.c
+++ b/src/systemctl/systemctl-show.c
@@ -39,7 +39,7 @@
static OutputFlags get_output_flags(void) {
return
- arg_all * OUTPUT_SHOW_ALL |
+ FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
(arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR |
!arg_quiet * OUTPUT_WARN_CUTOFF;
@@ -955,7 +955,7 @@ static int map_exec(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_e
return 0;
}
-static int print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
+static int print_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
char bus_type;
const char *contents;
int r;
@@ -980,9 +980,9 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return r;
if (i >= 0 && i <= 255)
- bus_print_property_valuef(name, expected_value, value, "%"PRIi32, i);
- else if (all)
- bus_print_property_value(name, expected_value, value, "[not set]");
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIi32, i);
+ else if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY))
+ bus_print_property_value(name, expected_value, flags, "[not set]");
return 1;
} else if (streq(name, "NUMAPolicy")) {
@@ -992,7 +992,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return r;
- bus_print_property_valuef(name, expected_value, value, "%s", strna(mpol_to_string(i)));
+ bus_print_property_valuef(name, expected_value, flags, "%s", strna(mpol_to_string(i)));
return 1;
}
@@ -1008,9 +1008,9 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
if (u > 0)
- bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
- else if (all)
- bus_print_property_value(name, expected_value, value, "");
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIu32, u);
+ else
+ bus_print_property_value(name, expected_value, flags, NULL);
return 1;
@@ -1021,8 +1021,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(s))
- bus_print_property_value(name, expected_value, value, s);
+ bus_print_property_value(name, expected_value, flags, s);
return 1;
@@ -1034,9 +1033,9 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
if (!isempty(a) || !isempty(b))
- bus_print_property_valuef(name, expected_value, value, "%s \"%s\"", strempty(a), strempty(b));
- else if (all)
- bus_print_property_value(name, expected_value, value, "");
+ bus_print_property_valuef(name, expected_value, flags, "%s \"%s\"", strempty(a), strempty(b));
+ else
+ bus_print_property_value(name, expected_value, flags, NULL);
return 1;
@@ -1060,11 +1059,11 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || allow_list || !strv_isempty(l)) {
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || allow_list || !strv_isempty(l)) {
bool first = true;
char **i;
- if (!value) {
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
fputs(name, stdout);
fputc('=', stdout);
}
@@ -1094,9 +1093,9 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
if (!isempty(s))
- bus_print_property_valuef(name, expected_value, value, "%s%s", ignore ? "-" : "", s);
- else if (all)
- bus_print_property_value(name, expected_value, value, "");
+ bus_print_property_valuef(name, expected_value, flags, "%s%s", ignore ? "-" : "", s);
+ else
+ bus_print_property_value(name, expected_value, flags, NULL);
return 1;
@@ -1123,10 +1122,10 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
n_status /= sizeof(int32_t);
n_signal /= sizeof(int32_t);
- if (all || n_status > 0 || n_signal > 0) {
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || n_status > 0 || n_signal > 0) {
bool first = true;
- if (!value) {
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
fputs(name, stdout);
fputc('=', stdout);
}
@@ -1174,8 +1173,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(sb)", &path, &ignore)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s (ignore_errors=%s)", path, yes_no(ignore));
-
+ bus_print_property_valuef(name, expected_value, flags, "%s (ignore_errors=%s)", path, yes_no(ignore));
if (r < 0)
return bus_log_parse_error(r);
@@ -1193,7 +1191,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s (%s)", path, type);
+ bus_print_property_valuef(name, expected_value, flags, "%s (%s)", path, type);
if (r < 0)
return bus_log_parse_error(r);
@@ -1211,7 +1209,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s (%s)", path, type);
+ bus_print_property_valuef(name, expected_value, flags, "%s (%s)", path, type);
if (r < 0)
return bus_log_parse_error(r);
@@ -1235,7 +1233,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
(void) format_timespan(timespan1, sizeof timespan1, v, 0);
(void) format_timespan(timespan2, sizeof timespan2, next_elapse, 0);
- bus_print_property_valuef(name, expected_value, value,
+ bus_print_property_valuef(name, expected_value, flags,
"{ %s=%s ; next_elapse=%s }", base, timespan1, timespan2);
}
if (r < 0)
@@ -1259,7 +1257,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
char timestamp[FORMAT_TIMESTAMP_MAX] = "n/a";
(void) format_timestamp_style(timestamp, sizeof(timestamp), next_elapse, arg_timestamp_style);
- bus_print_property_valuef(name, expected_value, value,
+ bus_print_property_valuef(name, expected_value, flags,
"{ %s=%s ; next_elapse=%s }", base, spec, timestamp);
}
if (r < 0)
@@ -1293,7 +1291,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
o = strv_join(optv, " ");
- bus_print_property_valuef(name, expected_value, value,
+ bus_print_property_valuef(name, expected_value, flags,
"{ path=%s ; argv[]=%s ; flags=%s ; start_time=[%s] ; stop_time=[%s] ; pid="PID_FMT" ; code=%s ; status=%i%s%s }",
strna(info.path),
strna(tt),
@@ -1306,7 +1304,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
info.code == CLD_EXITED ? "" : "/",
strempty(info.code == CLD_EXITED ? NULL : signal_to_string(info.status)));
} else
- bus_print_property_valuef(name, expected_value, value,
+ bus_print_property_valuef(name, expected_value, flags,
"{ path=%s ; argv[]=%s ; ignore_errors=%s ; start_time=[%s] ; stop_time=[%s] ; pid="PID_FMT" ; code=%s ; status=%i%s%s }",
strna(info.path),
strna(tt),
@@ -1338,7 +1336,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(ss)", &path, &rwm)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s %s", strna(path), strna(rwm));
+ bus_print_property_valuef(name, expected_value, flags, "%s %s", strna(path), strna(rwm));
if (r < 0)
return bus_log_parse_error(r);
@@ -1358,7 +1356,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(st)", &path, &weight)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s %"PRIu64, strna(path), weight);
+ bus_print_property_valuef(name, expected_value, flags, "%s %"PRIu64, strna(path), weight);
if (r < 0)
return bus_log_parse_error(r);
@@ -1379,7 +1377,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(st)", &path, &bandwidth)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s %"PRIu64, strna(path), bandwidth);
+ bus_print_property_valuef(name, expected_value, flags, "%s %"PRIu64, strna(path), bandwidth);
if (r < 0)
return bus_log_parse_error(r);
@@ -1400,7 +1398,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(st)", &path, &target)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s %s", strna(path),
+ bus_print_property_valuef(name, expected_value, flags, "%s %s", strna(path),
format_timespan(ts, sizeof(ts), target, 1));
if (r < 0)
return bus_log_parse_error(r);
@@ -1425,8 +1423,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (n < 0)
return log_oom();
- if (all || !isempty(h))
- bus_print_property_value(name, expected_value, value, h);
+ bus_print_property_value(name, expected_value, flags, h);
return 1;
@@ -1486,8 +1483,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(addresses))
- bus_print_property_value(name, expected_value, value, strempty(addresses));
+ bus_print_property_value(name, expected_value, flags, addresses);
return 1;
@@ -1525,8 +1521,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(paths))
- bus_print_property_value(name, expected_value, value, strempty(paths));
+ bus_print_property_value(name, expected_value, flags, paths);
return 1;
@@ -1557,8 +1552,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(paths))
- bus_print_property_value(name, expected_value, value, strempty(paths));
+ bus_print_property_value(name, expected_value, flags, paths);
return 1;
@@ -1605,11 +1599,14 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(fields))
- bus_print_property_value(name, expected_value, value, strempty(fields));
+ bus_print_property_value(name, expected_value, flags, fields);
return 1;
- } else if (contents[0] == SD_BUS_TYPE_BYTE && STR_IN_SET(name, "CPUAffinity", "NUMAMask", "AllowedCPUs", "AllowedMemoryNodes", "EffectiveCPUs", "EffectiveMemoryNodes")) {
+ } else if (contents[0] == SD_BUS_TYPE_BYTE &&
+ STR_IN_SET(name,
+ "CPUAffinity", "NUMAMask", "AllowedCPUs", "AllowedMemoryNodes",
+ "EffectiveCPUs", "EffectiveMemoryNodes")) {
+
_cleanup_free_ char *affinity = NULL;
_cleanup_(cpu_set_reset) CPUSet set = {};
const void *a;
@@ -1627,8 +1624,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (!affinity)
return log_oom();
- if (all || !isempty(affinity))
- bus_print_property_value(name, expected_value, value, affinity);
+ bus_print_property_value(name, expected_value, flags, affinity);
return 1;
} else if (streq(name, "MountImages")) {
@@ -1691,8 +1687,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(paths))
- bus_print_property_value(name, expected_value, value, strempty(paths));
+ bus_print_property_value(name, expected_value, flags, paths);
return 1;
@@ -1704,7 +1699,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(ss)", &a, &p)) > 0)
- bus_print_property_valuef(name, expected_value, value, "%s:%s", a, p);
+ bus_print_property_valuef(name, expected_value, flags, "%s:%s", a, p);
if (r < 0)
return bus_log_parse_error(r);
@@ -1935,7 +1930,7 @@ static int show_one(
if (r < 0)
return log_error_errno(r, "Failed to rewind: %s", bus_error_message(&error, r));
- r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_value, arg_all, &found_properties);
+ r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags, &found_properties);
if (r < 0)
return bus_log_parse_error(r);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index bcc5f896b9..16c1f39440 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -75,7 +75,7 @@ bool arg_no_wtmp = false;
bool arg_no_sync = false;
bool arg_no_wall = false;
bool arg_no_reload = false;
-bool arg_value = false;
+BusPrintPropertyFlags arg_print_flags = 0;
bool arg_show_types = false;
int arg_check_inhibitors = -1;
bool arg_dry_run = false;
@@ -541,7 +541,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case 'P':
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
_fallthrough_;
case 'p':
@@ -566,11 +566,12 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
}
/* If the user asked for a particular property, show it, even if it is empty. */
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
case 'a':
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
arg_all = true;
break;
@@ -593,7 +594,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case ARG_JOB_MODE:
diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h
index 3a3ff9ac10..ed8152e3dd 100644
--- a/src/systemctl/systemctl.h
+++ b/src/systemctl/systemctl.h
@@ -3,6 +3,7 @@
#include <stdbool.h>
+#include "bus-print-properties.h"
#include "bus-util.h"
#include "install.h"
#include "output-mode.h"
@@ -58,7 +59,7 @@ extern bool arg_no_wtmp;
extern bool arg_no_sync;
extern bool arg_no_wall;
extern bool arg_no_reload;
-extern bool arg_value;
+extern BusPrintPropertyFlags arg_print_flags;
extern bool arg_show_types;
extern int arg_check_inhibitors;
extern bool arg_dry_run;