|
|
a3e2b5 |
From c9630164b869e109bf2960968fc583449ccf0875 Mon Sep 17 00:00:00 2001
|
|
|
a3e2b5 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
a3e2b5 |
Date: Fri, 19 Oct 2018 11:42:11 +0200
|
|
|
a3e2b5 |
Subject: [PATCH] chown-recursive: TAKE_FD() is your friend
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(cherry-picked from commit cd6b7d50c337b3676a3d5fc2188ff298dcbdb939)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Related: #1643368
|
|
|
a3e2b5 |
---
|
|
|
a3e2b5 |
src/core/chown-recursive.c | 6 +-----
|
|
|
a3e2b5 |
1 file changed, 1 insertion(+), 5 deletions(-)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
diff --git a/src/core/chown-recursive.c b/src/core/chown-recursive.c
|
|
|
a3e2b5 |
index 447b771267..7767301f7d 100644
|
|
|
a3e2b5 |
--- a/src/core/chown-recursive.c
|
|
|
a3e2b5 |
+++ b/src/core/chown-recursive.c
|
|
|
a3e2b5 |
@@ -111,7 +111,6 @@ static int chown_recursive_internal(int fd, const struct stat *st, uid_t uid, gi
|
|
|
a3e2b5 |
int path_chown_recursive(const char *path, uid_t uid, gid_t gid) {
|
|
|
a3e2b5 |
_cleanup_close_ int fd = -1;
|
|
|
a3e2b5 |
struct stat st;
|
|
|
a3e2b5 |
- int r;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
|
|
|
a3e2b5 |
if (fd < 0)
|
|
|
a3e2b5 |
@@ -130,8 +129,5 @@ int path_chown_recursive(const char *path, uid_t uid, gid_t gid) {
|
|
|
a3e2b5 |
(!gid_is_valid(gid) || st.st_gid == gid))
|
|
|
a3e2b5 |
return 0;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
- r = chown_recursive_internal(fd, &st, uid, gid);
|
|
|
a3e2b5 |
- fd = -1; /* we donated the fd to the call, regardless if it succeeded or failed */
|
|
|
a3e2b5 |
-
|
|
|
a3e2b5 |
- return r;
|
|
|
a3e2b5 |
+ return chown_recursive_internal(TAKE_FD(fd), &st, uid, gid); /* we donate the fd to the call, regardless if it succeeded or failed */
|
|
|
a3e2b5 |
}
|