[lxc-devel] [lxcfs/master] bindings: use openat fd for fstatat(), unlinkat()

brauner on Github lxc-bot at linuxcontainers.org
Mon Aug 22 00:49:56 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 353 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160822/13000a84/attachment.bin>
-------------- next part --------------
From 1ccb348442426147af2c413f2c5fd749f115d298 Mon Sep 17 00:00:00 2001
From: Christian Brauner <cbrauner at suse.de>
Date: Mon, 22 Aug 2016 02:47:27 +0200
Subject: [PATCH] bindings: use openat fd for fstatat(), unlinkat()

Signed-off-by: Christian Brauner <cbrauner at suse.de>
---
 bindings.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/bindings.c b/bindings.c
index 1fa1027..140158d 100644
--- a/bindings.c
+++ b/bindings.c
@@ -563,7 +563,7 @@ int cgfs_create(const char *controller, const char *cg, uid_t uid, gid_t gid)
 	return 0;
 }
 
-static bool recursive_rmdir(const char *dirname, int fd)
+static bool recursive_rmdir(const char *dirname, int fd, int cfd)
 {
 	struct dirent *direntp;
 	DIR *dir;
@@ -587,9 +587,6 @@ static bool recursive_rmdir(const char *dirname, int fd)
 		struct stat mystat;
 		int rc;
 
-		if (!direntp)
-			break;
-
 		if (!strcmp(direntp->d_name, ".") ||
 		    !strcmp(direntp->d_name, ".."))
 			continue;
@@ -600,15 +597,15 @@ static bool recursive_rmdir(const char *dirname, int fd)
 			continue;
 		}
 
-		ret = fstatat(fd, pathname, &mystat, AT_SYMLINK_NOFOLLOW);
-		if (ret) {
+		rc = fstatat(cfd, pathname, &mystat, AT_SYMLINK_NOFOLLOW);
+		if (rc < 0) {
 #if DEBUG
 			fprintf(stderr, "%s: failed to stat %s: %s\n", __func__, pathname, strerror(errno));
 #endif
 			continue;
 		}
 		if (S_ISDIR(mystat.st_mode)) {
-			if (!recursive_rmdir(pathname, fd)) {
+			if (!recursive_rmdir(pathname, fd, cfd)) {
 #if DEBUG
 				fprintf(stderr, "Error removing %s\n", pathname);
 #endif
@@ -622,7 +619,7 @@ static bool recursive_rmdir(const char *dirname, int fd)
 		ret = false;
 	}
 
-	if (unlinkat(fd, dirname, AT_REMOVEDIR) < 0) {
+	if (unlinkat(cfd, dirname, AT_REMOVEDIR) < 0) {
 #if DEBUG
 		fprintf(stderr, "%s: failed to delete %s: %s\n", __func__, dirname, strerror(errno));
 #endif
@@ -654,7 +651,7 @@ bool cgfs_remove(const char *controller, const char *cg)
 	if (fd < 0)
 		return false;
 
-	return recursive_rmdir(dirnam, fd);
+	return recursive_rmdir(dirnam, fd, cfd);
 }
 
 bool cgfs_chmod_file(const char *controller, const char *file, mode_t mode)


More information about the lxc-devel mailing list