nspawn: TAKE_FD() is your friend
This commit is contained in:
+5
-11
@@ -2812,7 +2812,7 @@ static int inner_child(
|
||||
}
|
||||
|
||||
static int setup_sd_notify_child(void) {
|
||||
int fd = -1;
|
||||
_cleanup_close_ int fd = -1;
|
||||
union sockaddr_union sa = {
|
||||
.un.sun_family = AF_UNIX,
|
||||
.un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH,
|
||||
@@ -2827,24 +2827,18 @@ static int setup_sd_notify_child(void) {
|
||||
(void) sockaddr_un_unlink(&sa.un);
|
||||
|
||||
r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
||||
if (r < 0) {
|
||||
safe_close(fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "bind(" NSPAWN_NOTIFY_SOCKET_PATH ") failed: %m");
|
||||
}
|
||||
|
||||
r = userns_lchown(NSPAWN_NOTIFY_SOCKET_PATH, 0, 0);
|
||||
if (r < 0) {
|
||||
safe_close(fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to chown " NSPAWN_NOTIFY_SOCKET_PATH ": %m");
|
||||
}
|
||||
|
||||
r = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &const_int_one, sizeof(const_int_one));
|
||||
if (r < 0) {
|
||||
safe_close(fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "SO_PASSCRED failed: %m");
|
||||
}
|
||||
|
||||
return fd;
|
||||
return TAKE_FD(fd);
|
||||
}
|
||||
|
||||
static int outer_child(
|
||||
|
||||
Reference in New Issue
Block a user