I saw a new test failure this morning on fedora 12. One was because of syntax errors in the new test, when using a non-conforming "nice" program.
The second was because Eric's new test exposed a flaw in our existing nice program: it doesn't run the selected program when setpriority fails with EACCES. I'm about to add a NEWS update for the bug fix in 1/2. >From 889da57f1a4f5f5d60360f683d4bafdc2a5a7bac Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Sat, 24 Oct 2009 13:50:13 +0200 Subject: [PATCH 1/2] nice: execute program even when setpriority fails due to EACCES * src/nice.c (perm_related_errno): New function. (main): Use it, rather than testing only errno == EPERM. --- src/nice.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/nice.c b/src/nice.c index b04f675..e157db8 100644 --- a/src/nice.c +++ b/src/nice.c @@ -86,6 +86,12 @@ With no COMMAND, print the current niceness. Nicenesses range from\n\ exit (status); } +static bool +perm_related_errno (int err) +{ + return err == EACCES || err == EPERM; +} + int main (int argc, char **argv) { @@ -179,7 +185,8 @@ main (int argc, char **argv) ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0); #endif if (!ok) - error (errno == EPERM ? 0 : EXIT_CANCELED, errno, _("cannot set niceness")); + error (perm_related_errno (errno) ? 0 + : EXIT_CANCELED, errno, _("cannot set niceness")); execvp (argv[i], &argv[i]); -- 1.6.5.1.324.g6e63a >From fd733b56bf64c0528785a45d5e82dbeb92b0662b Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Sat, 24 Oct 2009 13:53:05 +0200 Subject: [PATCH 2/2] tests: nice: adjust new tests to work more portably * tests/misc/nice (tests): Accommodate a nice program for which "nice -n -1 nice" prints nothing. It should print -1 or (usually) 0. Otherwise, we'd get syntax errors. --- tests/misc/nice | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/misc/nice b/tests/misc/nice index f271eb4..cf4d96b 100755 --- a/tests/misc/nice +++ b/tests/misc/nice @@ -75,7 +75,7 @@ while :; do done # Test negative niceness - command must be run whether or not change happens. -if test `nice -n -1 nice 2> /dev/null` = 0 ; then +if test x`nice -n -1 nice 2> /dev/null` = x0 ; then # unprivileged user - warn about failure to change nice -n -1 true 2> err || fail=1 test -s err || fail=1 @@ -86,8 +86,8 @@ else # superuser - change succeeds nice -n -1 nice 2> err || fail=1 test -s err && fail=1 - test `nice -n -1 nice` = -1 || fail=1 - test `nice --1 nice` = -1 || fail=1 + test x`nice -n -1 nice` = x-1 || fail=1 + test x`nice --1 nice` = x-1 || fail=1 fi Exit $fail -- 1.6.5.1.324.g6e63a
