Revert a last-minute 'optimization' in rev 1.99 that could cause fd 1 and 2 being...
authorFabian Keil <fk@fabiankeil.de>
Tue, 29 Dec 2009 13:15:24 +0000 (13:15 +0000)
committerFabian Keil <fk@fabiankeil.de>
Tue, 29 Dec 2009 13:15:24 +0000 (13:15 +0000)
Yay for procstat(1).

jcc.c

diff --git a/jcc.c b/jcc.c
index d17bce3..263a44f 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.307 2009/12/26 11:32:54 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.308 2009/12/26 11:34:01 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -3162,27 +3162,31 @@ int main(int argc, char **argv)
        * from sending stuff to the clients or servers.
        */
       fd = open("/dev/null", O_RDONLY);
-      if (fd > 0)
+      if (fd == -1)
+      {
+         log_error(LOG_LEVEL_FATAL, "Failed to open /dev/null: %E");
+      }
+      else if (fd != 0)
       {
          if (dup2(fd, 0) == -1)
          {
             log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 0: %E");
          }
          close(fd);
-         fd = open("/dev/null", O_WRONLY);
-         if ((fd >= 0) && (fd != 1))
-         {
-            if (dup2(fd, 1) == -1)
-            {
-               log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 1: %E");
-            }
-            close(fd);
-         }
       }
+      fd = open("/dev/null", O_WRONLY);
       if (fd == -1)
       {
          log_error(LOG_LEVEL_FATAL, "Failed to open /dev/null: %E");
       }
+      else if (fd != 1)
+      {
+         if (dup2(fd, 1) == -1)
+         {
+            log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 1: %E");
+         }
+         close(fd);
+      }
 
       chdir("/");