mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-08-27 21:50:15 +03:00
Merge pull request #11871 from yuwata/systemctl-show-format-unprintable
systemctl: format many entries in 'show' command
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include "macro.h"
|
||||
#include "parse-util.h"
|
||||
#include "random-util.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "util.h"
|
||||
|
||||
bool in4_addr_is_null(const struct in_addr *a) {
|
||||
@ -294,7 +295,7 @@ int in_addr_random_prefix(
|
||||
}
|
||||
|
||||
int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
char *x;
|
||||
_cleanup_free_ char *x = NULL;
|
||||
size_t l;
|
||||
|
||||
assert(u);
|
||||
@ -312,18 +313,50 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l)) {
|
||||
free(x);
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
}
|
||||
|
||||
*ret = x;
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret) {
|
||||
_cleanup_free_ char *x = NULL;
|
||||
char *p;
|
||||
size_t l;
|
||||
|
||||
assert(u);
|
||||
assert(ret);
|
||||
|
||||
if (family == AF_INET)
|
||||
l = INET_ADDRSTRLEN + 3;
|
||||
else if (family == AF_INET6)
|
||||
l = INET6_ADDRSTRLEN + 4;
|
||||
else
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
if (prefixlen > FAMILY_ADDRESS_SIZE(family) * 8)
|
||||
return -EINVAL;
|
||||
|
||||
x = new(char, l);
|
||||
if (!x)
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
|
||||
p = x + strlen(x);
|
||||
l -= strlen(x);
|
||||
(void) strpcpyf(&p, l, "/%u", prefixlen);
|
||||
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
|
||||
_cleanup_free_ char *x = NULL;
|
||||
size_t l;
|
||||
char *x;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
@ -349,14 +382,12 @@ int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifin
|
||||
return -ENOMEM;
|
||||
|
||||
errno = 0;
|
||||
if (!inet_ntop(family, u, x, l)) {
|
||||
free(x);
|
||||
if (!inet_ntop(family, u, x, l))
|
||||
return errno > 0 ? -errno : -EINVAL;
|
||||
}
|
||||
|
||||
sprintf(strchr(x, 0), "%%%i", ifindex);
|
||||
*ret = x;
|
||||
|
||||
*ret = TAKE_PTR(x);
|
||||
return 0;
|
||||
|
||||
fallback:
|
||||
|
@ -37,6 +37,7 @@ int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned
|
||||
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
|
||||
int in_addr_random_prefix(int family, union in_addr_union *u, unsigned prefixlen_fixed_part, unsigned prefixlen);
|
||||
int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
|
||||
int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret);
|
||||
int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret);
|
||||
int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
|
||||
int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret);
|
||||
|
@ -55,7 +55,7 @@ static int property_get_exit_status_set(
|
||||
return r;
|
||||
|
||||
SET_FOREACH(id, status_set->status, i) {
|
||||
int val = PTR_TO_INT(id);
|
||||
int32_t val = PTR_TO_INT(id);
|
||||
|
||||
if (val < 0 || val > 255)
|
||||
continue;
|
||||
@ -74,10 +74,10 @@ static int property_get_exit_status_set(
|
||||
return r;
|
||||
|
||||
SET_FOREACH(id, status_set->signal, i) {
|
||||
int val = PTR_TO_INT(id);
|
||||
int32_t val = PTR_TO_INT(id);
|
||||
const char *str;
|
||||
|
||||
str = signal_to_string(val);
|
||||
str = signal_to_string((int) val);
|
||||
if (!str)
|
||||
continue;
|
||||
|
||||
@ -151,7 +151,7 @@ static int bus_set_transient_exit_status(
|
||||
UnitWriteFlags flags,
|
||||
sd_bus_error *error) {
|
||||
|
||||
const int *status, *signal;
|
||||
const int32_t *status, *signal;
|
||||
size_t sz_status, sz_signal, i;
|
||||
int r;
|
||||
|
||||
@ -171,6 +171,9 @@ static int bus_set_transient_exit_status(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
sz_status /= sizeof(int32_t);
|
||||
sz_signal /= sizeof(int32_t);
|
||||
|
||||
if (sz_status == 0 && sz_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
exit_status_set_free(status_set);
|
||||
unit_write_settingf(u, flags, name, "%s=", name);
|
||||
@ -179,34 +182,34 @@ static int bus_set_transient_exit_status(
|
||||
|
||||
for (i = 0; i < sz_status; i++) {
|
||||
if (status[i] < 0 || status[i] > 255)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %i", name, status[i]);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %"PRIi32, name, status[i]);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
r = set_ensure_allocated(&status_set->status, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = set_put(status_set->status, INT_TO_PTR(status[i]));
|
||||
r = set_put(status_set->status, INT_TO_PTR((int) status[i]));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
unit_write_settingf(u, flags, name, "%s=%i", name, status[i]);
|
||||
unit_write_settingf(u, flags, name, "%s=%"PRIi32, name, status[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < sz_signal; i++) {
|
||||
const char *str;
|
||||
|
||||
str = signal_to_string(signal[i]);
|
||||
str = signal_to_string((int) signal[i]);
|
||||
if (!str)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %i", name, signal[i]);
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %"PRIi32, name, signal[i]);
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
r = set_ensure_allocated(&status_set->signal, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = set_put(status_set->signal, INT_TO_PTR(signal[i]));
|
||||
r = set_put(status_set->signal, INT_TO_PTR((int) signal[i]));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -755,7 +755,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(s))
|
||||
bus_print_property_value(name, expected_value, value, "%s", s);
|
||||
bus_print_property_value(name, expected_value, value, s);
|
||||
|
||||
return 1;
|
||||
|
||||
@ -771,7 +771,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
"Invalid user ID: " UID_FMT,
|
||||
uid);
|
||||
|
||||
bus_print_property_value(name, expected_value, value, UID_FMT, uid);
|
||||
bus_print_property_valuef(name, expected_value, value, UID_FMT, uid);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -628,7 +628,21 @@ int bus_connect_user_systemd(sd_bus **_bus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) {
|
||||
int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value) {
|
||||
assert(name);
|
||||
|
||||
if (expected_value && !streq_ptr(expected_value, value))
|
||||
return 0;
|
||||
|
||||
if (only_value)
|
||||
puts(value);
|
||||
else
|
||||
printf("%s=%s\n", name, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
@ -691,7 +705,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
/* 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, "%s", good ? s : "[unprintable]");
|
||||
bus_print_property_value(name, expected_value, value, good ? s : "[unprintable]");
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -707,7 +721,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, "%s", yes_no(b));
|
||||
bus_print_property_value(name, NULL, value, yes_no(b));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -728,13 +742,13 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
|
||||
t = format_timestamp(timestamp, sizeof(timestamp), u);
|
||||
if (t || all)
|
||||
bus_print_property_value(name, expected_value, value, "%s", strempty(t));
|
||||
bus_print_property_value(name, expected_value, value, strempty(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, "%s", timespan);
|
||||
bus_print_property_value(name, expected_value, value, timespan);
|
||||
|
||||
} else if (streq(name, "RestrictNamespaces")) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
@ -752,7 +766,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
result = s;
|
||||
}
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", result);
|
||||
bus_print_property_value(name, expected_value, value, result);
|
||||
|
||||
} else if (streq(name, "MountFlags")) {
|
||||
const char *result;
|
||||
@ -761,7 +775,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
if (!result)
|
||||
return -EINVAL;
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", result);
|
||||
bus_print_property_value(name, expected_value, value, result);
|
||||
|
||||
} else if (STR_IN_SET(name, "CapabilityBoundingSet", "AmbientCapabilities")) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
@ -770,7 +784,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", s);
|
||||
bus_print_property_value(name, expected_value, value, 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) ||
|
||||
@ -778,16 +792,18 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
(STR_IN_SET(name, "MemoryCurrent", "TasksCurrent") && u == (uint64_t) -1) ||
|
||||
(endswith(name, "NSec") && u == (uint64_t) -1))
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", "[not set]");
|
||||
bus_print_property_value(name, expected_value, value, "[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))
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", "infinity");
|
||||
bus_print_property_value(name, expected_value, value, "infinity");
|
||||
else if (STR_IN_SET(name, "IPIngressBytes", "IPIngressPackets", "IPEgressBytes", "IPEgressPackets") && u == (uint64_t) -1)
|
||||
bus_print_property_value(name, expected_value, value, "[no data]");
|
||||
else
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIu64, u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIu64, u);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -799,7 +815,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIi64, i);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIi64, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -811,20 +827,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_value(name, expected_value, value, "%04o", u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%04o", u);
|
||||
|
||||
else if (streq(name, "UID")) {
|
||||
if (u == UID_INVALID)
|
||||
bus_print_property_value(name, expected_value, value, "%s", "[not set]");
|
||||
bus_print_property_value(name, expected_value, value, "[not set]");
|
||||
else
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
|
||||
} else if (streq(name, "GID")) {
|
||||
if (u == GID_INVALID)
|
||||
bus_print_property_value(name, expected_value, value, "%s", "[not set]");
|
||||
bus_print_property_value(name, expected_value, value, "[not set]");
|
||||
else
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
|
||||
} else
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIu32, u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -836,7 +852,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%"PRIi32, i);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIi32, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -847,7 +863,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%g", d);
|
||||
bus_print_property_valuef(name, expected_value, value, "%g", d);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,8 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
|
||||
|
||||
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_value(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) _printf_(4,5);
|
||||
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);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/socket.h>
|
||||
@ -41,7 +42,9 @@
|
||||
#include "hostname-util.h"
|
||||
#include "initreq.h"
|
||||
#include "install.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "io-util.h"
|
||||
#include "journal-util.h"
|
||||
#include "list.h"
|
||||
#include "locale-util.h"
|
||||
#include "log.h"
|
||||
@ -73,6 +76,7 @@
|
||||
#include "unit-def.h"
|
||||
#include "unit-name.h"
|
||||
#include "user-util.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "utmp-wtmp.h"
|
||||
#include "verbs.h"
|
||||
@ -4669,6 +4673,23 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
|
||||
switch (bus_type) {
|
||||
|
||||
case SD_BUS_TYPE_INT32:
|
||||
if (endswith(name, "ActionExitStatus")) {
|
||||
int32_t i;
|
||||
|
||||
r = sd_bus_message_read_basic(m, bus_type, &i);
|
||||
if (r < 0)
|
||||
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]");
|
||||
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SD_BUS_TYPE_STRUCT:
|
||||
|
||||
if (contents[0] == SD_BUS_TYPE_UINT32 && streq(name, "Job")) {
|
||||
@ -4679,9 +4700,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_value(name, expected_value, value, "%"PRIu32, u);
|
||||
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
|
||||
else if (all)
|
||||
bus_print_property_value(name, expected_value, value, "%s", "");
|
||||
bus_print_property_value(name, expected_value, value, "");
|
||||
|
||||
return 1;
|
||||
|
||||
@ -4693,7 +4714,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(s))
|
||||
bus_print_property_value(name, expected_value, value, "%s", s);
|
||||
bus_print_property_value(name, expected_value, value, s);
|
||||
|
||||
return 1;
|
||||
|
||||
@ -4704,11 +4725,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(a) || !isempty(b))
|
||||
bus_print_property_value(name, expected_value, value, "%s \"%s\"", strempty(a), strempty(b));
|
||||
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, "");
|
||||
|
||||
return 1;
|
||||
} else if (streq_ptr(name, "SystemCallFilter")) {
|
||||
|
||||
} else if (STR_IN_SET(name, "SystemCallFilter", "RestrictAddressFamilies")) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
int whitelist;
|
||||
|
||||
@ -4752,6 +4776,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (STR_IN_SET(name, "SELinuxContext", "AppArmorProfile", "SmackProcessLabel")) {
|
||||
int ignore;
|
||||
const char *s;
|
||||
@ -4761,11 +4786,73 @@ 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_value(name, expected_value, value, "%s%s", ignore ? "-" : "", s);
|
||||
bus_print_property_valuef(name, expected_value, value, "%s%s", ignore ? "-" : "", s);
|
||||
else if (all)
|
||||
bus_print_property_value(name, expected_value, value, "%s", "");
|
||||
bus_print_property_value(name, expected_value, value, "");
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (endswith(name, "ExitStatus") && streq(contents, "aiai")) {
|
||||
const int32_t *status, *signal;
|
||||
size_t sz_status, sz_signal, i;
|
||||
|
||||
r = sd_bus_message_enter_container(m, 'r', "aiai");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_read_array(m, 'i', (const void **) &status, &sz_status);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_read_array(m, 'i', (const void **) &signal, &sz_signal);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
sz_status /= sizeof(int32_t);
|
||||
sz_signal /= sizeof(int32_t);
|
||||
|
||||
if (all || sz_status > 0 || sz_signal > 0) {
|
||||
bool first = true;
|
||||
|
||||
if (!value) {
|
||||
fputs(name, stdout);
|
||||
fputc('=', stdout);
|
||||
}
|
||||
|
||||
for (i = 0; i < sz_status; i++) {
|
||||
if (status[i] < 0 || status[i] > 255)
|
||||
continue;
|
||||
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
fputc(' ', stdout);
|
||||
|
||||
printf("%"PRIi32, status[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < sz_signal; i++) {
|
||||
const char *str;
|
||||
|
||||
str = signal_to_string((int) signal[i]);
|
||||
if (!str)
|
||||
continue;
|
||||
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
fputc(' ', stdout);
|
||||
|
||||
fputs(str, stdout);
|
||||
}
|
||||
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -4781,7 +4868,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_value(name, expected_value, value, "%s (ignore_errors=%s)", path, yes_no(ignore));
|
||||
bus_print_property_valuef(name, expected_value, value, "%s (ignore_errors=%s)", path, yes_no(ignore));
|
||||
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
@ -4800,7 +4887,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_value(name, expected_value, value, "%s (%s)", path, type);
|
||||
bus_print_property_valuef(name, expected_value, value, "%s (%s)", path, type);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -4818,7 +4905,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_value(name, expected_value, value, "%s (%s)", path, type);
|
||||
bus_print_property_valuef(name, expected_value, value, "%s (%s)", path, type);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -4839,9 +4926,9 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
while ((r = sd_bus_message_read(m, "(stt)", &base, &v, &next_elapse)) > 0) {
|
||||
char timespan1[FORMAT_TIMESPAN_MAX], timespan2[FORMAT_TIMESPAN_MAX];
|
||||
|
||||
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));
|
||||
bus_print_property_valuef(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);
|
||||
@ -4863,8 +4950,8 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
while ((r = sd_bus_message_read(m, "(sst)", &base, &spec, &next_elapse)) > 0) {
|
||||
char timestamp[FORMAT_TIMESTAMP_MAX];
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "{ %s=%s ; next_elapse=%s }", base, spec,
|
||||
format_timestamp(timestamp, sizeof(timestamp), next_elapse));
|
||||
bus_print_property_valuef(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);
|
||||
@ -4888,18 +4975,18 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
|
||||
tt = strv_join(info.argv, " ");
|
||||
|
||||
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)));
|
||||
bus_print_property_valuef(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);
|
||||
@ -4920,7 +5007,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_value(name, expected_value, value, "%s %s", strna(path), strna(rwm));
|
||||
bus_print_property_valuef(name, expected_value, value, "%s %s", strna(path), strna(rwm));
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -4940,7 +5027,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_value(name, expected_value, value, "%s %"PRIu64, strna(path), weight);
|
||||
bus_print_property_valuef(name, expected_value, value, "%s %"PRIu64, strna(path), weight);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -4961,7 +5048,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_value(name, expected_value, value, "%s %"PRIu64, strna(path), bandwidth);
|
||||
bus_print_property_valuef(name, expected_value, value, "%s %"PRIu64, strna(path), bandwidth);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -4982,8 +5069,8 @@ 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_value(name, expected_value, value, "%s %s", strna(path),
|
||||
format_timespan(ts, sizeof(ts), target, 1));
|
||||
bus_print_property_valuef(name, expected_value, value, "%s %s", strna(path),
|
||||
format_timespan(ts, sizeof(ts), target, 1));
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
@ -5007,7 +5094,187 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
||||
if (n < 0)
|
||||
return log_oom();
|
||||
|
||||
bus_print_property_value(name, expected_value, value, "%s", h);
|
||||
bus_print_property_value(name, expected_value, value, h);
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (STR_IN_SET(name, "IPAddressAllow", "IPAddressDeny")) {
|
||||
_cleanup_free_ char *addresses = NULL;
|
||||
|
||||
r = sd_bus_message_enter_container(m, 'a', "(iayu)");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
for (;;) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
uint32_t prefixlen;
|
||||
int32_t family;
|
||||
const void *ap;
|
||||
size_t an;
|
||||
|
||||
r = sd_bus_message_enter_container(m, 'r', "iayu");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
r = sd_bus_message_read(m, "i", &family);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_read_array(m, 'y', &ap, &an);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_read(m, "u", &prefixlen);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (!IN_SET(family, AF_INET, AF_INET6))
|
||||
continue;
|
||||
|
||||
if (an != FAMILY_ADDRESS_SIZE(family))
|
||||
continue;
|
||||
|
||||
if (prefixlen > FAMILY_ADDRESS_SIZE(family) * 8)
|
||||
continue;
|
||||
|
||||
if (in_addr_prefix_to_string(family, (union in_addr_union *) ap, prefixlen, &str) < 0)
|
||||
continue;
|
||||
|
||||
if (!strextend_with_separator(&addresses, " ", str, NULL))
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(addresses))
|
||||
bus_print_property_value(name, expected_value, value, strempty(addresses));
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
|
||||
_cleanup_free_ char *paths = NULL;
|
||||
const char *source, *dest;
|
||||
int ignore_enoent;
|
||||
uint64_t rbind;
|
||||
|
||||
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ssbt)");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
while ((r = sd_bus_message_read(m, "(ssbt)", &source, &dest, &ignore_enoent, &rbind)) > 0) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
|
||||
if (isempty(source))
|
||||
continue;
|
||||
|
||||
if (asprintf(&str, "%s%s%s%s%s",
|
||||
ignore_enoent ? "-" : "",
|
||||
source,
|
||||
isempty(dest) ? "" : ":",
|
||||
strempty(dest),
|
||||
rbind == MS_REC ? ":rbind" : "") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (!strextend_with_separator(&paths, " ", str, NULL))
|
||||
return log_oom();
|
||||
}
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(paths))
|
||||
bus_print_property_value(name, expected_value, value, strempty(paths));
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (streq(name, "TemporaryFileSystem")) {
|
||||
_cleanup_free_ char *paths = NULL;
|
||||
const char *target, *option;
|
||||
|
||||
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(ss)");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
while ((r = sd_bus_message_read(m, "(ss)", &target, &option)) > 0) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
|
||||
if (isempty(target))
|
||||
continue;
|
||||
|
||||
if (asprintf(&str, "%s%s%s", target, isempty(option) ? "" : ":", strempty(option)) < 0)
|
||||
return log_oom();
|
||||
|
||||
if (!strextend_with_separator(&paths, " ", str, NULL))
|
||||
return log_oom();
|
||||
}
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(paths))
|
||||
bus_print_property_value(name, expected_value, value, strempty(paths));
|
||||
|
||||
return 1;
|
||||
|
||||
} else if (streq(name, "LogExtraFields")) {
|
||||
_cleanup_free_ char *fields = NULL;
|
||||
const void *p;
|
||||
size_t sz;
|
||||
|
||||
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "ay");
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
while ((r = sd_bus_message_read_array(m, 'y', &p, &sz)) > 0) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
const char *eq;
|
||||
|
||||
if (memchr(p, 0, sz))
|
||||
continue;
|
||||
|
||||
eq = memchr(p, '=', sz);
|
||||
if (!eq)
|
||||
continue;
|
||||
|
||||
if (!journal_field_valid(p, eq - (const char*) p, false))
|
||||
continue;
|
||||
|
||||
str = malloc(sz + 1);
|
||||
if (!str)
|
||||
return log_oom();
|
||||
|
||||
memcpy(str, p, sz);
|
||||
str[sz] = '\0';
|
||||
|
||||
if (!utf8_is_valid(str))
|
||||
continue;
|
||||
|
||||
if (!strextend_with_separator(&fields, " ", str, NULL))
|
||||
return log_oom();
|
||||
}
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = sd_bus_message_exit_container(m);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (all || !isempty(fields))
|
||||
bus_print_property_value(name, expected_value, value, strempty(fields));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "strv.h"
|
||||
#include "in-addr-util.h"
|
||||
|
||||
static void test_in_addr_prefix_from_string(
|
||||
static void test_in_addr_prefix_from_string_one(
|
||||
const char *p,
|
||||
int family,
|
||||
int ret,
|
||||
@ -57,6 +57,82 @@ static void test_in_addr_prefix_from_string(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_from_string(void) {
|
||||
test_in_addr_prefix_from_string_one("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, -ENOANO, 0, 0, 8);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, 0, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, 0, 1, 0, 1);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, 0, 2, 0, 2);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, 0, 32, 0, 32);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string_one("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string_one("::1", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
|
||||
test_in_addr_prefix_from_string_one("", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/8", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, -ENOANO, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string_one("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, 0, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string_one("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, 0, 1, 0, 1);
|
||||
test_in_addr_prefix_from_string_one("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, 0, 2, 0, 2);
|
||||
test_in_addr_prefix_from_string_one("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, 0, 32, 0, 32);
|
||||
test_in_addr_prefix_from_string_one("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, 0, 33, 0, 33);
|
||||
test_in_addr_prefix_from_string_one("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, 0, 64, 0, 64);
|
||||
test_in_addr_prefix_from_string_one("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, 0, 128, 0, 128);
|
||||
test_in_addr_prefix_from_string_one("::1/129", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string_one("::1/-1", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_to_string_valid(int family, const char *p) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
union in_addr_union u;
|
||||
unsigned char l;
|
||||
|
||||
log_info("/* %s */", p);
|
||||
|
||||
assert_se(in_addr_prefix_from_string(p, family, &u, &l) >= 0);
|
||||
assert_se(in_addr_prefix_to_string(family, &u, l, &str) >= 0);
|
||||
assert_se(streq(str, p));
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_to_string_unoptimized(int family, const char *p) {
|
||||
_cleanup_free_ char *str1 = NULL, *str2 = NULL;
|
||||
union in_addr_union u1, u2;
|
||||
unsigned char len1, len2;
|
||||
|
||||
log_info("/* %s */", p);
|
||||
|
||||
assert_se(in_addr_prefix_from_string(p, family, &u1, &len1) >= 0);
|
||||
assert_se(in_addr_prefix_to_string(family, &u1, len1, &str1) >= 0);
|
||||
assert_se(in_addr_prefix_from_string(str1, family, &u2, &len2) >= 0);
|
||||
assert_se(in_addr_prefix_to_string(family, &u2, len2, &str2) >= 0);
|
||||
|
||||
assert_se(streq(str1, str2));
|
||||
assert_se(len1 == len2);
|
||||
assert_se(in_addr_equal(family, &u1, &u2) > 0);
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_to_string(void) {
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "0.0.0.0/32");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "1.2.3.4/0");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "1.2.3.4/24");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "1.2.3.4/32");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "255.255.255.255/32");
|
||||
|
||||
test_in_addr_prefix_to_string_valid(AF_INET6, "::1/128");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET6, "fd00:abcd::1/64");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET6, "fd00:abcd::1234:1/64");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET6, "1111:2222:3333:4444:5555:6666:7777:8888/128");
|
||||
|
||||
test_in_addr_prefix_to_string_unoptimized(AF_INET, "0.0.0.0");
|
||||
test_in_addr_prefix_to_string_unoptimized(AF_INET, "192.168.0.1");
|
||||
|
||||
test_in_addr_prefix_to_string_unoptimized(AF_INET6, "fd00:0000:0000:0000:0000:0000:0000:0001/64");
|
||||
test_in_addr_prefix_to_string_unoptimized(AF_INET6, "fd00:1111::0000:2222:3333:4444:0001/64");
|
||||
}
|
||||
|
||||
static void test_in_addr_random_prefix(void) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
union in_addr_union a;
|
||||
@ -102,33 +178,9 @@ static void test_in_addr_random_prefix(void) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_in_addr_prefix_from_string("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, -ENOANO, 0, 0, 8);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, 0, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, 0, 1, 0, 1);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, 0, 2, 0, 2);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, 0, 32, 0, 32);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string("::1", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
|
||||
test_in_addr_prefix_from_string("", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("/", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("/8", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, -ENOANO, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, 0, 0, 0, 0);
|
||||
test_in_addr_prefix_from_string("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, 0, 1, 0, 1);
|
||||
test_in_addr_prefix_from_string("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, 0, 2, 0, 2);
|
||||
test_in_addr_prefix_from_string("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, 0, 32, 0, 32);
|
||||
test_in_addr_prefix_from_string("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, 0, 33, 0, 33);
|
||||
test_in_addr_prefix_from_string("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, 0, 64, 0, 64);
|
||||
test_in_addr_prefix_from_string("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, 0, 128, 0, 128);
|
||||
test_in_addr_prefix_from_string("::1/129", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
test_in_addr_prefix_from_string("::1/-1", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0);
|
||||
|
||||
test_in_addr_prefix_from_string();
|
||||
test_in_addr_random_prefix();
|
||||
test_in_addr_prefix_to_string();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ static int print_timesync_property(const char *name, const char *expected_value,
|
||||
return r;
|
||||
|
||||
if (arg_all || !isempty(str))
|
||||
bus_print_property_value(name, expected_value, value, "%s", str);
|
||||
bus_print_property_value(name, expected_value, value, str);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user