1
0
mirror of https://github.com/systemd/systemd synced 2025-12-28 11:54:45 +01:00

Compare commits

...

14 Commits

Author SHA1 Message Date
Daan De Meyer
4ad303fddd meson: Optimize add-wants targets
Instead of invoking meson-add-wants.sh once for each wants that has
to be added, we pass all wants to a single invocation of
meson-add-wants.sh and in meson-add-wants.sh, loop over the
arguments.

This saves about 300ms on the install step.

Before:

```
‣ Running build script...
[1/418] Generating version.h with a custom command
Installing /root/build/po/be.gmo to /root/dest/usr/share/locale/be/LC_MESSAGES/systemd.mo
Installing /root/build/po/be@latin.gmo to /root/dest/usr/share/locale/be@latin/LC_MESSAGES/systemd.mo
Installing /root/build/po/bg.gmo to /root/dest/usr/share/locale/bg/LC_MESSAGES/systemd.mo
Installing /root/build/po/ca.gmo to /root/dest/usr/share/locale/ca/LC_MESSAGES/systemd.mo
Installing /root/build/po/cs.gmo to /root/dest/usr/share/locale/cs/LC_MESSAGES/systemd.mo
Installing /root/build/po/da.gmo to /root/dest/usr/share/locale/da/LC_MESSAGES/systemd.mo
Installing /root/build/po/de.gmo to /root/dest/usr/share/locale/de/LC_MESSAGES/systemd.mo
Installing /root/build/po/el.gmo to /root/dest/usr/share/locale/el/LC_MESSAGES/systemd.mo
Installing /root/build/po/es.gmo to /root/dest/usr/share/locale/es/LC_MESSAGES/systemd.mo
Installing /root/build/po/fr.gmo to /root/dest/usr/share/locale/fr/LC_MESSAGES/systemd.mo
Installing /root/build/po/gl.gmo to /root/dest/usr/share/locale/gl/LC_MESSAGES/systemd.mo
Installing /root/build/po/hr.gmo to /root/dest/usr/share/locale/hr/LC_MESSAGES/systemd.mo
Installing /root/build/po/hu.gmo to /root/dest/usr/share/locale/hu/LC_MESSAGES/systemd.mo
Installing /root/build/po/id.gmo to /root/dest/usr/share/locale/id/LC_MESSAGES/systemd.mo
Installing /root/build/po/it.gmo to /root/dest/usr/share/locale/it/LC_MESSAGES/systemd.mo
Installing /root/build/po/ja.gmo to /root/dest/usr/share/locale/ja/LC_MESSAGES/systemd.mo
Installing /root/build/po/ko.gmo to /root/dest/usr/share/locale/ko/LC_MESSAGES/systemd.mo
Installing /root/build/po/lt.gmo to /root/dest/usr/share/locale/lt/LC_MESSAGES/systemd.mo
Installing /root/build/po/pl.gmo to /root/dest/usr/share/locale/pl/LC_MESSAGES/systemd.mo
Installing /root/build/po/pt_BR.gmo to /root/dest/usr/share/locale/pt_BR/LC_MESSAGES/systemd.mo
Installing /root/build/po/ro.gmo to /root/dest/usr/share/locale/ro/LC_MESSAGES/systemd.mo
Installing /root/build/po/ru.gmo to /root/dest/usr/share/locale/ru/LC_MESSAGES/systemd.mo
Installing /root/build/po/sk.gmo to /root/dest/usr/share/locale/sk/LC_MESSAGES/systemd.mo
Installing /root/build/po/sr.gmo to /root/dest/usr/share/locale/sr/LC_MESSAGES/systemd.mo
Installing /root/build/po/sv.gmo to /root/dest/usr/share/locale/sv/LC_MESSAGES/systemd.mo
Installing /root/build/po/tr.gmo to /root/dest/usr/share/locale/tr/LC_MESSAGES/systemd.mo
Installing /root/build/po/uk.gmo to /root/dest/usr/share/locale/uk/LC_MESSAGES/systemd.mo
Installing /root/build/po/zh_CN.gmo to /root/dest/usr/share/locale/zh_CN/LC_MESSAGES/systemd.mo
Installing /root/build/po/zh_TW.gmo to /root/dest/usr/share/locale/zh_TW/LC_MESSAGES/systemd.mo
Installing /root/build/po/pa.gmo to /root/dest/usr/share/locale/pa/LC_MESSAGES/systemd.mo

real    0m1.465s
user    0m1.025s
sys     0m0.426s
```

After:

```
‣ Running build script...
[1/418] Generating version.h with a custom command
Installing /root/build/po/be.gmo to /root/dest/usr/share/locale/be/LC_MESSAGES/systemd.mo
Installing /root/build/po/be@latin.gmo to /root/dest/usr/share/locale/be@latin/LC_MESSAGES/systemd.mo
Installing /root/build/po/bg.gmo to /root/dest/usr/share/locale/bg/LC_MESSAGES/systemd.mo
Installing /root/build/po/ca.gmo to /root/dest/usr/share/locale/ca/LC_MESSAGES/systemd.mo
Installing /root/build/po/cs.gmo to /root/dest/usr/share/locale/cs/LC_MESSAGES/systemd.mo
Installing /root/build/po/da.gmo to /root/dest/usr/share/locale/da/LC_MESSAGES/systemd.mo
Installing /root/build/po/de.gmo to /root/dest/usr/share/locale/de/LC_MESSAGES/systemd.mo
Installing /root/build/po/el.gmo to /root/dest/usr/share/locale/el/LC_MESSAGES/systemd.mo
Installing /root/build/po/es.gmo to /root/dest/usr/share/locale/es/LC_MESSAGES/systemd.mo
Installing /root/build/po/fr.gmo to /root/dest/usr/share/locale/fr/LC_MESSAGES/systemd.mo
Installing /root/build/po/gl.gmo to /root/dest/usr/share/locale/gl/LC_MESSAGES/systemd.mo
Installing /root/build/po/hr.gmo to /root/dest/usr/share/locale/hr/LC_MESSAGES/systemd.mo
Installing /root/build/po/hu.gmo to /root/dest/usr/share/locale/hu/LC_MESSAGES/systemd.mo
Installing /root/build/po/id.gmo to /root/dest/usr/share/locale/id/LC_MESSAGES/systemd.mo
Installing /root/build/po/it.gmo to /root/dest/usr/share/locale/it/LC_MESSAGES/systemd.mo
Installing /root/build/po/ja.gmo to /root/dest/usr/share/locale/ja/LC_MESSAGES/systemd.mo
Installing /root/build/po/ko.gmo to /root/dest/usr/share/locale/ko/LC_MESSAGES/systemd.mo
Installing /root/build/po/lt.gmo to /root/dest/usr/share/locale/lt/LC_MESSAGES/systemd.mo
Installing /root/build/po/pl.gmo to /root/dest/usr/share/locale/pl/LC_MESSAGES/systemd.mo
Installing /root/build/po/pt_BR.gmo to /root/dest/usr/share/locale/pt_BR/LC_MESSAGES/systemd.mo
Installing /root/build/po/ro.gmo to /root/dest/usr/share/locale/ro/LC_MESSAGES/systemd.mo
Installing /root/build/po/ru.gmo to /root/dest/usr/share/locale/ru/LC_MESSAGES/systemd.mo
Installing /root/build/po/sk.gmo to /root/dest/usr/share/locale/sk/LC_MESSAGES/systemd.mo
Installing /root/build/po/sr.gmo to /root/dest/usr/share/locale/sr/LC_MESSAGES/systemd.mo
Installing /root/build/po/sv.gmo to /root/dest/usr/share/locale/sv/LC_MESSAGES/systemd.mo
Installing /root/build/po/tr.gmo to /root/dest/usr/share/locale/tr/LC_MESSAGES/systemd.mo
Installing /root/build/po/uk.gmo to /root/dest/usr/share/locale/uk/LC_MESSAGES/systemd.mo
Installing /root/build/po/zh_CN.gmo to /root/dest/usr/share/locale/zh_CN/LC_MESSAGES/systemd.mo
Installing /root/build/po/zh_TW.gmo to /root/dest/usr/share/locale/zh_TW/LC_MESSAGES/systemd.mo
Installing /root/build/po/pa.gmo to /root/dest/usr/share/locale/pa/LC_MESSAGES/systemd.mo

real    0m1.162s
user    0m0.803s
sys     0m0.338s
```
2021-01-09 22:52:55 +01:00
Lennart Poettering
1ea9580d8f
Merge pull request #18183 from poettering/arg-json-rework
--json= argument rework in various tools
2021-01-09 21:52:56 +01:00
Lennart Poettering
84319c5c07 test-xattr-util: don't insist that /usr supports xattrs
(apparently overlayfs has issues with xattrs, hence don't require that
/usr supports xattrs)
2021-01-09 21:31:25 +01:00
Daan De Meyer
534fd13070
Merge pull request #18182 from DaanDeMeyer/mkosi-build-pushd
mkosi.build: Silence "Entering directory" message from ninja
2021-01-09 17:27:56 +00:00
Daan De Meyer
1e48ef3f5d mkosi.build: Only create groups if they don't exist yet 2021-01-09 18:06:28 +01:00
Daan De Meyer
c3e2dc71de mkosi.build: Silence "Entering directory" message from ninja
When using `ninja -C "$BUILDDIR"`, ninja prints an annoying log
message about entering the directory that cannot be silenced. Let's
manually move in and out of the build directory instead.
2021-01-09 18:05:57 +01:00
Lennart Poettering
923d37c64a busctl: port busctl to JSON_FORMAT_OFF too
This is a bit more complex, since busctl's JSON code predates json.c and
was only minimally updated sofar.
2021-01-09 17:36:28 +01:00
Lennart Poettering
6a01ea4a2f json: port various tools to the new JSON_FORMAT_OFF flag
These are the obvious cases.
2021-01-09 17:36:24 +01:00
Lennart Poettering
b95a05d014 json: add generic cmdline parser for --json= switch 2021-01-09 17:36:11 +01:00
Lennart Poettering
10d7126365 json: add new json format flag for disabling JSON output
This adds a new flag JSON_FORMAT_OFF that is a marker for "no JSON
output please!".

Of course, this flag sounds pointless in a JSON implementation, however
this is useful in code that can generate JSON output, but also more
human friendly output (for example our table formatters).

With this in place various tools that so far maintained one boolean
field "arg_json" that controlled whether JSON output was requested at
all and another field "arg_json_format_flags" for selecing the precise
json output flags may merge them into one, simplifying code a bit.
2021-01-09 17:35:58 +01:00
Luca Boccassi
28abf5ad34 bpf: zero bpf_attr before initialization
When building with Clang and using structured initialization, the
bpf_attr union is not zero-padded, so the kernel misdetects it as
an unsupported extension.
zero it until Clang's behaviour matches GCC. Do not skip the test
on Github Actions anymore.
2021-01-09 17:35:38 +01:00
Lennart Poettering
91efc847dc
Merge pull request #18179 from poettering/machine-image-tweaks
two simple tweaks to the machine-image.c logic
2021-01-09 17:34:50 +01:00
Lennart Poettering
02dcf21571 machine-image: pick up crtime of directory images, too 2021-01-09 15:56:03 +01:00
Lennart Poettering
c21087014e machine-image: use structured initialization 2021-01-09 15:48:33 +01:00
14 changed files with 158 additions and 188 deletions

View File

@ -87,14 +87,16 @@ if [ ! -f "$BUILDDIR"/build.ninja ] ; then
meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D "rootprefix=$rootprefix" -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group" meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D "rootprefix=$rootprefix" -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group"
fi fi
ninja -C "$BUILDDIR" all cd "$BUILDDIR"
ninja
if [ "$WITH_TESTS" = 1 ] ; then if [ "$WITH_TESTS" = 1 ] ; then
for id in 1 2 3; do for id in 1 2 3; do
groupadd -g $id testgroup$id || : getent group $id > /dev/null || groupadd -g $id testgroup$id
done done
ninja -C "$BUILDDIR" test ninja test
fi fi
cd "$SRCDIR"
# Ubuntu Focal is stuck with meson 0.53.0. # Ubuntu Focal is stuck with meson 0.53.0.
if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then if [ "$(meson -v | cut -d . -f 2)" -gt 53 ] ; then

View File

@ -31,11 +31,7 @@
#include "user-util.h" #include "user-util.h"
#include "verbs.h" #include "verbs.h"
static enum { static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
JSON_OFF,
JSON_SHORT,
JSON_PRETTY,
} arg_json = JSON_OFF;
static PagerFlags arg_pager_flags = 0; static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true; static bool arg_legend = true;
static bool arg_full = false; static bool arg_full = false;
@ -67,7 +63,6 @@ STATIC_DESTRUCTOR_REGISTER(arg_matches, strv_freep);
#define NAME_IS_ACTIVATABLE INT_TO_PTR(2) #define NAME_IS_ACTIVATABLE INT_TO_PTR(2)
static int json_transform_message(sd_bus_message *m, JsonVariant **ret); static int json_transform_message(sd_bus_message *m, JsonVariant **ret);
static void json_dump_with_flags(JsonVariant *v, FILE *f);
static int acquire_bus(bool set_monitor, sd_bus **ret) { static int acquire_bus(bool set_monitor, sd_bus **ret) {
_cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
@ -362,13 +357,10 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
return log_error_errno(r, "Failed to fill line: %m"); return log_error_errno(r, "Failed to fill line: %m");
} }
if (arg_json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
if (arg_json) r = table_print_json(table, NULL, arg_json_format_flags);
r = table_print_json(table, stdout,
(arg_json == JSON_PRETTY ? JSON_FORMAT_PRETTY : JSON_FORMAT_NEWLINE) | JSON_FORMAT_COLOR_AUTO);
else
r = table_print(table, stdout);
if (r < 0) if (r < 0)
return table_log_print_error(r); return table_log_print_error(r);
@ -1228,7 +1220,7 @@ static int message_json(sd_bus_message *m, FILE *f) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to build JSON object: %m"); return log_error_errno(r, "Failed to build JSON object: %m");
json_dump_with_flags(w, f); json_variant_dump(w, arg_json_format_flags, f, NULL);
return 0; return 0;
} }
@ -1355,7 +1347,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
} }
static int verb_monitor(int argc, char **argv, void *userdata) { static int verb_monitor(int argc, char **argv, void *userdata) {
return monitor(argc, argv, arg_json != JSON_OFF ? message_json : message_dump); return monitor(argc, argv, (arg_json_format_flags & JSON_FORMAT_OFF) ? message_dump : message_json);
} }
static int verb_capture(int argc, char **argv, void *userdata) { static int verb_capture(int argc, char **argv, void *userdata) {
@ -2006,14 +1998,6 @@ static int json_transform_message(sd_bus_message *m, JsonVariant **ret) {
return 0; return 0;
} }
static void json_dump_with_flags(JsonVariant *v, FILE *f) {
json_variant_dump(v,
(arg_json == JSON_PRETTY ? JSON_FORMAT_PRETTY : JSON_FORMAT_NEWLINE) |
JSON_FORMAT_COLOR_AUTO,
f, NULL);
}
static int call(int argc, char **argv, void *userdata) { static int call(int argc, char **argv, void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
@ -2072,17 +2056,17 @@ static int call(int argc, char **argv, void *userdata) {
if (r == 0 && !arg_quiet) { if (r == 0 && !arg_quiet) {
if (arg_json != JSON_OFF) { if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
if (arg_json != JSON_SHORT) if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
r = json_transform_message(reply, &v); r = json_transform_message(reply, &v);
if (r < 0) if (r < 0)
return r; return r;
json_dump_with_flags(v, stdout); json_variant_dump(v, arg_json_format_flags, NULL, NULL);
} else if (arg_verbose) { } else if (arg_verbose) {
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
@ -2181,17 +2165,17 @@ static int get_property(int argc, char **argv, void *userdata) {
if (r < 0) if (r < 0)
return bus_log_parse_error(r); return bus_log_parse_error(r);
if (arg_json != JSON_OFF) { if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
if (arg_json != JSON_SHORT) if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
r = json_transform_variant(reply, contents, &v); r = json_transform_variant(reply, contents, &v);
if (r < 0) if (r < 0)
return r; return r;
json_dump_with_flags(v, stdout); json_variant_dump(v, arg_json_format_flags, NULL, NULL);
} else if (arg_verbose) { } else if (arg_verbose) {
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
@ -2543,25 +2527,13 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'j': case 'j':
if (on_tty()) arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
arg_json = JSON_PRETTY;
else
arg_json = JSON_SHORT;
break; break;
case ARG_JSON: case ARG_JSON:
if (streq(optarg, "short")) r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
arg_json = JSON_SHORT; if (r <= 0)
else if (streq(optarg, "pretty")) return r;
arg_json = JSON_PRETTY;
else if (streq(optarg, "help")) {
fputs("short\n"
"pretty\n", stdout);
return 0;
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown JSON out mode: %s",
optarg);
break; break;

View File

@ -45,8 +45,7 @@ static const char *arg_source = NULL;
static const char *arg_target = NULL; static const char *arg_target = NULL;
static DissectImageFlags arg_flags = DISSECT_IMAGE_REQUIRE_ROOT|DISSECT_IMAGE_DISCARD_ON_LOOP|DISSECT_IMAGE_RELAX_VAR_CHECK|DISSECT_IMAGE_FSCK; static DissectImageFlags arg_flags = DISSECT_IMAGE_REQUIRE_ROOT|DISSECT_IMAGE_DISCARD_ON_LOOP|DISSECT_IMAGE_RELAX_VAR_CHECK|DISSECT_IMAGE_FSCK;
static VeritySettings arg_verity_settings = VERITY_SETTINGS_DEFAULT; static VeritySettings arg_verity_settings = VERITY_SETTINGS_DEFAULT;
static bool arg_json = false; static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
static JsonFormatFlags arg_json_format_flags = 0;
STATIC_DESTRUCTOR_REGISTER(arg_verity_settings, verity_settings_done); STATIC_DESTRUCTOR_REGISTER(arg_verity_settings, verity_settings_done);
@ -242,22 +241,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_JSON: case ARG_JSON:
if (streq(optarg, "pretty")) { r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
arg_json = true; if (r <= 0)
arg_json_format_flags = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO; return r;
} else if (streq(optarg, "short")) {
arg_json = true;
arg_json_format_flags = JSON_FORMAT_NEWLINE;
} else if (streq(optarg, "off")) {
arg_json = false;
arg_json_format_flags = 0;
} else if (streq(optarg, "help")) {
puts("pretty\n"
"short\n"
"off");
return 0;
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json=: %s", optarg);
break; break;
@ -353,17 +339,17 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
assert(m); assert(m);
assert(d); assert(d);
if (!arg_json) if (arg_json_format_flags & JSON_FORMAT_OFF)
printf(" Name: %s\n", basename(arg_image)); printf(" Name: %s\n", basename(arg_image));
if (ioctl(d->fd, BLKGETSIZE64, &size) < 0) if (ioctl(d->fd, BLKGETSIZE64, &size) < 0)
log_debug_errno(errno, "Failed to query size of loopback device: %m"); log_debug_errno(errno, "Failed to query size of loopback device: %m");
else if (!arg_json) { else if (arg_json_format_flags & JSON_FORMAT_OFF) {
char s[FORMAT_BYTES_MAX]; char s[FORMAT_BYTES_MAX];
printf(" Size: %s\n", format_bytes(s, sizeof(s), size)); printf(" Size: %s\n", format_bytes(s, sizeof(s), size));
} }
if (!arg_json) if (arg_json_format_flags & JSON_FORMAT_OFF)
putc('\n', stdout); putc('\n', stdout);
r = dissected_image_acquire_metadata(m); r = dissected_image_acquire_metadata(m);
@ -379,7 +365,7 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
log_warning_errno(r, "OS image is currently in use, proceeding without showing OS image metadata."); log_warning_errno(r, "OS image is currently in use, proceeding without showing OS image metadata.");
else if (r < 0) else if (r < 0)
return log_error_errno(r, "Failed to acquire image metadata: %m"); return log_error_errno(r, "Failed to acquire image metadata: %m");
else if (!arg_json) { else if (arg_json_format_flags & JSON_FORMAT_OFF) {
if (m->hostname) if (m->hostname)
printf(" Hostname: %s\n", m->hostname); printf(" Hostname: %s\n", m->hostname);
@ -495,7 +481,11 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
return table_log_add_error(r); return table_log_add_error(r);
} }
if (arg_json) { if (arg_json_format_flags & JSON_FORMAT_OFF) {
r = table_print(t, stdout);
if (r < 0)
return table_log_print_error(r);
} else {
_cleanup_(json_variant_unrefp) JsonVariant *jt = NULL; _cleanup_(json_variant_unrefp) JsonVariant *jt = NULL;
r = table_to_json(t, &jt); r = table_to_json(t, &jt);
@ -507,10 +497,6 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
return log_oom(); return log_oom();
json_variant_dump(v, arg_json_format_flags, stdout, NULL); json_variant_dump(v, arg_json_format_flags, stdout, NULL);
} else {
r = table_print(t, stdout);
if (r < 0)
return log_error_errno(r, "Failed to dump table: %m");
} }
return 0; return 0;

View File

@ -56,8 +56,7 @@ static uint64_t arg_disk_size_relative = UINT64_MAX;
static char **arg_pkcs11_token_uri = NULL; static char **arg_pkcs11_token_uri = NULL;
static char **arg_fido2_device = NULL; static char **arg_fido2_device = NULL;
static bool arg_recovery_key = false; static bool arg_recovery_key = false;
static bool arg_json = false; static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
static JsonFormatFlags arg_json_format_flags = 0;
static bool arg_and_resize = false; static bool arg_and_resize = false;
static bool arg_and_change_password = false; static bool arg_and_change_password = false;
static enum { static enum {
@ -171,22 +170,19 @@ static int list_homes(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return bus_log_parse_error(r); return bus_log_parse_error(r);
if (table_get_rows(table) > 1 || arg_json) { if (table_get_rows(table) > 1 || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
r = table_set_sort(table, (size_t) 0, (size_t) -1); r = table_set_sort(table, (size_t) 0, (size_t) -1);
if (r < 0) if (r < 0)
return table_log_sort_error(r); return table_log_sort_error(r);
table_set_header(table, arg_legend); table_set_header(table, arg_legend);
if (arg_json)
r = table_print_json(table, stdout, arg_json_format_flags); r = table_print_json(table, stdout, arg_json_format_flags);
else
r = table_print(table, NULL);
if (r < 0) if (r < 0)
return table_log_print_error(r); return table_log_print_error(r);
} }
if (arg_legend && !arg_json) { if (arg_legend && (arg_json_format_flags & JSON_FORMAT_OFF)) {
if (table_get_rows(table) > 1) if (table_get_rows(table) > 1)
printf("\n%zu home areas listed.\n", table_get_rows(table) - 1); printf("\n%zu home areas listed.\n", table_get_rows(table) - 1);
else else
@ -462,7 +458,9 @@ static void dump_home_record(UserRecord *hr) {
log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr->user_name); log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr->user_name);
} }
if (arg_json) { if (arg_json_format_flags & JSON_FORMAT_OFF)
user_record_show(hr, true);
else {
_cleanup_(user_record_unrefp) UserRecord *stripped = NULL; _cleanup_(user_record_unrefp) UserRecord *stripped = NULL;
if (arg_export_format == EXPORT_FORMAT_STRIPPED) if (arg_export_format == EXPORT_FORMAT_STRIPPED)
@ -477,8 +475,7 @@ static void dump_home_record(UserRecord *hr) {
hr = stripped; hr = stripped;
json_variant_dump(hr->json, arg_json_format_flags, stdout, NULL); json_variant_dump(hr->json, arg_json_format_flags, stdout, NULL);
} else }
user_record_show(hr, true);
} }
static char **mangle_user_list(char **list, char ***ret_allocated) { static char **mangle_user_list(char **list, char ***ret_allocated) {
@ -3235,27 +3232,13 @@ static int parse_argv(int argc, char *argv[]) {
} }
case 'j': case 'j':
arg_json = true;
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO; arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
break; break;
case ARG_JSON: case ARG_JSON:
if (streq(optarg, "pretty")) { r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
arg_json = true; if (r <= 0)
arg_json_format_flags = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO; return r;
} else if (streq(optarg, "short")) {
arg_json = true;
arg_json_format_flags = JSON_FORMAT_NEWLINE;
} else if (streq(optarg, "off")) {
arg_json = false;
arg_json_format_flags = 0;
} else if (streq(optarg, "help")) {
puts("pretty\n"
"short\n"
"off");
return 0;
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json=: %s", optarg);
break; break;
@ -3267,7 +3250,7 @@ static int parse_argv(int argc, char *argv[]) {
else else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specifying -E more than twice is not supported."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specifying -E more than twice is not supported.");
arg_json = true; arg_json_format_flags &= ~JSON_FORMAT_OFF;
if (arg_json_format_flags == 0) if (arg_json_format_flags == 0)
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO; arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
break; break;

View File

@ -106,8 +106,7 @@ static bool arg_randomize = false;
static int arg_pretty = -1; static int arg_pretty = -1;
static uint64_t arg_size = UINT64_MAX; static uint64_t arg_size = UINT64_MAX;
static bool arg_size_auto = false; static bool arg_size_auto = false;
static bool arg_json = false; static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
static JsonFormatFlags arg_json_format_flags = 0;
static void *arg_key = NULL; static void *arg_key = NULL;
static size_t arg_key_size = 0; static size_t arg_key_size = 0;
static char *arg_tpm2_device = NULL; static char *arg_tpm2_device = NULL;
@ -1824,7 +1823,7 @@ static int context_dump_partitions(Context *context, const char *node) {
Partition *p; Partition *p;
int r; int r;
if (!arg_json && context->n_partitions == 0) { if ((arg_json_format_flags & JSON_FORMAT_OFF) && context->n_partitions == 0) {
log_info("Empty partition table."); log_info("Empty partition table.");
return 0; return 0;
} }
@ -1834,12 +1833,12 @@ static int context_dump_partitions(Context *context, const char *node) {
return log_oom(); return log_oom();
if (!DEBUG_LOGGING) { if (!DEBUG_LOGGING) {
if (arg_json) if (arg_json_format_flags & JSON_FORMAT_OFF)
(void) table_set_display(t, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 4,
(size_t) 5, (size_t) 6, (size_t) 7, (size_t) 9, (size_t) 10, (size_t) 12, (size_t) -1);
else
(void) table_set_display(t, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 4, (void) table_set_display(t, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 4,
(size_t) 8, (size_t) 11, (size_t) -1); (size_t) 8, (size_t) 11, (size_t) -1);
else
(void) table_set_display(t, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 4,
(size_t) 5, (size_t) 6, (size_t) 7, (size_t) 9, (size_t) 10, (size_t) 12, (size_t) -1);
} }
(void) table_set_align_percent(t, table_get_cell(t, 0, 4), 100); (void) table_set_align_percent(t, table_get_cell(t, 0, 4), 100);
@ -1893,7 +1892,7 @@ static int context_dump_partitions(Context *context, const char *node) {
return table_log_add_error(r); return table_log_add_error(r);
} }
if (!arg_json && (sum_padding > 0 || sum_size > 0)) { if ((arg_json_format_flags & JSON_FORMAT_OFF) && (sum_padding > 0 || sum_size > 0)) {
char s[FORMAT_BYTES_MAX]; char s[FORMAT_BYTES_MAX];
const char *a, *b; const char *a, *b;
@ -1919,12 +1918,9 @@ static int context_dump_partitions(Context *context, const char *node) {
return table_log_add_error(r); return table_log_add_error(r);
} }
if (arg_json)
r = table_print_json(t, stdout, arg_json_format_flags); r = table_print_json(t, stdout, arg_json_format_flags);
else
r = table_print(t, stdout);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to dump table: %m"); return table_log_print_error(r);
return 0; return 0;
} }
@ -3203,13 +3199,13 @@ static int context_write_partition_table(
if (arg_pretty > 0 || if (arg_pretty > 0 ||
(arg_pretty < 0 && isatty(STDOUT_FILENO) > 0) || (arg_pretty < 0 && isatty(STDOUT_FILENO) > 0) ||
arg_json) { !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
(void) context_dump_partitions(context, node); (void) context_dump_partitions(context, node);
putc('\n', stdout); putc('\n', stdout);
if (!arg_json) if (arg_json_format_flags & JSON_FORMAT_OFF)
(void) context_dump_partition_bar(context, node); (void) context_dump_partition_bar(context, node);
putc('\n', stdout); putc('\n', stdout);
fflush(stdout); fflush(stdout);
@ -3679,22 +3675,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
case ARG_JSON: case ARG_JSON:
if (streq(optarg, "pretty")) { r = json_parse_cmdline_parameter_and_warn(optarg, &arg_json_format_flags);
arg_json = true; if (r <= 0)
arg_json_format_flags = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO; return r;
} else if (streq(optarg, "short")) {
arg_json = true;
arg_json_format_flags = JSON_FORMAT_NEWLINE;
} else if (streq(optarg, "off")) {
arg_json = false;
arg_json_format_flags = 0;
} else if (streq(optarg, "help")) {
puts("pretty\n"
"short\n"
"off");
return 0;
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json=: %s", optarg);
break; break;

View File

@ -76,6 +76,11 @@ int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size) {
return 0; return 0;
} }
// FIXME: Clang doesn't 0-pad with structured initialization, causing
// the kernel to reject the bpf_attr as invalid. See:
// https://github.com/torvalds/linux/blob/v5.9/kernel/bpf/syscall.c#L65
// Ideally it should behave like GCC, so that we can remove these workarounds.
zero(attr);
attr = (union bpf_attr) { attr = (union bpf_attr) {
.prog_type = p->prog_type, .prog_type = p->prog_type,
.insns = PTR_TO_UINT64(p->instructions), .insns = PTR_TO_UINT64(p->instructions),
@ -101,6 +106,7 @@ int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path) {
if (p->kernel_fd >= 0) /* don't overwrite an assembled or loaded program */ if (p->kernel_fd >= 0) /* don't overwrite an assembled or loaded program */
return -EBUSY; return -EBUSY;
zero(attr);
attr = (union bpf_attr) { attr = (union bpf_attr) {
.pathname = PTR_TO_UINT64(path), .pathname = PTR_TO_UINT64(path),
}; };
@ -158,6 +164,7 @@ int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_
if (fd < 0) if (fd < 0)
return -errno; return -errno;
zero(attr);
attr = (union bpf_attr) { attr = (union bpf_attr) {
.attach_type = type, .attach_type = type,
.target_fd = fd, .target_fd = fd,
@ -194,6 +201,7 @@ int bpf_program_cgroup_detach(BPFProgram *p) {
} else { } else {
union bpf_attr attr; union bpf_attr attr;
zero(attr);
attr = (union bpf_attr) { attr = (union bpf_attr) {
.attach_type = p->attached_type, .attach_type = p->attached_type,
.target_fd = fd, .target_fd = fd,

View File

@ -2536,6 +2536,9 @@ int table_print_json(Table *t, FILE *f, JsonFormatFlags flags) {
assert(t); assert(t);
if (flags & JSON_FORMAT_OFF) /* If JSON output is turned off, use regular output */
return table_print(t, f);
if (!f) if (!f)
f = stdout; f = stdout;

View File

@ -1766,6 +1766,9 @@ int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
assert_return(v, -EINVAL); assert_return(v, -EINVAL);
assert_return(ret, -EINVAL); assert_return(ret, -EINVAL);
if (flags & JSON_FORMAT_OFF)
return -ENOEXEC;
{ {
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
@ -4456,6 +4459,27 @@ int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size) {
return unhexmem(json_variant_string(v), (size_t) -1, ret, ret_size); return unhexmem(json_variant_string(v), (size_t) -1, ret, ret_size);
} }
int json_parse_cmdline_parameter_and_warn(const char *s, JsonFormatFlags *ret) {
assert(s);
assert(ret);
if (streq(s, "pretty"))
*ret = JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO;
else if (streq(s, "short"))
*ret = JSON_FORMAT_NEWLINE;
else if (streq(s, "off"))
*ret = JSON_FORMAT_OFF;
else if (streq(s, "help")) {
puts("pretty\n"
"short\n"
"off");
return 0; /* 0 means → we showed a brief help, exit now */
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json= switch: %s", s);
return 1; /* 1 means → properly parsed */
}
static const char* const json_variant_type_table[_JSON_VARIANT_TYPE_MAX] = { static const char* const json_variant_type_table[_JSON_VARIANT_TYPE_MAX] = {
[JSON_VARIANT_STRING] = "string", [JSON_VARIANT_STRING] = "string",
[JSON_VARIANT_INTEGER] = "integer", [JSON_VARIANT_INTEGER] = "integer",

View File

@ -175,6 +175,7 @@ typedef enum JsonFormatFlags {
JSON_FORMAT_SSE = 1 << 6, /* prefix/suffix with W3C server-sent events */ JSON_FORMAT_SSE = 1 << 6, /* prefix/suffix with W3C server-sent events */
JSON_FORMAT_SEQ = 1 << 7, /* prefix/suffix with RFC 7464 application/json-seq */ JSON_FORMAT_SEQ = 1 << 7, /* prefix/suffix with RFC 7464 application/json-seq */
JSON_FORMAT_FLUSH = 1 << 8, /* call fflush() after dumping JSON */ JSON_FORMAT_FLUSH = 1 << 8, /* call fflush() after dumping JSON */
JSON_FORMAT_OFF = 1 << 9, /* make json_variant_format() fail with -ENOEXEC */
} JsonFormatFlags; } JsonFormatFlags;
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret); int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);
@ -356,5 +357,7 @@ int json_log_internal(JsonVariant *variant, int level, int error, const char *fi
int json_variant_unbase64(JsonVariant *v, void **ret, size_t *ret_size); int json_variant_unbase64(JsonVariant *v, void **ret, size_t *ret_size);
int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size); int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size);
int json_parse_cmdline_parameter_and_warn(const char *s, JsonFormatFlags *ret);
const char *json_variant_type_to_string(JsonVariantType t); const char *json_variant_type_to_string(JsonVariantType t);
JsonVariantType json_variant_type_from_string(const char *s); JsonVariantType json_variant_type_from_string(const char *s);

View File

@ -129,17 +129,21 @@ static int image_new(
assert(filename); assert(filename);
assert(ret); assert(ret);
i = new0(Image, 1); i = new(Image, 1);
if (!i) if (!i)
return -ENOMEM; return -ENOMEM;
i->n_ref = 1; *i = (Image) {
i->type = t; .n_ref = 1,
i->read_only = read_only; .type = t,
i->crtime = crtime; .read_only = read_only,
i->mtime = mtime; .crtime = crtime,
i->usage = i->usage_exclusive = (uint64_t) -1; .mtime = mtime,
i->limit = i->limit_exclusive = (uint64_t) -1; .usage = UINT64_MAX,
.usage_exclusive = UINT64_MAX,
.limit = UINT64_MAX,
.limit_exclusive = UINT64_MAX,
};
i->name = strdup(pretty); i->name = strdup(pretty);
if (!i->name) if (!i->name)
@ -232,6 +236,7 @@ static int image_make(
if (S_ISDIR(st->st_mode)) { if (S_ISDIR(st->st_mode)) {
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
unsigned file_attr = 0; unsigned file_attr = 0;
usec_t crtime = 0;
if (!ret) if (!ret)
return 0; return 0;
@ -291,8 +296,10 @@ static int image_make(
} }
} }
/* If the IMMUTABLE bit is set, we consider the /* Get directory creation time (not available everywhere, but that's OK */
* directory read-only. Since the ioctl is not (void) fd_getcrtime(dfd, &crtime);
/* If the IMMUTABLE bit is set, we consider the directory read-only. Since the ioctl is not
* supported everywhere we ignore failures. */ * supported everywhere we ignore failures. */
(void) read_attr_fd(fd, &file_attr); (void) read_attr_fd(fd, &file_attr);
@ -302,8 +309,8 @@ static int image_make(
path, path,
filename, filename,
read_only || (file_attr & FS_IMMUTABLE_FL), read_only || (file_attr & FS_IMMUTABLE_FL),
0, crtime,
0, 0, /* we don't use mtime of stat() here, since it's not the time of last change of the tree, but only of the top-level dir */
ret); ret);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -37,16 +37,6 @@ int main(int argc, char *argv[]) {
if (detect_container() > 0) if (detect_container() > 0)
return log_tests_skipped("test-bpf-firewall fails inside LXC and Docker containers: https://github.com/systemd/systemd/issues/9666"); return log_tests_skipped("test-bpf-firewall fails inside LXC and Docker containers: https://github.com/systemd/systemd/issues/9666");
#ifdef __clang__
/* FIXME: This test is for (currently unknown) reasons failing in both
* sanitized and unsanitized clang runs. Until the issue is resolved,
* let's skip the test when running on GH Actions and compiled with
* clang.
*/
if (strstr_ptr(ci_environment(), "github-actions"))
return log_tests_skipped("Skipping test on GH Actions");
#endif
assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0); assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE); rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
(void) setrlimit(RLIMIT_MEMLOCK, &rl); (void) setrlimit(RLIMIT_MEMLOCK, &rl);

View File

@ -28,7 +28,7 @@ static void test_fgetxattrat_fake(void) {
assert_se(touch(x) >= 0); assert_se(touch(x) >= 0);
r = setxattr(x, "user.foo", "bar", 3, 0); r = setxattr(x, "user.foo", "bar", 3, 0);
if (r < 0 && errno == EOPNOTSUPP) /* no xattrs supported on /var/tmp... */ if (r < 0 && ERRNO_IS_NOT_SUPPORTED(errno)) /* no xattrs supported on /var/tmp... */
goto cleanup; goto cleanup;
assert_se(r >= 0); assert_se(r >= 0);
@ -42,7 +42,8 @@ static void test_fgetxattrat_fake(void) {
safe_close(fd); safe_close(fd);
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY); fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
assert_se(fd >= 0); assert_se(fd >= 0);
assert_se(fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0, &size) == -ENODATA); r = fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0, &size);
assert_se(r == -ENODATA || ERRNO_IS_NOT_SUPPORTED(r));
cleanup: cleanup:
assert_se(unlink(x) >= 0); assert_se(unlink(x) >= 0);

View File

@ -1,34 +1,39 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
unitdir="$1" i=1
target="$2" while [ $i -lt $# ] ; do
unit="$3" eval unitdir="\${$i}"
eval target="\${$((i + 1))}"
eval unit="\${$((i + 2))}"
if [ "${MESON_INSTALL_QUIET:-0}" = 1 ] ; then if [ "${MESON_INSTALL_QUIET:-0}" = 1 ] ; then
VERBOSE="" VERBOSE=""
else else
VERBOSE="v" VERBOSE="v"
fi fi
case "$target" in case "$target" in
*/?*) # a path, but not just a slash at the end */?*) # a path, but not just a slash at the end
dir="${DESTDIR:-}${target}" dir="${DESTDIR:-}${target}"
;; ;;
*) *)
dir="${DESTDIR:-}${unitdir}/${target}" dir="${DESTDIR:-}${unitdir}/${target}"
;; ;;
esac esac
unitpath="${DESTDIR:-}${unitdir}/${unit}" unitpath="${DESTDIR:-}${unitdir}/${unit}"
case "$target" in case "$target" in
*/) */)
mkdir -${VERBOSE}p -m 0755 "$dir" mkdir -${VERBOSE}p -m 0755 "$dir"
;; ;;
*) *)
mkdir -${VERBOSE}p -m 0755 "$(dirname "$dir")" mkdir -${VERBOSE}p -m 0755 "$(dirname "$dir")"
;; ;;
esac esac
ln -${VERBOSE}fs --relative "$unitpath" "$dir" ln -${VERBOSE}fs --relative "$unitpath" "$dir"
i=$((i + 3))
done

View File

@ -247,6 +247,8 @@ m4_units = [
['serial-getty@.service', ''], ['serial-getty@.service', ''],
] ]
add_wants = []
foreach tuple : in_units foreach tuple : in_units
file = tuple[0] file = tuple[0]
@ -270,7 +272,7 @@ foreach tuple : in_units
if install and tuple.length() > 2 if install and tuple.length() > 2
foreach target : tuple[2].split() foreach target : tuple[2].split()
meson.add_install_script('meson-add-wants.sh', systemunitdir, target, file) add_wants += [systemunitdir, target, file]
endforeach endforeach
endif endif
endforeach endforeach
@ -295,7 +297,7 @@ foreach tuple : m4_units
if tuple.length() > 2 and install if tuple.length() > 2 and install
foreach target : tuple[2].split() foreach target : tuple[2].split()
meson.add_install_script('meson-add-wants.sh', systemunitdir, target, file) add_wants += [systemunitdir, target, file]
endforeach endforeach
endif endif
endforeach endforeach
@ -314,13 +316,14 @@ foreach tuple : units
if tuple.length() > 2 if tuple.length() > 2
foreach target : tuple[2].split() foreach target : tuple[2].split()
meson.add_install_script( add_wants += [systemunitdir, target, file]
'meson-add-wants.sh', systemunitdir, target, file)
endforeach endforeach
endif endif
endif endif
endforeach endforeach
meson.add_install_script('meson-add-wants.sh', add_wants)
install_data('user-.slice.d/10-defaults.conf', install_data('user-.slice.d/10-defaults.conf',
install_dir : systemunitdir + '/user-.slice.d') install_dir : systemunitdir + '/user-.slice.d')