#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;
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;
}
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;
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;
"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;
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) {
space = true;
}
- if (space || !value)
+ if (space || !FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("\n");
if (r < 0)
path,
print_property,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
return version();
case 'P':
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
_fallthrough_;
case 'p': {
/* 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':
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;
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;
*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");
*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");
/* 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':
#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;
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;
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;
}
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;
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;
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;
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) ||
(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;
}
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;
}
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;
}
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;
}
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;
}
return -ENOMEM;
if (first) {
- if (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
first = false;
} else
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);
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++)
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++)
sd_bus_message *m,
bus_message_print_t func,
char **filter,
- bool value,
- bool all,
+ BusPrintPropertyFlags flags,
Set **found_properties) {
int r;
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);
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;
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);
}
#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);
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;
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;
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")) {
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;
}
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;
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;
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;
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);
}
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;
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);
}
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);
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);
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);
(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)
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)
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),
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),
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);
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);
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);
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);
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;
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;
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;
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;
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;
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")) {
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;
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);
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);
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;
break;
case 'P':
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
_fallthrough_;
case 'p':
}
/* 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;
break;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case ARG_JOB_MODE:
#include <stdbool.h>
+#include "bus-print-properties.h"
#include "bus-util.h"
#include "install.h"
#include "output-mode.h"
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;
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;
"/org/freedesktop/timedate1",
NULL,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
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;
if (i.packet_count == 0)
return 1;
- if (!value) {
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
fputs(name, stdout);
fputc('=', stdout);
}
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;
}
"/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);
/* 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 '?':