]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/util.c
Import changes from CUPS 1.4svn-r8704.
[thirdparty/cups.git] / scheduler / util.c
index 48716d3662b9a3884c35b60b246d6c77cb1ee86a..db920c225e28572fe7326ab9d9f5afbb1d09ed92 100644 (file)
@@ -282,7 +282,8 @@ cupsdPipeCommand(int        *pid,   /* O - Process ID or 0 on error */
                  char       **argv,    /* I - Arguments to pass to command */
                 int        user)       /* I - User to run as or 0 for current */
 {
-  int  fds[2];                         /* Pipe file descriptors */
+  int  fd,                             /* Temporary file descriptor */
+       fds[2];                         /* Pipe file descriptors */
 
 
  /*
@@ -344,11 +345,14 @@ cupsdPipeCommand(int        *pid, /* O - Process ID or 0 on error */
     if (!getuid() && user)
       setuid(user);                    /* Run as restricted user */
 
-    close(0);                          /* </dev/null */
-    open("/dev/null", O_RDONLY);
+    if ((fd = open("/dev/null", O_RDONLY)) > 0)
+    {
+      dup2(fd, 0);                     /* </dev/null */
+      close(fd);
+    }
 
-    close(1);                          /* >pipe */
-    dup(fds[1]);
+    dup2(fds[1], 1);                   /* >pipe */
+    close(fds[1]);
 
     cupsdExec(command, argv);
     exit(errno);