summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-04-27 07:22:34 +0200
committerLennart Poettering <lennart@poettering.net>2021-04-28 17:36:09 +0200
commit255b1fc8a3055a7d59946a0fc483ee3885740398 (patch)
tree7c7d5ee14440f44c5fcbc548c9e8953e8834f8a5
parentdocs: document that one shouldn't pass the audit caps to containers (diff)
downloadsystemd-255b1fc8a3055a7d59946a0fc483ee3885740398.tar.xz
systemd-255b1fc8a3055a7d59946a0fc483ee3885740398.zip
bus-print-property: introduce BusPrintPropertyFlags
Follow-ups for 1ceaad69378272c64da4ecaab0d59ebb7a92ca0a.
-rw-r--r--src/login/loginctl.c27
-rw-r--r--src/machine/machinectl.c13
-rw-r--r--src/shared/bus-print-properties.c128
-rw-r--r--src/shared/bus-print-properties.h15
-rw-r--r--src/systemctl/systemctl-show.c95
-rw-r--r--src/systemctl/systemctl.c9
-rw-r--r--src/systemctl/systemctl.h3
-rw-r--r--src/timedate/timedatectl.c22
8 files changed, 142 insertions, 170 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 4ece3fda58..7a2b13e442 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -39,8 +39,7 @@
#include "verbs.h"
static char **arg_property = NULL;
-static bool arg_all = false;
-static bool arg_value = false;
+static BusPrintPropertyFlags arg_print_flags = 0;
static bool arg_full = false;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
@@ -57,7 +56,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep);
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;
}
@@ -705,7 +704,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line)
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 type;
const char *contents;
int r;
@@ -728,8 +727,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;
@@ -745,7 +743,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
"Invalid user ID: " UID_FMT,
uid);
- bus_print_property_valuef(name, expected_value, value, UID_FMT, uid);
+ bus_print_property_valuef(name, expected_value, flags, UID_FMT, uid);
return 1;
}
break;
@@ -760,7 +758,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 (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
while ((r = sd_bus_message_read(m, "(so)", &s, NULL)) > 0) {
@@ -768,7 +766,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
space = true;
}
- if (space || !value)
+ if (space || !FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("\n");
if (r < 0)
@@ -804,8 +802,7 @@ static int show_properties(sd_bus *bus, const char *path, bool *new_line) {
path,
print_property,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
@@ -1331,7 +1328,7 @@ static int parse_argv(int argc, char *argv[]) {
return version();
case 'P':
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
_fallthrough_;
case 'p': {
@@ -1342,16 +1339,16 @@ static int parse_argv(int argc, char *argv[]) {
/* If the user asked for a particular
* property, show it to them, even if it is
* empty. */
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
}
case 'a':
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case 'l':
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index d7849973b8..15f7d39921 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -63,7 +63,7 @@
static char **arg_property = NULL;
static bool arg_all = false;
-static bool arg_value = false;
+static BusPrintPropertyFlags arg_print_flags = 0;
static bool arg_full = false;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
@@ -89,7 +89,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_setenv, strv_freep);
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;
@@ -689,7 +689,7 @@ static int show_machine_properties(sd_bus *bus, const char *path, bool *new_line
*new_line = true;
- r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, NULL, arg_property, arg_value, arg_all, NULL);
+ r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, NULL, arg_property, arg_print_flags, NULL);
if (r < 0)
log_error_errno(r, "Could not get properties: %m");
@@ -1002,7 +1002,7 @@ static int show_image_properties(sd_bus *bus, const char *path, bool *new_line)
*new_line = true;
- r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, NULL, arg_property, arg_value, arg_all, NULL);
+ r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, NULL, arg_property, arg_print_flags, NULL);
if (r < 0)
log_error_errno(r, "Could not get properties: %m");
@@ -2673,15 +2673,16 @@ static int parse_argv(int argc, char *argv[]) {
/* If the user asked for a particular
* property, show it to them, 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;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case 'l':
diff --git a/src/shared/bus-print-properties.c b/src/shared/bus-print-properties.c
index b4fe8bb038..e4427dbced 100644
--- a/src/shared/bus-print-properties.c
+++ b/src/shared/bus-print-properties.c
@@ -13,57 +13,41 @@
#include "time-util.h"
#include "user-util.h"
-int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value) {
+int bus_print_property_value(const char *name, const char *expected_value, BusPrintPropertyFlags flags, const char *value) {
assert(name);
if (expected_value && !streq_ptr(expected_value, value))
return 0;
- if (only_value)
- puts(value);
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) && isempty(value))
+ return 0;
+
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
+ puts(strempty(value));
else
- printf("%s=%s\n", name, value);
+ printf("%s=%s\n", name, strempty(value));
return 0;
}
-int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) {
+int bus_print_property_valuef(const char *name, const char *expected_value, BusPrintPropertyFlags flags, const char *fmt, ...) {
+ _cleanup_free_ char *s = NULL;
va_list ap;
int r;
assert(name);
assert(fmt);
- if (expected_value) {
- _cleanup_free_ char *s = NULL;
-
- va_start(ap, fmt);
- r = vasprintf(&s, fmt, ap);
- va_end(ap);
- if (r < 0)
- return -ENOMEM;
-
- if (streq_ptr(expected_value, s)) {
- if (only_value)
- puts(s);
- else
- printf("%s=%s\n", name, s);
- }
-
- return 0;
- }
-
- if (!only_value)
- printf("%s=", name);
va_start(ap, fmt);
- vprintf(fmt, ap);
+ r = vasprintf(&s, fmt, ap);
va_end(ap);
- puts("");
+ if (r < 0)
+ return -ENOMEM;
- return 0;
+ return bus_print_property_value(name, expected_value, flags, s);
}
-static int bus_print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
+static int bus_print_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
char type;
const char *contents;
int r;
@@ -84,13 +68,13 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- if (all || !isempty(s)) {
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || !isempty(s)) {
bool good;
/* This property has a single value, so we need to take
* care not to print a new line, everything else is OK. */
good = !strchr(s, '\n');
- bus_print_property_value(name, expected_value, value, good ? s : "[unprintable]");
+ bus_print_property_value(name, expected_value, flags, good ? s : "[unprintable]");
}
return 1;
@@ -106,7 +90,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (expected_value && parse_boolean(expected_value) != b)
return 1;
- bus_print_property_value(name, NULL, value, yes_no(b));
+ bus_print_property_value(name, NULL, flags, yes_no(b));
return 1;
}
@@ -126,22 +110,18 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
const char *t;
t = format_timestamp(timestamp, sizeof(timestamp), u);
- if (t || all)
- bus_print_property_value(name, expected_value, value, strempty(t));
+ bus_print_property_value(name, expected_value, flags, t);
} else if (strstr(name, "USec")) {
char timespan[FORMAT_TIMESPAN_MAX];
(void) format_timespan(timespan, sizeof(timespan), u, 0);
- bus_print_property_value(name, expected_value, value, timespan);
-
- } else if (streq(name, "CoredumpFilter")) {
- char buf[STRLEN("0xFFFFFFFF")];
+ bus_print_property_value(name, expected_value, flags, timespan);
- xsprintf(buf, "0x%"PRIx64, u);
- bus_print_property_value(name, expected_value, value, buf);
+ } else if (streq(name, "CoredumpFilter"))
+ bus_print_property_valuef(name, expected_value, flags, "0x%"PRIx64, u);
- } else if (streq(name, "RestrictNamespaces")) {
+ else if (streq(name, "RestrictNamespaces")) {
_cleanup_free_ char *s = NULL;
const char *result;
@@ -154,10 +134,10 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- result = strempty(s);
+ result = s;
}
- bus_print_property_value(name, expected_value, value, result);
+ bus_print_property_value(name, expected_value, flags, result);
} else if (streq(name, "MountFlags")) {
const char *result;
@@ -166,8 +146,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (!result)
return -EINVAL;
- if (all || !isempty(result))
- bus_print_property_value(name, expected_value, value, result);
+ bus_print_property_value(name, expected_value, flags, result);
} else if (STR_IN_SET(name, "CapabilityBoundingSet", "AmbientCapabilities")) {
_cleanup_free_ char *s = NULL;
@@ -176,8 +155,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- if (all || !isempty(s))
- bus_print_property_value(name, expected_value, value, s);
+ bus_print_property_value(name, expected_value, flags, s);
} else if ((STR_IN_SET(name, "CPUWeight", "StartupCPUWeight", "IOWeight", "StartupIOWeight") && u == CGROUP_WEIGHT_INVALID) ||
(STR_IN_SET(name, "CPUShares", "StartupCPUShares") && u == CGROUP_CPU_SHARES_INVALID) ||
@@ -185,18 +163,18 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
(STR_IN_SET(name, "MemoryCurrent", "TasksCurrent") && u == UINT64_MAX) ||
(endswith(name, "NSec") && u == UINT64_MAX))
- bus_print_property_value(name, expected_value, value, "[not set]");
+ bus_print_property_value(name, expected_value, flags, "[not set]");
else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryLimit") && u == CGROUP_LIMIT_MAX) ||
(STR_IN_SET(name, "TasksMax", "DefaultTasksMax") && u == UINT64_MAX) ||
(startswith(name, "Limit") && u == UINT64_MAX) ||
(startswith(name, "DefaultLimit") && u == UINT64_MAX))
- bus_print_property_value(name, expected_value, value, "infinity");
+ bus_print_property_value(name, expected_value, flags, "infinity");
else if (STR_IN_SET(name, "IPIngressBytes", "IPIngressPackets", "IPEgressBytes", "IPEgressPackets") && u == UINT64_MAX)
- bus_print_property_value(name, expected_value, value, "[no data]");
+ bus_print_property_value(name, expected_value, flags, "[no data]");
else
- bus_print_property_valuef(name, expected_value, value, "%"PRIu64, u);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIu64, u);
return 1;
}
@@ -208,7 +186,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- bus_print_property_valuef(name, expected_value, value, "%"PRIi64, i);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIi64, i);
return 1;
}
@@ -220,20 +198,20 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
return r;
if (strstr(name, "UMask") || strstr(name, "Mode"))
- bus_print_property_valuef(name, expected_value, value, "%04o", u);
+ bus_print_property_valuef(name, expected_value, flags, "%04o", u);
else if (streq(name, "UID")) {
if (u == UID_INVALID)
- bus_print_property_value(name, expected_value, value, "[not set]");
+ bus_print_property_value(name, expected_value, flags, "[not set]");
else
- bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIu32, u);
} else if (streq(name, "GID")) {
if (u == GID_INVALID)
- bus_print_property_value(name, expected_value, value, "[not set]");
+ bus_print_property_value(name, expected_value, flags, "[not set]");
else
- bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIu32, u);
} else
- bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIu32, u);
return 1;
}
@@ -245,7 +223,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- bus_print_property_valuef(name, expected_value, value, "%"PRIi32, i);
+ bus_print_property_valuef(name, expected_value, flags, "%"PRIi32, i);
return 1;
}
@@ -256,7 +234,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- bus_print_property_valuef(name, expected_value, value, "%g", d);
+ bus_print_property_valuef(name, expected_value, flags, "%g", d);
return 1;
}
@@ -277,7 +255,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
return -ENOMEM;
if (first) {
- if (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
first = false;
} else
@@ -288,9 +266,9 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- if (first && all && !value)
+ if (first && FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) && !FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
- if (!first || all)
+ if (!first || FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY))
puts("");
r = sd_bus_message_exit_container(m);
@@ -307,10 +285,10 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- if (all || n > 0) {
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || n > 0) {
unsigned i;
- if (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
for (i = 0; i < n; i++)
@@ -329,10 +307,10 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if (r < 0)
return r;
- if (all || n > 0) {
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || n > 0) {
unsigned i;
- if (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
for (i = 0; i < n; i++)
@@ -354,8 +332,7 @@ int bus_message_print_all_properties(
sd_bus_message *m,
bus_message_print_t func,
char **filter,
- bool value,
- bool all,
+ BusPrintPropertyFlags flags,
Set **found_properties) {
int r;
@@ -395,13 +372,13 @@ int bus_message_print_all_properties(
return r;
if (func)
- r = func(name, expected_value, m, value, all);
+ r = func(name, expected_value, m, flags);
if (!func || r == 0)
- r = bus_print_property(name, expected_value, m, value, all);
+ r = bus_print_property(name, expected_value, m, flags);
if (r < 0)
return r;
if (r == 0) {
- if (all && !expected_value)
+ if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) && !expected_value)
printf("%s=[unprintable]\n", name);
/* skip what we didn't read */
r = sd_bus_message_skip(m, contents);
@@ -438,8 +415,7 @@ int bus_print_all_properties(
const char *path,
bus_message_print_t func,
char **filter,
- bool value,
- bool all,
+ BusPrintPropertyFlags flags,
Set **found_properties) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
@@ -460,5 +436,5 @@ int bus_print_all_properties(
if (r < 0)
return r;
- return bus_message_print_all_properties(reply, func, filter, value, all, found_properties);
+ return bus_message_print_all_properties(reply, func, filter, flags, found_properties);
}
diff --git a/src/shared/bus-print-properties.h b/src/shared/bus-print-properties.h
index a4574758e5..a17875cc47 100644
--- a/src/shared/bus-print-properties.h
+++ b/src/shared/bus-print-properties.h
@@ -8,9 +8,14 @@
#include "macro.h"
#include "set.h"
-typedef int (*bus_message_print_t) (const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all);
+typedef enum BusPrintPropertyFlags {
+ BUS_PRINT_PROPERTY_ONLY_VALUE = 1 << 0, /* e.g. systemctl --value */
+ BUS_PRINT_PROPERTY_SHOW_EMPTY = 1 << 1, /* e.g. systemctl --all */
+} BusPrintPropertyFlags;
-int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value);
-int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) _printf_(4,5);
-int bus_message_print_all_properties(sd_bus_message *m, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);
-int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);
+typedef int (*bus_message_print_t) (const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags);
+
+int bus_print_property_value(const char *name, const char *expected_value, BusPrintPropertyFlags flags, const char *value);
+int bus_print_property_valuef(const char *name, const char *expected_value, BusPrintPropertyFlags flags, const char *fmt, ...) _printf_(4,5);
+int bus_message_print_all_properties(sd_bus_message *m, bus_message_print_t func, char **filter, BusPrintPropertyFlags flags, Set **found_properties);
+int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, bus_message_print_t func, char **filter, BusPrintPropertyFlags flags, Set **found_properties);
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;
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 4cab8acbd9..d31f67f4cb 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -34,8 +34,7 @@ static char *arg_host = NULL;
static bool arg_adjust_system_clock = false;
static bool arg_monitor = false;
static char **arg_property = NULL;
-static bool arg_value = false;
-static bool arg_all = false;
+static BusPrintPropertyFlags arg_print_flags = 0;
typedef struct StatusInfo {
usec_t time;
@@ -210,8 +209,7 @@ static int show_properties(int argc, char **argv, void *userdata) {
"/org/freedesktop/timedate1",
NULL,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
@@ -702,7 +700,7 @@ static int show_timesync_status(int argc, char **argv, void *userdata) {
return 0;
}
-static int print_timesync_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
+static int print_timesync_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
char type;
const char *contents;
int r;
@@ -728,7 +726,7 @@ static int print_timesync_property(const char *name, const char *expected_value,
if (i.packet_count == 0)
return 1;
- if (!value) {
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
fputs(name, stdout);
fputc('=', stdout);
}
@@ -767,8 +765,7 @@ static int print_timesync_property(const char *name, const char *expected_value,
if (r < 0)
return r;
- if (arg_all || !isempty(str))
- bus_print_property_value(name, expected_value, value, str);
+ bus_print_property_value(name, expected_value, flags, str);
return 1;
}
@@ -789,8 +786,7 @@ static int show_timesync(int argc, char **argv, void *userdata) {
"/org/freedesktop/timesync1",
print_timesync_property,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
@@ -997,16 +993,16 @@ static int parse_argv(int argc, char *argv[]) {
/* If the user asked for a particular
* property, show it to them, even if it is
* empty. */
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
}
case 'a':
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case '?':