From: Lennart Poettering Date: Fri, 19 Oct 2018 09:42:11 +0000 (+0200) Subject: chown-recursive: TAKE_FD() is your friend X-Git-Tag: archive/raspbian/239-13+rpi1^2~29 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c2655149c14bc20b42e087cfb50ef15c6b993e2a;p=systemd.git chown-recursive: TAKE_FD() is your friend (cherry picked from commit cd6b7d50c337b3676a3d5fc2188ff298dcbdb939) Gbp-Pq: Name chown-recursive-TAKE_FD-is-your-friend.patch --- diff --git a/src/core/chown-recursive.c b/src/core/chown-recursive.c index 447b7712..7767301f 100644 --- a/src/core/chown-recursive.c +++ b/src/core/chown-recursive.c @@ -111,7 +111,6 @@ static int chown_recursive_internal(int fd, const struct stat *st, uid_t uid, gi int path_chown_recursive(const char *path, uid_t uid, gid_t gid) { _cleanup_close_ int fd = -1; struct stat st; - int r; fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME); if (fd < 0) @@ -130,8 +129,5 @@ int path_chown_recursive(const char *path, uid_t uid, gid_t gid) { (!gid_is_valid(gid) || st.st_gid == gid)) return 0; - r = chown_recursive_internal(fd, &st, uid, gid); - fd = -1; /* we donated the fd to the call, regardless if it succeeded or failed */ - - return r; + return chown_recursive_internal(TAKE_FD(fd), &st, uid, gid); /* we donate the fd to the call, regardless if it succeeded or failed */ }