diff mbox

[iproute2,2/3] ip vrf: Improve cgroup2 error messages

Message ID 1483662143-15242-3-git-send-email-dsa@cumulusnetworks.com
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

David Ahern Jan. 6, 2017, 12:22 a.m. UTC
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 | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Sergei Shtylyov Jan. 6, 2017, 9:45 a.m. UTC | #1
Hello!

On 1/6/2017 3:22 AM, David Ahern wrote:

> 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 | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/lib/fs.c b/lib/fs.c
> index 644bb486ae8e..12a4657a0bc9 100644
> --- 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));
>  		}

    How about a *switch* instead?

> +		free(mnt);
> +		return NULL;
>  	}
> +out:
>  	return mnt;
>  }
>

MBR, Sergei
David Ahern Jan. 6, 2017, 3:05 p.m. UTC | #2
>> @@ -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));
>>          }
> 
>    How about a *switch* instead?

I did consider it. Did not make the code simpler or easier to read.
diff mbox

Patch

diff --git a/lib/fs.c b/lib/fs.c
index 644bb486ae8e..12a4657a0bc9 100644
--- 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;
 }