nspawn: make failure in sd_listen_fds() critical

Also, drop doubled call of sd_listen_fds().
This commit is contained in:
Yu Watanabe
2025-03-19 02:09:40 +09:00
parent 024bb0c63e
commit b8d5303733
2 changed files with 16 additions and 12 deletions
+5 -8
View File
@@ -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
+11 -4
View File
@@ -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) {