for (size_t i = 0; i < arg_n_credentials; i++) {
_cleanup_free_ char *j = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
j = path_join(q, arg_credentials[i].id);
if (!j)
static int setup_kmsg(int fd_inner_socket) {
_cleanup_(unlink_and_freep) char *from = NULL;
_cleanup_free_ char *fifo = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(fd_inner_socket >= 0);
const char *directory,
bool secondary,
int fd_inner_socket,
- int master_pty_socket,
FDSet *fds,
char **os_release_pairs) {
if (r < 0)
return log_error_errno(r, "Failed to set up /dev/console: %m");
- r = send_one_fd(master_pty_socket, master, 0);
+ r = send_one_fd(fd_inner_socket, master, 0);
if (r < 0)
return log_error_errno(r, "Failed to send master fd: %m");
- master_pty_socket = safe_close(master_pty_socket);
r = setup_stdio_as_dev_console();
if (r < 0)
}
static int setup_notify_child(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
static const union sockaddr_union sa = {
.un.sun_family = AF_UNIX,
.un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH,
bool secondary,
int fd_outer_socket,
int fd_inner_socket,
- int master_pty_socket,
- int unified_cgroup_hierarchy_socket,
FDSet *fds,
int netns_fd) {
_cleanup_(bind_user_context_freep) BindUserContext *bind_user_context = NULL;
_cleanup_strv_free_ char **os_release_pairs = NULL;
- _cleanup_close_ int fd = -1, mntns_fd = -EBADF;
+ _cleanup_close_ int fd = -EBADF, mntns_fd = -EBADF;
bool idmap = false;
const char *p;
pid_t pid;
assert(barrier);
assert(directory);
assert(fd_outer_socket >= 0);
- assert(master_pty_socket >= 0);
assert(fd_inner_socket >= 0);
log_debug("Outer child is initializing.");
if (r < 0)
return r;
- l = send(unified_cgroup_hierarchy_socket, &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), MSG_NOSIGNAL);
+ l = send(fd_outer_socket, &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send cgroup mode: %m");
if (l != sizeof(arg_unified_cgroup_hierarchy))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short write while sending cgroup mode.");
-
- unified_cgroup_hierarchy_socket = safe_close(unified_cgroup_hierarchy_socket);
}
r = recursive_chown(directory, arg_uid_shift, arg_uid_range);
* directory mount to root later on.
* https://github.com/systemd/systemd/issues/3847#issuecomment-562735251
*/
- r = mount_switch_root(directory, MOUNT_ATTR_PROPAGATION_SHARED);
+ r = mount_switch_root(directory, MS_SHARED);
if (r < 0)
return log_error_errno(r, "Failed to move root directory: %m");
return log_error_errno(r, "Failed to join network namespace: %m");
}
- r = inner_child(barrier, directory, secondary, fd_inner_socket, master_pty_socket, fds, os_release_pairs);
+ r = inner_child(barrier, directory, secondary, fd_inner_socket, fds, os_release_pairs);
if (r < 0)
_exit(EXIT_FAILURE);
return log_error_errno(l, "Failed to send notify fd: %m");
fd_outer_socket = safe_close(fd_outer_socket);
- master_pty_socket = safe_close(master_pty_socket);
fd_inner_socket = safe_close(fd_inner_socket);
netns_fd = safe_close(netns_fd);
_cleanup_close_ int etc_passwd_lock = -1;
_cleanup_close_pair_ int
fd_inner_socket_pair[2] = { -EBADF, -EBADF },
- fd_outer_socket_pair[2] = { -EBADF, -EBADF },
- master_pty_socket_pair[2] = { -1, -1 },
- unified_cgroup_hierarchy_socket_pair[2] = { -1, -1};
+ fd_outer_socket_pair[2] = { -EBADF, -EBADF };
_cleanup_close_ int notify_socket = -1, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
_cleanup_(barrier_destroy) Barrier barrier = BARRIER_NULL;
int ifi = 0, r;
ssize_t l;
sigset_t mask_chld;
- _cleanup_close_ int child_netns_fd = -1;
+ _cleanup_close_ int child_netns_fd = -EBADF;
assert_se(sigemptyset(&mask_chld) == 0);
assert_se(sigaddset(&mask_chld, SIGCHLD) == 0);
if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, fd_outer_socket_pair) < 0)
return log_error_errno(errno, "Failed to create outer socket pair: %m");
- if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, master_pty_socket_pair) < 0)
- return log_error_errno(errno, "Failed to create console socket pair: %m");
-
- if (arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_UNKNOWN)
- if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, unified_cgroup_hierarchy_socket_pair) < 0)
- return log_error_errno(errno, "Failed to create unified cgroup socket pair: %m");
-
/* Child can be killed before execv(), so handle SIGCHLD in order to interrupt
* parent's blocking calls and give it a chance to call wait() and terminate. */
r = sigprocmask(SIG_UNBLOCK, &mask_chld, NULL);
fd_inner_socket_pair[0] = safe_close(fd_inner_socket_pair[0]);
fd_outer_socket_pair[0] = safe_close(fd_outer_socket_pair[0]);
- master_pty_socket_pair[0] = safe_close(master_pty_socket_pair[0]);
- unified_cgroup_hierarchy_socket_pair[0] = safe_close(unified_cgroup_hierarchy_socket_pair[0]);
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
secondary,
fd_outer_socket_pair[1],
fd_inner_socket_pair[1],
- master_pty_socket_pair[1],
- unified_cgroup_hierarchy_socket_pair[1],
fds,
child_netns_fd);
if (r < 0)
fd_inner_socket_pair[1] = safe_close(fd_inner_socket_pair[1]);
fd_outer_socket_pair[1] = safe_close(fd_outer_socket_pair[1]);
- master_pty_socket_pair[1] = safe_close(master_pty_socket_pair[1]);
- unified_cgroup_hierarchy_socket_pair[1] = safe_close(unified_cgroup_hierarchy_socket_pair[1]);
if (arg_userns_mode != USER_NAMESPACE_NO) {
mntns_fd = receive_one_fd(fd_outer_socket_pair[0], 0);
if (arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_UNKNOWN) {
/* The child let us know the support cgroup mode it might have read from the image. */
- l = recv(unified_cgroup_hierarchy_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0);
+ l = recv(fd_outer_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0);
if (l < 0)
return log_error_errno(errno, "Failed to read cgroup mode: %m");
if (l != sizeof(arg_unified_cgroup_hierarchy))
}
if (arg_console_mode != CONSOLE_PIPE) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
PTYForwardFlags flags = 0;
/* Retrieve the master pty allocated by inner child */
- fd = receive_one_fd(master_pty_socket_pair[0], 0);
+ fd = receive_one_fd(fd_inner_socket_pair[0], 0);
if (fd < 0)
return log_error_errno(fd, "Failed to receive master pty from the inner child: %m");
return r;
if (r == 0) {
- _cleanup_close_ int parent_netns_fd = -1;
+ _cleanup_close_ int parent_netns_fd = -EBADF;
r = namespace_open(getpid(), NULL, NULL, &parent_netns_fd, NULL, NULL);
if (r < 0) {
}
static int cant_be_in_netns(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct ucred ucred;
int r;