diff options
-rw-r--r-- | src/start-stop-daemon/start-stop-daemon.c | 13 | ||||
-rw-r--r-- | src/supervise-daemon/supervise-daemon.c | 8 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/start-stop-daemon/start-stop-daemon.c b/src/start-stop-daemon/start-stop-daemon.c index 9117f92f..e439388f 100644 --- a/src/start-stop-daemon/start-stop-daemon.c +++ b/src/start-stop-daemon/start-stop-daemon.c @@ -878,11 +878,23 @@ int main(int argc, char **argv) devnull_fd = open("/dev/null", O_RDWR); + /* Must call setsid() before setting autogroup nicelevel + * but after opening tty_fd. */ + setsid(); + if (nicelevel != INT_MIN) { if (setpriority(PRIO_PROCESS, mypid, nicelevel) == -1) eerrorx("%s: setpriority %d: %s", applet, nicelevel, strerror(errno)); + /* Open in "r+" mode to avoid creating if non-existent. */ + fp = fopen("/proc/self/autogroup", "r+"); + if (fp) { + fprintf(fp, "%d\n", nicelevel); + fclose(fp); + } else if (errno != ENOENT) + eerrorx("%s: autogroup nice %d: %s", applet, + nicelevel, strerror(errno)); } if (ionicec != -1 && @@ -1118,7 +1130,6 @@ int main(int argc, char **argv) eerrorx("Failed to set scheduler parameters: %s", strerror(errno)); } - setsid(); execvp(exec, argv); #ifdef HAVE_PAM if (changeuser != NULL && pamr == PAM_SUCCESS) diff --git a/src/supervise-daemon/supervise-daemon.c b/src/supervise-daemon/supervise-daemon.c index 58946716..68490ad4 100644 --- a/src/supervise-daemon/supervise-daemon.c +++ b/src/supervise-daemon/supervise-daemon.c @@ -391,6 +391,14 @@ static void child_process(char *exec, char **argv) if (setpriority(PRIO_PROCESS, getpid(), nicelevel) == -1) eerrorx("%s: setpriority %d: %s", applet, nicelevel, strerror(errno)); + /* Open in "r+" mode to avoid creating if non-existent. */ + fp = fopen("/proc/self/autogroup", "r+"); + if (fp) { + fprintf(fp, "%d\n", nicelevel); + fclose(fp); + } else if (errno != ENOENT) + eerrorx("%s: autogroup nice %d: %s", applet, + nicelevel, strerror(errno)); } if (ionicec != -1 && ioprio_set(1, getpid(), ionicec | ioniced) == -1) |