From: Lennart Poettering Date: Mon, 15 Oct 2018 17:45:37 +0000 (+0200) Subject: nspawn: TAKE_FD() is your friend X-Git-Tag: v240~538^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=271f518f35af9b27cb3f35d2d8a32b7f8e3bef22;p=thirdparty%2Fsystemd.git nspawn: TAKE_FD() is your friend --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a6802d6938c..fb360a6f4f1 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(