From: Yu Watanabe Date: Tue, 18 Mar 2025 16:38:18 +0000 (+0900) Subject: nspawn: make failure in sd_listen_fds() critical X-Git-Tag: v258-rc1~1051^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8d5303733e846ed39604731aab4d1f0fd245f3d;p=thirdparty%2Fsystemd.git nspawn: make failure in sd_listen_fds() critical Also, drop doubled call of sd_listen_fds(). --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 87cae525ca8..3004bfc1b7d 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5970,7 +5970,7 @@ static int run(int argc, char *argv[]) { bool remove_directory = false, remove_image = false, veth_created = false; _cleanup_close_ int master = -EBADF, userns_fd = -EBADF, mount_fd = -EBADF; _cleanup_fdset_free_ FDSet *fds = NULL; - int r, n_fd_passed, ret = EXIT_SUCCESS; + int r, ret = EXIT_SUCCESS; char veth_name[IFNAMSIZ] = ""; struct ExposeArgs expose_args = {}; _cleanup_(release_lock_file) LockFile tree_global_lock = LOCK_FILE_INIT, tree_local_lock = LOCK_FILE_INIT; @@ -6057,13 +6057,10 @@ static int run(int argc, char *argv[]) { * so just turning this off here means we only turn it off in nspawn itself, not any children. */ (void) ignore_signals(SIGPIPE); - n_fd_passed = sd_listen_fds(false); - if (n_fd_passed > 0) { - r = fdset_new_listen_fds(&fds, false); - if (r < 0) { - log_error_errno(r, "Failed to collect file descriptors: %m"); - goto finish; - } + r = fdset_new_listen_fds(&fds, /* unset = */ false); + if (r < 0) { + log_error_errno(r, "Failed to collect file descriptors: %m"); + goto finish; } /* The "default" umask. This is appropriate for most file and directory diff --git a/src/shared/fdset.c b/src/shared/fdset.c index 42092ada258..7f4b15b1790 100644 --- a/src/shared/fdset.c +++ b/src/shared/fdset.c @@ -254,25 +254,32 @@ int fdset_cloexec(FDSet *fds, bool b) { int fdset_new_listen_fds(FDSet **ret, bool unset) { _cleanup_(fdset_shallow_freep) FDSet *s = NULL; - int n, fd, r; + int n, r; assert(ret); /* Creates an fdset and fills in all passed file descriptors */ + n = sd_listen_fds(unset); + if (n < 0) + return n; + if (n == 0) { + *ret = NULL; + return 0; + } + s = fdset_new(); if (!s) return -ENOMEM; - n = sd_listen_fds(unset); - for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { + for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { r = fdset_put(s, fd); if (r < 0) return r; } *ret = TAKE_PTR(s); - return 0; + return n; } int fdset_to_array(FDSet *fds, int **ret) {