ip vrf: Improve cgroup2 error messages

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>
This commit is contained in:
David Ahern 2017-01-05 16:22:22 -08:00 committed by Stephen Hemminger
parent edbae5e0b2
commit 2bbc5b0726
1 changed files with 11 additions and 3 deletions

View File

@ -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;
}