[git commit] runit: fix chpst -n -N -u USER

Denys Vlasenko vda.linux at googlemail.com
Mon Mar 13 21:35:30 UTC 2017


commit: https://git.busybox.net/busybox/commit/?id=018804204f41e6e60cec536843275f8fdd4d3620
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

busybox's chpst first switches user/group and then tries to call nice().
Once the root priviledges are dropped, process priority can only be lowered.
So negative nice values don't work anymore.
Upstream version of chpst correctly calls nice() before switching user.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 runit/chpst.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/runit/chpst.c b/runit/chpst.c
index 846c846..ee3a331 100644
--- a/runit/chpst.c
+++ b/runit/chpst.c
@@ -463,6 +463,13 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
 		xchroot(root);
 	}
 
+	/* nice should be done before xsetuid */
+	if (opt & OPT_n) {
+		errno = 0;
+		if (nice(xatoi(nicestr)) == -1)
+			bb_perror_msg_and_die("nice");
+	}
+
 	if (opt & OPT_u) {
 		if (setgroups(1, &ugid.gid) == -1)
 			bb_perror_msg_and_die("setgroups");
@@ -470,12 +477,6 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
 		xsetuid(ugid.uid);
 	}
 
-	if (opt & OPT_n) {
-		errno = 0;
-		if (nice(xatoi(nicestr)) == -1)
-			bb_perror_msg_and_die("nice");
-	}
-
 	if (opt & OPT_0)
 		close(STDIN_FILENO);
 	if (opt & OPT_1)


More information about the busybox-cvs mailing list