mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] nice: return EPERM instead of EACCES
Date: Tue, 29 Jun 2021 10:48:35 -0400	[thread overview]
Message-ID: <20210629144834.GP13220@brightrain.aerifal.cx> (raw)
In-Reply-To: <20210629133130.143543-1-aleksei.kodanev@bell-sw.com>

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

  reply	other threads:[~2021-06-29 14:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29 13:31 Alexey Kodanev
2021-06-29 14:48 ` Rich Felker [this message]
2021-06-29 15:45   ` Alexey Kodanev
2021-06-29 20:10     ` Rich Felker
2021-08-03  9:18       ` Alexey Kodanev
2022-03-08 22:16         ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210629144834.GP13220@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=aleksei.kodanev@bell-sw.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).