coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nice: clamp the niceness correctly on GNU/Hurd


From: Collin Funk
Subject: Re: nice: clamp the niceness correctly on GNU/Hurd
Date: Sun, 09 Nov 2025 19:02:06 -0800
User-agent: Gnus/5.13 (Gnus v5.13)

Hi PƔdraig,

PƔdraig Brady <P@draigBrady.com> writes:

> On 09/11/2025 11:00, PƔdraig Brady wrote:
>> On 09/11/2025 07:17, Collin Funk wrote:
>>> Collin Funk <collin.funk1@gmail.com> writes:
>>>
>>>> That test program assumes that nice() does not clamp the niceness to the
>>>> supported range as it is supposed to [1]. This is the case on GNU/Hurd,
>>>> so I will submit a bug report for that later.
>>>>
>>>> The output is the same on a normal and privileged user:
>>>>
>>>>       $ gcc main.c ./a.out
>>>>       starting nice: 0
>>>>       minimum nice: 0
>>>>       maximum nice: 38
>>>>       minimum errno: EPERM
>>>>       maximum errno: ESRCH
>>>>
>>>> This patch clamps it to the supported range and adds some tests. Here is
>>>> the corrected behavior:
>>>>
>>>>       $ ./src/nice -n +100 ./src/nice
>>>>       38
>>>
>>> Actually my original patch did not work if 'nice' was invoked with a
>>> niceness greater than zero. This v2 patch fixes that and adds more
>>> tests.
>> That's restricted to Hurd so looks safe to push.
>
> I should add that this should be reported to Hurd also,
> so it's a layering violation to do the workaround in user space,
> as we can't do it robustly because of races.

Apologies for the delay. Was busy with work, so couldn't get to it until
now.

Samuel Thibault, who maintains Hurd, changed the maximum niceness to 39
instead of 38 [1]. That value is equal to (2 * NZERO - 1) which brings
things more into alignment with other systems. He also made setpriority(2),
and therefore nice(2), clamp the niceness to the supported range [2].
That change will be in glibc 2.43.

Therefore, we can avoid the race with glibc 2.43 or newer. I also
adjusted the tests a bit to allow for the differing maximum niceness.
Otherwise the future Hurd release would fail.

Pushed the attached patch with those changes.

Collin

[1] 
https://git.savannah.gnu.org/cgit/hurd/gnumach.git/commit/?id=4e19e045e5c9e2207c6dd2965180d55d1a8c73e9
[2] 
https://inbox.sourceware.org/libc-alpha/20251109104433.1604563-1-samuel.thibault@ens-lyon.org/T/#m99c567494eec00dbac9298c0c38e16f7053996e6

Attachment: v3-0001-nice-clamp-the-niceness-correctly-on-GNU-Hurd.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]