chiark / gitweb /
udevd: disable OOM
authorKay Sievers <kay.sievers@suse.de>
Sat, 5 Nov 2005 18:41:00 +0000 (19:41 +0100)
committerKay Sievers <kay.sievers@suse.de>
Sat, 5 Nov 2005 18:41:00 +0000 (19:41 +0100)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
udevd.c

diff --git a/udevd.c b/udevd.c
index c49cf292cf349681574a9189c51af5ce6df50182..e2514e5947cc61f60c3ab3e4c94e6872bc632f39 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -814,7 +814,7 @@ static int init_uevent_netlink_sock(void)
 int main(int argc, char *argv[], char *envp[])
 {
        int retval;
 int main(int argc, char *argv[], char *envp[])
 {
        int retval;
-       int devnull;
+       int fd;
        struct sigaction act;
        fd_set readfds;
        const char *value;
        struct sigaction act;
        fd_set readfds;
        const char *value;
@@ -824,20 +824,20 @@ int main(int argc, char *argv[], char *envp[])
        int rc = 0;
 
        /* redirect std fd's, if the kernel forks us, we don't have them at all */
        int rc = 0;
 
        /* redirect std fd's, if the kernel forks us, we don't have them at all */
-       devnull = open("/dev/null", O_RDWR);
-       if (devnull >= 0) {
-               if (devnull != STDIN_FILENO)
-                       dup2(devnull, STDIN_FILENO);
-               if (devnull != STDOUT_FILENO)
-                       dup2(devnull, STDOUT_FILENO);
-               if (devnull != STDERR_FILENO)
-                       dup2(devnull, STDERR_FILENO);
-               if (devnull > STDERR_FILENO)
-                       close(devnull);
+       fd = open("/dev/null", O_RDWR);
+       if (fd >= 0) {
+               if (fd != STDIN_FILENO)
+                       dup2(fd, STDIN_FILENO);
+               if (fd != STDOUT_FILENO)
+                       dup2(fd, STDOUT_FILENO);
+               if (fd != STDERR_FILENO)
+                       dup2(fd, STDERR_FILENO);
+               if (fd > STDERR_FILENO)
+                       close(fd);
        }
 
        logging_init("udevd");
        }
 
        logging_init("udevd");
-       if (devnull < 0)
+       if (fd < 0)
                err("fatal, could not open /dev/null");
 
        udev_init_config();
                err("fatal, could not open /dev/null");
 
        udev_init_config();
@@ -889,13 +889,6 @@ int main(int argc, char *argv[], char *envp[])
                switch (pid) {
                case 0:
                        dbg("daemonized fork running");
                switch (pid) {
                case 0:
                        dbg("daemonized fork running");
-
-                       /* become session leader */
-                       sid = setsid();
-                       dbg("our session is %d", sid);
-
-                       chdir("/");
-                       umask(umask(077) | 022);
                        break;
                case -1:
                        err("fork of daemon failed");
                        break;
                case -1:
                        err("fork of daemon failed");
@@ -907,9 +900,25 @@ int main(int argc, char *argv[], char *envp[])
                }
        }
 
                }
        }
 
-       /* set a reasonable scheduling priority for the daemon */
+       /* set scheduling priority for the daemon */
        setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
 
        setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
 
+       chdir("/");
+       umask(077);
+
+       /* become session leader */
+       sid = setsid();
+       dbg("our session is %d", sid);
+
+       /* OOM_DISABLE == -17 */
+       fd = open("/proc/self/oom_adj", O_RDWR);
+       if (fd < 0)
+               err("error disabling OOM");
+       else {
+               write(fd, "-17", 3);
+               close(fd);
+       }
+
        /* setup signal handler pipe */
        retval = pipe(signal_pipe);
        if (retval < 0) {
        /* setup signal handler pipe */
        retval = pipe(signal_pipe);
        if (retval < 0) {