chiark / gitweb /
don't fail too bad, if /dev/null does not exist
authorKay Sievers <kay.sievers@suse.de>
Sat, 13 Aug 2005 00:36:12 +0000 (02:36 +0200)
committerKay Sievers <kay.sievers@suse.de>
Sat, 13 Aug 2005 00:36:12 +0000 (02:36 +0200)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
udev_utils_run.c
udevd.c

index 44fb7f831624c4012c3564f25411a724e3b95ff5..cf633661e4b1e29ce20433bc446f408be797cd8c 100644 (file)
@@ -136,23 +136,19 @@ int run_program(const char *command, const char *subsystem,
 
                /* discard child output or connect to pipe */
                devnull = open("/dev/null", O_RDWR);
-               if (devnull < 0) {
+               if (devnull > 0) {
+                       dup2(devnull, STDIN_FILENO);
+                       if (outpipe[1] < 0)
+                               dup2(devnull, STDOUT_FILENO);
+                       if (errpipe[1] < 0)
+                               dup2(devnull, STDERR_FILENO);
+                       close(devnull);
+               } else
                        err("open /dev/null failed");
-                       exit(1);
-               }
-               dup2(devnull, STDIN_FILENO);
-
                if (outpipe[1] > 0)
                        dup2(outpipe[1], STDOUT_FILENO);
-               else
-                       dup2(devnull, STDOUT_FILENO);
-
                if (errpipe[1] > 0)
                        dup2(errpipe[1], STDERR_FILENO);
-               else
-                       dup2(devnull, STDERR_FILENO);
-
-               close(devnull);
                execv(arg, argv);
 
                /* we should never reach this */
diff --git a/udevd.c b/udevd.c
index 1575da8d5a3005c217f40431091a087bc6e59407..8423278d6cca0bc2715656469f1a2d67c94a73fc 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -785,7 +785,7 @@ int main(int argc, char *argv[], char *envp[])
 {
        int maxsockplus;
        int retval;
-       int fd;
+       int devnull;
        struct sigaction act;
        fd_set readfds;
        const char *value;
@@ -841,12 +841,12 @@ int main(int argc, char *argv[], char *envp[])
        setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
 
        /* Set fds to dev/null */
-       fd = open( "/dev/null", O_RDWR );
-       if (fd >= 0)  {
-               dup2(fd, STDIN_FILENO);
-               dup2(fd, STDOUT_FILENO);
-               dup2(fd, STDERR_FILENO);
-               close(fd);
+       devnull = open( "/dev/null", O_RDWR );
+       if (devnull > 0)  {
+               dup2(devnull, STDIN_FILENO);
+               dup2(devnull, STDOUT_FILENO);
+               dup2(devnull, STDERR_FILENO);
+               close(devnull);
        } else
                err("error opening /dev/null %s", strerror(errno));