return 0;
}
-#define property(name, fmt, ...) \
- do { \
- if (value) \
- printf(fmt "\n", __VA_ARGS__); \
- else \
- printf("%s=" fmt "\n", name, __VA_ARGS__); \
- } while (0)
-
-static int print_property(const char *name, sd_bus_message *m, bool value, bool all) {
+static int print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
char type;
const char *contents;
int r;
return bus_log_parse_error(r);
if (all || !isempty(s))
- property(name, "%s", s);
+ bus_print_property_value(name, expected_value, value, "%s", s);
return 1;
return -EINVAL;
}
- property(name, UID_FMT, uid);
+ bus_print_property_value(name, expected_value, value, UID_FMT, uid);
return 1;
}
break;
return 0;
}
-#define print_property(name, fmt, ...) \
- do { \
- if (value) \
- printf(fmt "\n", __VA_ARGS__); \
- else \
- printf("%s=" fmt "\n", name, __VA_ARGS__); \
- } while (0)
-
-int bus_print_property(const char *name, sd_bus_message *m, bool value, bool all) {
+int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) {
+ 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);
+ va_end(ap);
+ puts("");
+
+ return 0;
+}
+
+static int bus_print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
char type;
const char *contents;
int r;
/* 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');
- print_property(name, "%s", good ? s : "[unprintable]");
+ bus_print_property_value(name, expected_value, value, "%s", good ? s : "[unprintable]");
}
return 1;
if (r < 0)
return r;
- print_property(name, "%s", yes_no(b));
+ if (expected_value && parse_boolean(expected_value) != b)
+ return 1;
+ bus_print_property_value(name, NULL, value, "%s", yes_no(b));
return 1;
}
t = format_timestamp(timestamp, sizeof(timestamp), u);
if (t || all)
- print_property(name, "%s", strempty(t));
+ bus_print_property_value(name, expected_value, value, "%s", strempty(t));
} else if (strstr(name, "USec")) {
char timespan[FORMAT_TIMESPAN_MAX];
- print_property(name, "%s", format_timespan(timespan, sizeof(timespan), u, 0));
+ (void) format_timespan(timespan, sizeof(timespan), u, 0);
+ bus_print_property_value(name, expected_value, value, "%s", timespan);
+
} else if (streq(name, "RestrictNamespaces")) {
_cleanup_free_ char *s = NULL;
const char *result;
result = s;
}
- print_property(name, "%s", result);
+ bus_print_property_value(name, expected_value, value, "%s", result);
} else if (streq(name, "MountFlags")) {
const char *result;
if (!result)
return -EINVAL;
- print_property(name, "%s", result);
+ bus_print_property_value(name, expected_value, value, "%s", result);
} else if (STR_IN_SET(name, "CapabilityBoundingSet", "AmbientCapabilities")) {
_cleanup_free_ char *s = NULL;
if (r < 0)
return r;
- print_property(name, "%s", s);
+ bus_print_property_value(name, expected_value, value, "%s", 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_t) -1) ||
(endswith(name, "NSec") && u == (uint64_t) -1))
- print_property(name, "%s", "[not set]");
+ bus_print_property_value(name, expected_value, value, "%s", "[not set]");
else if ((STR_IN_SET(name, "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryLimit") && u == CGROUP_LIMIT_MAX) ||
(STR_IN_SET(name, "TasksMax", "DefaultTasksMax") && u == (uint64_t) -1) ||
(startswith(name, "Limit") && u == (uint64_t) -1) ||
(startswith(name, "DefaultLimit") && u == (uint64_t) -1))
- print_property(name, "%s", "infinity");
+ bus_print_property_value(name, expected_value, value, "%s", "infinity");
else
- print_property(name, "%"PRIu64, u);
+ bus_print_property_value(name, expected_value, value, "%"PRIu64, u);
return 1;
}
if (r < 0)
return r;
- print_property(name, "%"PRIi64, i);
-
+ bus_print_property_value(name, expected_value, value, "%"PRIi64, i);
return 1;
}
return r;
if (strstr(name, "UMask") || strstr(name, "Mode"))
- print_property(name, "%04o", u);
+ bus_print_property_value(name, expected_value, value, "%04o", u);
+
else if (streq(name, "UID")) {
if (u == UID_INVALID)
- print_property(name, "%s", "[not set]");
+ bus_print_property_value(name, expected_value, value, "%s", "[not set]");
else
- print_property(name, "%"PRIu32, u);
+ bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
} else if (streq(name, "GID")) {
if (u == GID_INVALID)
- print_property(name, "%s", "[not set]");
+ bus_print_property_value(name, expected_value, value, "%s", "[not set]");
else
- print_property(name, "%"PRIu32, u);
+ bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
} else
- print_property(name, "%"PRIu32, u);
+ bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
return 1;
}
if (r < 0)
return r;
- print_property(name, "%"PRIi32, i);
+ bus_print_property_value(name, expected_value, value, "%"PRIi32, i);
return 1;
}
if (r < 0)
return r;
- print_property(name, "%g", d);
+ bus_print_property_value(name, expected_value, value, "%g", d);
return 1;
}
return r;
while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
- const char *name;
- const char *contents;
+ _cleanup_free_ char *name_with_equal = NULL;
+ const char *name, *contents, *expected_value = NULL;
r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &name);
if (r < 0)
return log_oom();
}
- if (!filter || strv_find(filter, name)) {
+ name_with_equal = strappend(name, "=");
+ if (!name_with_equal)
+ return log_oom();
+
+ if (!filter || strv_find(filter, name) ||
+ (expected_value = strv_find_startswith(filter, name_with_equal))) {
r = sd_bus_message_peek_type(m, NULL, &contents);
if (r < 0)
return r;
return r;
if (func)
- r = func(name, m, value, all);
+ r = func(name, expected_value, m, value, all);
if (!func || r == 0)
- r = bus_print_property(name, m, value, all);
+ r = bus_print_property(name, expected_value, m, value, all);
if (r < 0)
return r;
if (r == 0) {
- if (all)
+ if (all && !expected_value)
printf("%s=[unprintable]\n", name);
/* skip what we didn't read */
r = sd_bus_message_skip(m, contents);
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
-typedef int (*bus_message_print_t) (const char *name, sd_bus_message *m, bool value, bool all);
+typedef int (*bus_message_print_t) (const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all);
-int bus_print_property(const char *name, sd_bus_message *property, bool value, bool all);
+int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *fmt, ...);
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);
return 0;
}
-#define print_prop(name, fmt, ...) \
- do { \
- if (arg_value) \
- printf(fmt "\n", __VA_ARGS__); \
- else \
- printf("%s=" fmt "\n", name, __VA_ARGS__); \
- } while (0)
-
-static int print_property(const char *name, sd_bus_message *m, bool value, bool all) {
+static int print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
char bus_type;
const char *contents;
int r;
return bus_log_parse_error(r);
if (u > 0)
- print_prop(name, "%"PRIu32, u);
+ bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
else if (all)
- print_prop(name, "%s", "");
+ bus_print_property_value(name, expected_value, value, "%s", "");
return 1;
return bus_log_parse_error(r);
if (all || !isempty(s))
- print_prop(name, "%s", s);
+ bus_print_property_value(name, expected_value, value, "%s", s);
return 1;
return bus_log_parse_error(r);
if (all || !isempty(a) || !isempty(b))
- print_prop(name, "%s \"%s\"", strempty(a), strempty(b));
+ bus_print_property_value(name, expected_value, value, "%s \"%s\"", strempty(a), strempty(b));
return 1;
} else if (streq_ptr(name, "SystemCallFilter")) {
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(sb)", &path, &ignore)) > 0)
- print_prop(name, "%s (ignore_errors=%s)", path, yes_no(ignore));
+ bus_print_property_value(name, expected_value, value, "%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)
- print_prop(name, "%s (%s)", path, type);
+ bus_print_property_value(name, expected_value, value, "%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)
- print_prop(name, "%s (%s)", path, type);
+ bus_print_property_value(name, expected_value, value, "%s (%s)", path, type);
if (r < 0)
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(stt)", &base, &v, &next_elapse)) > 0) {
char timespan1[FORMAT_TIMESPAN_MAX], timespan2[FORMAT_TIMESPAN_MAX];
- print_prop(name, "{ %s=%s ; next_elapse=%s }", base,
- format_timespan(timespan1, sizeof(timespan1), v, 0),
- format_timespan(timespan2, sizeof(timespan2), next_elapse, 0));
+ bus_print_property_value(name, expected_value, value, "{ %s=%s ; next_elapse=%s }", base,
+ format_timespan(timespan1, sizeof(timespan1), v, 0),
+ format_timespan(timespan2, sizeof(timespan2), next_elapse, 0));
}
if (r < 0)
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(sst)", &base, &spec, &next_elapse)) > 0) {
char timestamp[FORMAT_TIMESTAMP_MAX];
- print_prop(name, "{ %s=%s ; next_elapse=%s }", base, spec,
- format_timestamp(timestamp, sizeof(timestamp), next_elapse));
+ bus_print_property_value(name, expected_value, value, "{ %s=%s ; next_elapse=%s }", base, spec,
+ format_timestamp(timestamp, sizeof(timestamp), next_elapse));
}
if (r < 0)
return bus_log_parse_error(r);
tt = strv_join(info.argv, " ");
- print_prop(name,
- "{ 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),
- yes_no(info.ignore),
- strna(format_timestamp(timestamp1, sizeof(timestamp1), info.start_timestamp)),
- strna(format_timestamp(timestamp2, sizeof(timestamp2), info.exit_timestamp)),
- info.pid,
- sigchld_code_to_string(info.code),
- info.status,
- info.code == CLD_EXITED ? "" : "/",
- strempty(info.code == CLD_EXITED ? NULL : signal_to_string(info.status)));
+ bus_print_property_value(name, expected_value, value,
+ "{ 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),
+ yes_no(info.ignore),
+ strna(format_timestamp(timestamp1, sizeof(timestamp1), info.start_timestamp)),
+ strna(format_timestamp(timestamp2, sizeof(timestamp2), info.exit_timestamp)),
+ info.pid,
+ sigchld_code_to_string(info.code),
+ info.status,
+ info.code == CLD_EXITED ? "" : "/",
+ strempty(info.code == CLD_EXITED ? NULL : signal_to_string(info.status)));
free(info.path);
strv_free(info.argv);
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(ss)", &path, &rwm)) > 0)
- print_prop(name, "%s %s", strna(path), strna(rwm));
+ bus_print_property_value(name, expected_value, value, "%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)
- print_prop(name, "%s %"PRIu64, strna(path), weight);
+ bus_print_property_value(name, expected_value, value, "%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)
- print_prop(name, "%s %"PRIu64, strna(path), bandwidth);
+ bus_print_property_value(name, expected_value, value, "%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)
- print_prop(name, "%s %s", strna(path),
- format_timespan(ts, sizeof(ts), target, 1));
+ bus_print_property_value(name, expected_value, value, "%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();
- print_prop(name, "%s", h);
+ bus_print_property_value(name, expected_value, value, "%s", h);
return 1;
}
return 0;
}
-#define property(name, fmt, ...) \
- do { \
- if (value) \
- printf(fmt "\n", __VA_ARGS__); \
- else \
- printf("%s=" fmt "\n", name, __VA_ARGS__); \
- } while (0)
-
-static int print_timesync_property(const char *name, sd_bus_message *m, bool value, bool all) {
+static int print_timesync_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
char type;
const char *contents;
int r;
return r;
if (arg_all || !isempty(str))
- property(name, "%s", str);
+ bus_print_property_value(name, expected_value, value, "%s", str);
return 1;
}