This prevents that "chpst -n -1 PROG" always fails if the current nice
value is 0.
SUS 1997 to POSIX 2024 require that nice(2) returns the new nice value
on success. The nice value may be -1. The native system call of older
Linux returns 0 on success, but Linux with glibc >= 2.2.4 provides POSIX
conformance. FreeBSD still returns 0 on success. Ancient Unix returned
nothing, BTW :-)
https://pubs.opengroup.org/onlinepubs/007908799/xsh/nice.html
https://pubs.opengroup.org/onlinepubs/9799919799/functions/nice.html
https://man7.org/linux/man-pages/man2/nice.2.html
https://man.freebsd.org/cgi/man.cgi?query=nice&sektion=3
http://man.cat-v.org/unix_10th/2/nice
--
Regards,
Christian
From fce97c6c72a96529ae4bc7dcb081980179b925e1 Mon Sep 17 00:00:00 2001
From: Christian Franke <[email protected]>
Date: Sun, 1 Dec 2024 13:40:16 +0100
Subject: [PATCH] chpst: fix error check of nice(2) call
Check errno instead of return value because -1 is a valid return
value also on success.
Signed-off-by: Christian Franke <[email protected]>
---
runit/chpst.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/runit/chpst.c b/runit/chpst.c
index af777568f..cc757114d 100644
--- a/runit/chpst.c
+++ b/runit/chpst.c
@@ -466,7 +466,8 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
/* nice should be done before xsetuid */
if (opt & OPT_n) {
errno = 0;
- if (nice(xatoi(nicestr)) == -1)
+ nice(xatoi(nicestr));
+ if (errno)
bb_simple_perror_msg_and_die("nice");
}
--
2.45.1
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox