nice return value erroneously interpreted as error
from bugzilla ticket #1084
Gerrit Kuehn (Albert-Einstein-Institut, Max-Planck-Institut f?r Gravitationsphysik, Hannover-Instrumentation Group) 2017-03-27 07:02:26 PDT
Running daqd, I see the following error
[Mon Mar 27 15:42:04 2017] Unable to set to nice = -20 -error Unknown error -20
This comes from the following lines of code in daqd.cc (starting at line 1851 in tagged rcg-version 3.2.1):
int set_nice = nice(-20); if(set_nice != 0){ system_log(1, "Unable to set to nice = -20 -error %s\n",strerror(set_nice } else { system_log(1, "Set daqd to nice = -20\n"); }
However, "man 2 nice" says
[...] RETURN VALUE On success, the new nice value is returned (but see NOTES below). On error, -1 is returned, and errno is set appropriately. [...] NOTES SUSv2 and POSIX.1 specify that nice() should return the new nice value. However, the Linux system call and the nice() library function provided in older versions of (g)libc (earlier than glibc 2.2.4) return 0 on success. The new nice value can be found using getpriority(2).
Since glibc 2.2.4, nice() is implemented as a library function that
calls getpriority(2) to obtain the new nice value to be returned to the
caller. With this implementation, a successful call can legitimately
return -1. To reliably detect an error, set errno to 0 before the
call, and check its value when nice() returns -1.
The error detection code needs to be rewritten to comply with newer versions of glibc.
Keith Thorne (LIGO - Livingston Observatory) 2017-03-27 07:12:06 PDT
This can occur if the account being used to start daqd is not the root account and does not have the security privilege to set the nice priority to a negative value - There is a way to allow accounts to do this.
But yes the code needs better error trapping
Gerrit Kuehn (Albert-Einstein-Institut, Max-Planck-Institut f?r Gravitationsphysik, Hannover-Instrumentation Group) 2017-03-28 03:08:29 PDT
(In reply to comment #1 (moved))
This can occur if the account being used to start daqd is not the root account and does not have the security privilege to set the nice priority to a negative value - There is a way to allow accounts to do this.
This happens here even when running as root. The glibc-version is 2.23-r3, so the notes below apply, the return code on success is supposedly the new nice value, -20, which is interpreted as error (because it is not 0).