[lxc-devel] [lxcfs/master] Fix `get_min_memlimit()` on non-glibc
devplayer0 on Github
lxc-bot at linuxcontainers.org
Thu Sep 3 21:47:02 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 716 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200903/73a390f1/attachment.bin>
-------------- next part --------------
From db36731bf3598d0f6fe5f493b1df59ed6edd16ce Mon Sep 17 00:00:00 2001
From: Jack O'Sullivan <jackos1998 at gmail.com>
Date: Thu, 3 Sep 2020 22:39:05 +0100
Subject: [PATCH] Fix `get_min_memlimit()` on non-glibc
Signed-off-by: Jack O'Sullivan <j at ckos.ie>
---
src/proc_fuse.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index a99162c..7e957d0 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -213,6 +213,25 @@ static uint64_t get_memlimit(const char *cgroup, bool swap)
return memlimit;
}
+/*
+ * dirname() behaves differently on musl than glibc, so implement the bits we
+ * need (the path in this case is always absolute and never ends in a `/`)
+ */
+static char *cgroup_parent(char *cgroup)
+{
+ if (strcmp(cgroup, "/") == 0) {
+ return cgroup;
+ }
+
+ char *last_slash = strrchr(cgroup, '/');
+ if (last_slash == cgroup) {
+ last_slash++;
+ }
+ *last_slash = '\0';
+
+ return cgroup;
+}
+
static uint64_t get_min_memlimit(const char *cgroup, bool swap)
{
__do_free char *copy = NULL;
@@ -227,7 +246,7 @@ static uint64_t get_min_memlimit(const char *cgroup, bool swap)
while (strcmp(copy, "/") != 0) {
char *it = copy;
- it = dirname(it);
+ it = cgroup_parent(it);
memlimit = get_memlimit(it, swap);
if (memlimit > 0 && memlimit < retlimit)
retlimit = memlimit;
More information about the lxc-devel
mailing list