Check exit code from dup() in spawn() and log error if it fail.
authorPetter Reinholdtsen <pere@hungry.com>
Mon, 10 Feb 2014 22:47:27 +0000 (22:47 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Mon, 10 Feb 2014 22:47:27 +0000 (22:47 +0000)
Patch from Michał Kulling.

git-svn-id: svn://svn.sv.gnu.org/sysvinit/sysvinit/trunk@159 456724a4-4300-0410-8514-c89748c515a2

doc/Changelog
src/init.c

index 722aef235609761fe5934f966069d3abe3bc65ed..f5c8d600a063eec2622a151a539845295331bda8 100644 (file)
@@ -89,6 +89,8 @@ sysvinit (2.89) UNRELEASED; urgency=low
     define INIT_FIFO.
   * Use narrowly scoped file descriptor for handling opened TTY in
     spawn().  Patch from Michał Kulling.
+  * Check exit code from dup() in spawn() and log error if it fail.
+    Patch from Michał Kulling.
 
  -- Petter Reinholdtsen <pere@hungry.com>  Sun Apr 11 11:28:55 CEST 2010
 
index d6234fb6de77791397c9a640e78d92fbb9036ba5..20c2ecbdcb014f9fd2981eceb516e8026ac98311 100644 (file)
@@ -1111,8 +1111,15 @@ pid_t spawn(CHILD *ch, int *res)
                        if ((ftty = console_open(O_RDWR|O_NOCTTY)) >= 0) {
                                /* Take over controlling tty by force */
                                (void)ioctl(ftty, TIOCSCTTY, 1);
-                               dup(ftty);
-                               dup(ftty);
+
+                               if(dup(ftty) < 0){
+                                       initlog(L_VB, "cannot duplicate console fd");
+                               }
+                               
+                               if(dup(ftty) < 0){
+                                       initlog(L_VB, "cannot duplicate console fd");
+                               }
+
                        }
 
                        /*
@@ -1181,8 +1188,15 @@ pid_t spawn(CHILD *ch, int *res)
                                        strerror(errno));
                                fd = open("/dev/null", O_RDWR);
                        }
-                       dup(fd);
-                       dup(fd);
+
+                       if(dup(fd) < 0) {
+                               initlog(L_VB, "cannot duplicate /dev/null fd");
+                       }
+                       
+                       if(dup(fd) < 0) {
+                               initlog(L_VB, "cannot duplicate /dev/null fd");
+                       }
+
                }
 
                /*