diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-15 19:45:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-15 19:45:37 +0200 |
commit | 271f518f35af9b27cb3f35d2d8a32b7f8e3bef22 (patch) | |
tree | 1debb0f940727a39745d01cff1dcf218a1614e41 /src/nspawn | |
parent | tree-wide: use sockaddr_un_unlink() at two more places where appropriate (diff) | |
download | systemd-271f518f35af9b27cb3f35d2d8a32b7f8e3bef22.tar.xz systemd-271f518f35af9b27cb3f35d2d8a32b7f8e3bef22.zip |
nspawn: TAKE_FD() is your friend
Diffstat (limited to 'src/nspawn')
-rw-r--r-- | src/nspawn/nspawn.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a6802d6938..fb360a6f4f 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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( |