[lxc-devel] [lxcfs/master] sysfs_fuse: cleanup

brauner on Github lxc-bot at linuxcontainers.org
Thu Mar 5 11:25:30 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200305/3256c150/attachment.bin>
-------------- next part --------------
From cf07826ef57054c5c80fa9c96b2a0116eaa4c285 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 12:24:29 +0100
Subject: [PATCH] sysfs_fuse: cleanup

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/sysfs_fuse.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/sysfs_fuse.c b/src/sysfs_fuse.c
index 83b2186..4b71633 100644
--- a/src/sysfs_fuse.c
+++ b/src/sysfs_fuse.c
@@ -98,10 +98,8 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size,
 		total_len = snprintf(d->buf, d->buflen, "0-%d\n", max_cpus - 1);
 	else
 		total_len = snprintf(d->buf, d->buflen, "0\n");
-	if (total_len < 0 || total_len >= d->buflen) {
-		lxcfs_error("%s\n", "failed to write to cache");
-		return 0;
-	}
+	if (total_len < 0 || total_len >= d->buflen)
+		return log_error(0, "Failed to write to cache");
 
 	d->size = (int)total_len;
 	d->cached = 1;
@@ -138,6 +136,7 @@ int sys_getattr(const char *path, struct stat *sb)
 	memset(sb, 0, sizeof(struct stat));
 	if (clock_gettime(CLOCK_REALTIME, &now) < 0)
 		return -EINVAL;
+
 	sb->st_uid = sb->st_gid = 0;
 	sb->st_atim = sb->st_mtim = sb->st_ctim = now;
 	if (strcmp(path, "/sys") == 0) {
@@ -145,21 +144,25 @@ int sys_getattr(const char *path, struct stat *sb)
 		sb->st_nlink = 2;
 		return 0;
 	}
+
 	if (strcmp(path, "/sys/devices") == 0) {
 		sb->st_mode = S_IFDIR | 00555;
 		sb->st_nlink = 2;
 		return 0;
 	}
+
 	if (strcmp(path, "/sys/devices/system") == 0) {
 		sb->st_mode = S_IFDIR | 00555;
 		sb->st_nlink = 2;
 		return 0;
 	}
+
 	if (strcmp(path, "/sys/devices/system/cpu") == 0) {
 		sb->st_mode = S_IFDIR | 00555;
 		sb->st_nlink = 2;
 		return 0;
 	}
+
 	if (strcmp(path, "/sys/devices/system/cpu/online") == 0) {
 		sb->st_size = 0;
 		sb->st_mode = S_IFREG | 00444;
@@ -174,31 +177,35 @@ int sys_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 		off_t offset, struct fuse_file_info *fi)
 {
 	if (strcmp(path, "/sys") == 0) {
-		if (filler(buf, ".", NULL, 0) != 0 ||
-		    filler(buf, "..", NULL, 0) != 0 ||
-		    filler(buf, "devices", NULL, 0) != 0)
+		if (filler(buf, ".",		NULL, 0) != 0 ||
+		    filler(buf, "..",		NULL, 0) != 0 ||
+		    filler(buf, "devices",	NULL, 0) != 0)
 			return -ENOENT;
+
 		return 0;
 	}
 	if (strcmp(path, "/sys/devices") == 0) {
-		if (filler(buf, ".", NULL, 0) != 0 ||
-		    filler(buf, "..", NULL, 0) != 0 ||
-		    filler(buf, "system", NULL, 0) != 0)
+		if (filler(buf, ".",		NULL, 0) != 0 ||
+		    filler(buf, "..",		NULL, 0) != 0 ||
+		    filler(buf, "system",	NULL, 0) != 0)
 			return -ENOENT;
+
 		return 0;
 	}
 	if (strcmp(path, "/sys/devices/system") == 0) {
-		if (filler(buf, ".", NULL, 0) != 0 ||
-		    filler(buf, "..", NULL, 0) != 0 ||
-		    filler(buf, "cpu", NULL, 0) != 0)
+		if (filler(buf, ".",	NULL, 0) != 0 ||
+		    filler(buf, "..",	NULL, 0) != 0 ||
+		    filler(buf, "cpu",	NULL, 0) != 0)
 			return -ENOENT;
+
 		return 0;
 	}
 	if (strcmp(path, "/sys/devices/system/cpu") == 0) {
-		if (filler(buf, ".", NULL, 0) != 0 ||
-		    filler(buf, "..", NULL, 0) != 0 ||
-		    filler(buf, "online", NULL, 0) != 0)
+		if (filler(buf, ".",		NULL, 0) != 0 ||
+		    filler(buf, "..",		NULL, 0) != 0 ||
+		    filler(buf, "online",	NULL, 0) != 0)
 			return -ENOENT;
+
 		return 0;
 	}
 
@@ -246,16 +253,21 @@ int sys_access(const char *path, int mask)
 {
 	if (strcmp(path, "/sys") == 0 && access(path, R_OK) == 0)
 		return 0;
+
 	if (strcmp(path, "/sys/devices") == 0 && access(path, R_OK) == 0)
 		return 0;
+
 	if (strcmp(path, "/sys/devices/system") == 0 && access(path, R_OK) == 0)
 		return 0;
+
 	if (strcmp(path, "/sys/devices/system/cpu") == 0 &&
 	    access(path, R_OK) == 0)
 		return 0;
+
 	/* these are all read-only */
 	if ((mask & ~R_OK) != 0)
 		return -EACCES;
+
 	return 0;
 }
 


More information about the lxc-devel mailing list