From: Fabian Keil <fk@fabiankeil.de>
Date: Tue, 29 Dec 2009 13:15:24 +0000 (+0000)
Subject: Revert a last-minute 'optimization' in rev 1.99 that could cause fd 1 and 2 being... 
X-Git-Tag: v_3_0_16~95
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/developer-manual/static/faq/static/@default-cgi@toggle?a=commitdiff_plain;h=9ea7da694a83f6983ce4e9cc2f0e5a9215527f5e;p=privoxy.git

Revert a last-minute 'optimization' in rev 1.99 that could cause fd 1 and 2 being bound to logfp.

Yay for procstat(1).
---

diff --git a/jcc.c b/jcc.c
index d17bce32..263a44fe 100644
--- 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("/");