Avoid reusing open file descriptor to make it easier to pinpoint Coverity CID 1164479...
authorPetter Reinholdtsen <pere@hungry.com>
Fri, 7 Feb 2014 09:50:14 +0000 (09:50 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Fri, 7 Feb 2014 09:50:14 +0000 (09:50 +0000)
git-svn-id: svn://svn.sv.gnu.org/sysvinit/sysvinit/trunk@147 456724a4-4300-0410-8514-c89748c515a2

src/init.c

index 418755306708c99f1412ef95b94642879861bab3..2569a54018565b514b169ebbde3228cc70fa0b53 100644 (file)
@@ -1170,15 +1170,16 @@ pid_t spawn(CHILD *ch, int *res)
                        /* Set ioctl settings to default ones */
                        console_stty();
 
-               } else {
+               } else { /* parent */
+                       int fd;
                        setsid();
-                       if ((f = console_open(O_RDWR|O_NOCTTY)) < 0) {
+                       if ((fd = console_open(O_RDWR|O_NOCTTY)) < 0) {
                                initlog(L_VB, "open(%s): %s", console_dev,
                                        strerror(errno));
-                               f = open("/dev/null", O_RDWR);
+                               fd = open("/dev/null", O_RDWR);
                        }
-                       dup(f);
-                       dup(f);
+                       dup(fd);
+                       dup(fd);
                }
 
                /*