mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH] nice: return EPERM instead of EACCES
@ 2021-06-29 13:31 Alexey Kodanev
  2021-06-29 14:48 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Kodanev @ 2021-06-29 13:31 UTC (permalink / raw)
  To: musl; +Cc: Alexey Kodanev

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH] nice: return EPERM instead of EACCES
  2021-06-29 13:31 [musl] [PATCH] nice: return EPERM instead of EACCES Alexey Kodanev
@ 2021-06-29 14:48 ` Rich Felker
  2021-06-29 15:45   ` Alexey Kodanev
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2021-06-29 14:48 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: musl

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH] nice: return EPERM instead of EACCES
  2021-06-29 14:48 ` Rich Felker
@ 2021-06-29 15:45   ` Alexey Kodanev
  2021-06-29 20:10     ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Kodanev @ 2021-06-29 15:45 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

On 29.06.2021 17:48, Rich Felker wrote:
> 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?

No, it's fine for setpriority(), it just seems wrong for nice()
to return EACCES in this case.

LTP/nice04 test (setting nice(-10)) is failing with musl and POSIX
indeed says that the errno should be EPERM, for nice().

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH] nice: return EPERM instead of EACCES
  2021-06-29 15:45   ` Alexey Kodanev
@ 2021-06-29 20:10     ` Rich Felker
  2021-08-03  9:18       ` Alexey Kodanev
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2021-06-29 20:10 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: musl

On Tue, Jun 29, 2021 at 06:45:42PM +0300, Alexey Kodanev wrote:
> On 29.06.2021 17:48, Rich Felker wrote:
> > 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?
> 
> No, it's fine for setpriority(), it just seems wrong for nice()
> to return EACCES in this case.
> 
> LTP/nice04 test (setting nice(-10)) is failing with musl and POSIX
> indeed says that the errno should be EPERM, for nice().

Oh, sorry, I read it backwards and was thinking it was replacing EPERM
with EACCES. Indeed nice is supposed to return EPERM where setpriority
would return EACCES so I think this patch is correct.

Rich

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] [PATCH] nice: return EPERM instead of EACCES
  2021-06-29 20:10     ` Rich Felker
@ 2021-08-03  9:18       ` Alexey Kodanev
  0 siblings, 0 replies; 5+ messages in thread
From: Alexey Kodanev @ 2021-08-03  9:18 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

On 29.06.2021 23:10, Rich Felker wrote:
> On Tue, Jun 29, 2021 at 06:45:42PM +0300, Alexey Kodanev wrote:
>> On 29.06.2021 17:48, Rich Felker wrote:
>>> 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?
>>
>> No, it's fine for setpriority(), it just seems wrong for nice()
>> to return EACCES in this case.
>>
>> LTP/nice04 test (setting nice(-10)) is failing with musl and POSIX
>> indeed says that the errno should be EPERM, for nice().
> 
> Oh, sorry, I read it backwards and was thinking it was replacing EPERM
> with EACCES. Indeed nice is supposed to return EPERM where setpriority
> would return EACCES so I think this patch is correct.
> 

Hi Rich,

I wonder what is the status of this patch, didn't find it in git... is
there any issue with it?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-03  9:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 13:31 [musl] [PATCH] nice: return EPERM instead of EACCES Alexey Kodanev
2021-06-29 14:48 ` Rich Felker
2021-06-29 15:45   ` Alexey Kodanev
2021-06-29 20:10     ` Rich Felker
2021-08-03  9:18       ` Alexey Kodanev

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ https://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git