From b05d828b5c16606d267b3a7869329bdf7c2a4c68 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 13 May 2026 18:31:27 +0100 Subject: [PATCH 1/2] import: do not create foreign ns on cleanup if not needed The user ns is only used if the appropriate flag is set, so avoid creating it unless it is. This avoids a spurious EPERM error in TEST-13-NSPAWN.machined that is confusing when debugging failures [ 34.054] systemd-importd[504]: (transfer18) Imported 92%. [ 34.118] systemd-importd[504]: (transfer18) Failed to decode and write: Broken pipe [ 34.119] systemd-importd[504]: (transfer18) Exiting. [ 34.121] systemd-importd[504]: (transfer18) Failed to allocate transient user namespace: Operation not permitted [ 34.121] systemd-importd[504]: Transfer process failed with exit code 1. Follow-up for 1be8caa6be6f5a10a7dea5ac562a0df5c5fac2e9 --- src/import/import-common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/import/import-common.c b/src/import/import-common.c index 5f17084f9f..840eac210f 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -392,13 +392,14 @@ int import_remove_tree(const char *path, int *userns_fd, ImportFlags flags) { assert(path); assert(userns_fd); - r = import_make_foreign_userns(userns_fd); - if (r < 0) - return r; - /* Try the userns dance first, to remove foreign UID range owned trees */ - if (FLAGS_SET(flags, IMPORT_FOREIGN_UID)) + if (FLAGS_SET(flags, IMPORT_FOREIGN_UID)) { + r = import_make_foreign_userns(userns_fd); + if (r < 0) + return r; + (void) remove_tree_foreign(path, *userns_fd); + } r = rm_rf(path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD); if (r < 0) From 148c34dd6aa57d62079fca3c66dc1deeb2f3cbc6 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 13 May 2026 18:39:06 +0100 Subject: [PATCH 2/2] import: try to capture tar exit codes on failure TEST-13-NSPAWN.machined occasionally fails with a tar error, and it's hard to say what the problem is at the exit code is lost. Try to capture it. [ 34.054] systemd-importd[504]: (transfer18) Imported 92%. [ 34.118] systemd-importd[504]: (transfer18) Failed to decode and write: Broken pipe [ 34.119] systemd-importd[504]: (transfer18) Exiting. [ 34.121] systemd-importd[504]: (transfer18) Failed to allocate transient user namespace: Operation not permitted [ 34.121] systemd-importd[504]: Transfer process failed with exit code 1. Follow-up for b6e676ce41508e2aeea22202fc8f234126177f52 --- src/import/import-tar.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 4bd5978800..06ee56bd78 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -368,6 +368,17 @@ static int tar_import_process(TarImport *i) { r = decompressor_push(i->compress, i->buffer, i->buffer_size, tar_import_write, i); if (r < 0) { log_error_errno(r, "Failed to decode and write: %m"); + + /* Try to check the actual exit code from the child process, to make debugging easier */ + if (r == -EPIPE && pidref_is_set(&i->tar_pid)) { + int q = pidref_wait_for_terminate_and_check("tar", &i->tar_pid, WAIT_LOG); + pidref_done(&i->tar_pid); + if (q < 0) + r = q; + else if (q != EXIT_SUCCESS) + r = -EPROTO; + } + goto finish; }