[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] start-stop-daemon: change priority before dropping privileges
From:       Aitor Esteve Alvarado <aesteve () singularaircraft ! com>
Date:       2019-03-07 9:14:48
Message-ID: 99654405-321b-08ae-9488-e4ffa896637e () singularaircraft ! com
[Download RAW message or body]

Currently start-stop-daemon fails when using both the -c option (set 
uid) and -N option (set niceness/priority) as it first drops privileges 
and then tries to increase the priority. This patch changes the order of 
execution.
---
  debianutils/start_stop_daemon.c | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/debianutils/start_stop_daemon.c 
b/debianutils/start_stop_daemon.c
index 3a4c1044a..d15f0c4ca 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -532,6 +532,15 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, 
char **argv)
  		/* User wants _us_ to make the pidfile */
  		write_pidfile(pidfile);
  	}
+#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
+	if (opt & OPT_NICELEVEL) {
+		/* Set process priority */
+		int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, 
INT_MIN/2, INT_MAX/2);
+		if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
+			bb_perror_msg_and_die("setpriority(%d)", prio);
+		}
+	}
+#endif
  	if (opt & OPT_c) {
  		struct bb_uidgid_t ugid;
  		parse_chown_usergroup_or_die(&ugid, chuid);
@@ -546,15 +555,6 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, 
char **argv)
  			setgroups(1, &ugid.gid);
  		}
  	}
-#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
-	if (opt & OPT_NICELEVEL) {
-		/* Set process priority */
-		int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, 
INT_MIN/2, INT_MAX/2);
-		if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
-			bb_perror_msg_and_die("setpriority(%d)", prio);
-		}
-	}
-#endif
  	/* Try:
  	 * strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000
  	 * should exec "/bin/usleep", but argv[0] should be "qwerty":
-- 
2.17.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic