From a13fda9e670b685a058af50b05e627a090574016 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 30 Jun 2025 23:12:36 +0200 Subject: [PATCH 1/5] machinectl: fix status output indentation All other status output lines use tabs, use that for the ID shift line too. otherwise output will appear unaligned if log viewers have fixed tab stop positions. --- src/machine/machinectl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 20fe2d1b0f..116d5ef74d 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -484,7 +484,7 @@ static int print_uid_shift(sd_bus *bus, const char *name) { if (shift == 0) /* Don't show trivial mappings */ return 0; - printf(" UID Shift: %" PRIu32 "\n", shift); + printf("\tID Shift: %" PRIu32 "\n", shift); return 0; } From 93555abe292e5f90165d89193e2ea0fd44de5c07 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 12 Jun 2025 17:37:45 +0200 Subject: [PATCH 2/5] nspawn: don't use strjoina() for user controlled strings --- src/nspawn/nspawn-register.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c index b746d09530..1582069505 100644 --- a/src/nspawn/nspawn-register.c +++ b/src/nspawn/nspawn-register.c @@ -266,7 +266,7 @@ int allocate_scope( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL; _cleanup_free_ char *scope = NULL; - const char *description, *object; + const char *object; int r; assert(bus); @@ -292,12 +292,14 @@ int allocate_scope( if (r < 0) return bus_log_create_error(r); - description = strjoina("Container ", machine_name); - r = bus_append_scope_pidref(m, pid, FLAGS_SET(flags, ALLOCATE_SCOPE_ALLOW_PIDFD)); if (r < 0) return bus_log_create_error(r); + _cleanup_free_ char *description = strjoin("Container ", machine_name); + if (!description) + return log_oom(); + r = sd_bus_message_append(m, "(sv)(sv)(sv)(sv)(sv)", "Description", "s", description, "Delegate", "b", 1, From 3779bdd5a3dde33b81c912ff7c672e65a5269d84 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 12 Jun 2025 17:38:04 +0200 Subject: [PATCH 3/5] nspawn: add argument comments to various calls --- src/nspawn/nspawn-register.c | 6 +++--- src/nspawn/nspawn.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c index 1582069505..5046f5d79c 100644 --- a/src/nspawn/nspawn-register.c +++ b/src/nspawn/nspawn-register.c @@ -389,11 +389,11 @@ int terminate_scope( _cleanup_free_ char *scope = NULL; int r; - r = unit_name_mangle_with_suffix(machine_name, "to terminate", 0, ".scope", &scope); + r = unit_name_mangle_with_suffix(machine_name, "to terminate", /* flags= */ 0, ".scope", &scope); if (r < 0) return log_error_errno(r, "Failed to mangle scope name: %m"); - r = bus_call_method(bus, bus_systemd_mgr, "AbandonScope", &error, NULL, "s", scope); + r = bus_call_method(bus, bus_systemd_mgr, "AbandonScope", &error, /* ret_reply= */ NULL, "s", scope); if (r < 0) { log_debug_errno(r, "Failed to abandon scope '%s', ignoring: %s", scope, bus_error_message(&error, r)); sd_bus_error_free(&error); @@ -414,7 +414,7 @@ int terminate_scope( sd_bus_error_free(&error); } - r = bus_call_method(bus, bus_systemd_mgr, "UnrefUnit", &error, NULL, "s", scope); + r = bus_call_method(bus, bus_systemd_mgr, "UnrefUnit", &error, /* ret_reply= */ NULL, "s", scope); if (r < 0) log_debug_errno(r, "Failed to drop reference to scope '%s', ignoring: %s", scope, bus_error_message(&error, r)); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 27d26f9809..e3ffc8c41d 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5483,13 +5483,13 @@ static int run_container( r = sd_bus_match_signal_async( bus, - NULL, + /* ret= */ NULL, "org.freedesktop.systemd1", - NULL, + /* path= */ NULL, "org.freedesktop.systemd1.Scope", "RequestStop", on_request_stop, - NULL, + /* install_callback= */ NULL, pid); if (r < 0) return log_error_errno(r, "Failed to request RequestStop match: %m"); From ba4624ff6cd4c8cf0ca4f16759187fee73e2dbfc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 16 Jun 2025 10:45:47 +0200 Subject: [PATCH 4/5] nspawn: fix parser of --notify-ready= This switch takes a bool only, not an enum, hence don't claim otherwise in the error log message. --- src/nspawn/nspawn.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index e3ffc8c41d..f0cfd4f1aa 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1332,11 +1332,10 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_NOTIFY_READY: - r = parse_boolean(optarg); + r = parse_boolean_argument("--notify-ready=", optarg, &arg_notify_ready); if (r < 0) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg); - arg_notify_ready = r; + return r; + arg_settings_mask |= SETTING_NOTIFY_READY; break; From 5279acb58d9df0b136f4d2931e7b88c1c09a966a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 16 Jun 2025 10:52:26 +0200 Subject: [PATCH 5/5] vmspawn: tighten parser of EXIT_STATUS= The EXIT_STATUS is supposed to encapuslate an ANSI C process exit status, which is 8bit unsigned. Hence parse it as such, do not accept negative values, or values > 255. --- src/vmspawn/vmspawn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 0a3ac89255..a3dd1432b2 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -727,9 +727,12 @@ static int read_vsock_notify(NotifyConnectionData *d, int fd) { p = strv_find_startswith(tags, "EXIT_STATUS="); if (p) { - r = safe_atoi(p, d->exit_status); + uint8_t k = 0; + r = safe_atou8(p, &k); if (r < 0) log_warning_errno(r, "Failed to parse exit status from %s, ignoring: %m", p); + else + *d->exit_status = k; } return 1; /* done */