The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/378
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 925d5849986f5a3d5a819eecdbaa066c94a2d1bb Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Mon, 16 Mar 2020 22:16:51 +0100 Subject: [PATCH] tree-wide: add and use must_make_path_relative() Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/cgroups/cgfsng.c | 29 +++++------------------------ src/cgroups/cgroup_utils.h | 10 ++++++++++ src/proc_cpuview.c | 6 +----- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c index 4d4d4b2..8d3c53d 100644 --- a/src/cgroups/cgfsng.c +++ b/src/cgroups/cgfsng.c @@ -537,11 +537,7 @@ static bool cgfsng_get(struct cgroup_ops *ops, const char *controller, if (!h) return false; - if (is_relative(cgroup)) - path = must_make_path(cgroup, file, NULL); - else - path = must_make_path(".", cgroup, file, NULL); - + path = must_make_path_relative(cgroup, file, NULL); *value = readat_file(h->fd, path); return *value != NULL; } @@ -571,11 +567,7 @@ static int cgfsng_get_memory(struct cgroup_ops *ops, const char *cgroup, ret = CGROUP2_SUPER_MAGIC; } - if (is_relative(cgroup)) - path = must_make_path(cgroup, file, NULL); - else - path = must_make_path(".", cgroup, file, NULL); - + path = must_make_path_relative(cgroup, file, NULL); *value = readat_file(h->fd, path); if (!*value) ret = -1; @@ -592,11 +584,7 @@ static int cgfsng_get_memory_stats_fd(struct cgroup_ops *ops, const char *cgroup if (!h) return -1; - if (is_relative(cgroup)) - path = must_make_path(cgroup, "memory.stat", NULL); - else - path = must_make_path(".", cgroup, "memory.stat", NULL); - + path = must_make_path_relative(cgroup, "memory.stat", NULL); return openat(h->fd, path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW); } @@ -665,10 +653,7 @@ static int cgfsng_get_cpuset_cpus(struct cgroup_ops *ops, const char *cgroup, ret = CGROUP2_SUPER_MAGIC; *value = NULL; - if (is_relative(cgroup)) - path = must_make_path(cgroup, NULL); - else - path = must_make_path(".", cgroup, NULL); + path = must_make_path_relative(cgroup, NULL); cgroup_fd = openat_safe(h->fd, path); if (cgroup_fd < 0) { return -1; @@ -718,11 +703,7 @@ static int cgfsng_get_io(struct cgroup_ops *ops, const char *cgroup, else ret = CGROUP2_SUPER_MAGIC; - if (is_relative(cgroup)) - path = must_make_path(cgroup, file, NULL); - else - path = must_make_path(".", cgroup, file, NULL); - + path = must_make_path_relative(cgroup, file, NULL); *value = readat_file(h->fd, path); if (!*value) { if (errno == ENOENT) diff --git a/src/cgroups/cgroup_utils.h b/src/cgroups/cgroup_utils.h index 35e5a98..e626e3f 100644 --- a/src/cgroups/cgroup_utils.h +++ b/src/cgroups/cgroup_utils.h @@ -107,4 +107,14 @@ static inline bool is_relative(const char *s) return s && *s != '/'; } +#define must_make_path_relative(__first__, ...) \ + ({ \ + char *__ptr__; \ + if (*__first__ == '/') \ + __ptr__ = must_make_path(".", __first__, __VA_ARGS__); \ + else \ + __ptr__ = must_make_path(__first__, __VA_ARGS__); \ + __ptr__; \ + }) + #endif /* __LXC_CGROUP_UTILS_H */ diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c index 129e192..5c21bc4 100644 --- a/src/proc_cpuview.c +++ b/src/proc_cpuview.c @@ -243,11 +243,7 @@ static bool cgfs_param_exist(const char *controller, const char *cgroup, if (cfd < 0) return false; - if (is_relative(cgroup)) - path = must_make_path(cgroup, file, NULL); - else - path = must_make_path(".", cgroup, file, NULL); - + path = must_make_path_relative(cgroup, file, NULL); return (faccessat(cfd, path, F_OK, 0) == 0); }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel