Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 29 Jun 2021 10:48:35 -0400
From: Rich Felker <dalias@...c.org>
To: Alexey Kodanev <aleksei.kodanev@...l-sw.com>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] nice: return EPERM instead of EACCES

On Tue, Jun 29, 2021 at 04:31:30PM +0300, Alexey Kodanev wrote:
> To comply with POSIX, change errno from EACCES to EPERM
> when the caller did not have the required privilege.
> ---
>  src/unistd/nice.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/unistd/nice.c b/src/unistd/nice.c
> index 6c25c8c3..1c2295ff 100644
> --- a/src/unistd/nice.c
> +++ b/src/unistd/nice.c
> @@ -1,4 +1,5 @@
>  #include <unistd.h>
> +#include <errno.h>
>  #include <sys/resource.h>
>  #include <limits.h>
>  #include "syscall.h"
> @@ -12,5 +13,11 @@ int nice(int inc)
>  		prio += getpriority(PRIO_PROCESS, 0);
>  	if (prio > NZERO-1) prio = NZERO-1;
>  	if (prio < -NZERO) prio = -NZERO;
> -	return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio;
> +	if (setpriority(PRIO_PROCESS, 0, prio)) {
> +		if (errno == EACCES)
> +			errno = EPERM;
> +		return -1;
> +	} else {
> +		return prio;
> +	}
>  }
> -- 
> 2.25.1

Is there actually an issue here? setpriority is specified to fail with
EACCES already for this case; EPERM is only specified for targeting
other processes you don't have permission to target. Is Linux getting
this wrong for setpriority?

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.