]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ulogd: Perform nice() before giving up root
authorChris Boot <bootc@bootc.net>
Sat, 11 May 2013 17:01:52 +0000 (18:01 +0100)
committerEric Leblond <eric@regit.org>
Tue, 21 May 2013 17:57:07 +0000 (19:57 +0200)
The daemon code currently tries to nice(-1) just after having given up root
privileges, which fails. This patch moves the nice(-1) call to just before
the code that gives up the required privileges.

Signed-off-by: Chris Boot <bootc@bootc.net>
src/ulogd.c

index 8f21cc277e9e77c4067a3c4b8215fa8738fdc719..76190d9474eadd1ea841520a58dffaa2f5f42fdc 100644 (file)
@@ -1235,6 +1235,13 @@ int main(int argc, char* argv[])
                warn_and_exit(daemonize);
        }
 
+       errno = 0;
+       if (nice(-1) == -1) {
+               if (errno != 0)
+                       ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
+                                 strerror(errno));
+       }
+
        if (change_uid) {
                ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
                if (setgid(gid)) {
@@ -1261,13 +1268,6 @@ int main(int argc, char* argv[])
                }
        }
 
-       errno = 0;
-       if (nice(-1) == -1) {
-               if (errno != 0)
-                       ulogd_log(ULOGD_ERROR, "Could not nice process: %s\n",
-                                 strerror(errno));
-       }
-
 
        if (daemonize){
                if (fork()) {