]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip vrf: Improve cgroup2 error messages
authorDavid Ahern <dsa@cumulusnetworks.com>
Fri, 6 Jan 2017 00:22:22 +0000 (16:22 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 9 Jan 2017 20:13:08 +0000 (12:13 -0800)
Currently, if a non-root user attempts to run ip vrf exec a non-helpful
error is returned:

$ ip vrf exec mgmt bash
Failed to mount cgroup2. Are CGROUPS enabled in your kernel?

Only show the CGROUPS kernel hint for the ENODEV error and for the
rest show the strerror for the errno. So now:

$ ip/ip vrf exec mgmt bash
Failed to mount cgroup2: Operation not permitted

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
lib/fs.c

index 644bb486ae8edbf88258a06a21442d75a29a1b9b..12a4657a0bc96baaa1f5982048a648183692c433 100644 (file)
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -80,13 +80,21 @@ char *find_cgroup2_mount(void)
 
        if (mount("none", mnt, CGROUP2_FS_NAME, 0, NULL)) {
                /* EBUSY means already mounted */
-               if (errno != EBUSY) {
+               if (errno == EBUSY)
+                       goto out;
+
+               if (errno == ENODEV) {
                        fprintf(stderr,
                                "Failed to mount cgroup2. Are CGROUPS enabled in your kernel?\n");
-                       free(mnt);
-                       return NULL;
+               } else {
+                       fprintf(stderr,
+                               "Failed to mount cgroup2: %s\n",
+                               strerror(errno));
                }
+               free(mnt);
+               return NULL;
        }
+out:
        return mnt;
 }