Don't pass an invalid file handle to dup2(). That causes a crash on
authorHeikki Linnakangas <[email protected]>
Thu, 1 Apr 2010 20:12:43 +0000 (20:12 +0000)
committerHeikki Linnakangas <[email protected]>
Thu, 1 Apr 2010 20:12:43 +0000 (20:12 +0000)
Windows, thanks to a feature in CRT called Parameter Validation.

Back to 8.2, which is the oldest version supported on Windows. In
8.2 and 8.3 also back the earlier change to use DEVNULL instead of
NULL_DEV #define for a /dev/null-like device. NULL_DEV was hard-coded to
"/dev/null" regardless of platform, which didn't work on Windows, while
DEVNULL works on all platforms. Restarting syslogger didn't work on
Windows on versions 8.3 and below because of that.

src/backend/postmaster/postmaster.c
src/backend/postmaster/syslogger.c
src/include/c.h

index 3883a451225957dbb9200bdb146d08e5ea5a5efa..69f37c02ad7e0d4f087d5da5b816f51f17d4a2b5 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.505.2.7 2009/12/02 17:41:39 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.505.2.8 2010/04/01 20:12:42 heikki Exp $
  *
  * NOTES
  *
@@ -1107,7 +1107,7 @@ pmdaemonize(void)
        ExitPostmaster(1);
    }
 #endif
-   i = open(NULL_DEV, O_RDWR, 0);
+   i = open(DEVNULL, O_RDWR, 0);
    dup2(i, 0);
    dup2(i, 1);
    dup2(i, 2);
index 5ac5b6edffaf952244b153e375104df44fa3a7b3..430e1c82949bda4c6491b2fe5d4736d63137b942 100644 (file)
@@ -18,7 +18,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.29.2.4 2007/09/22 18:19:24 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.29.2.5 2010/04/01 20:12:42 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -180,7 +180,7 @@ SysLoggerMain(int argc, char *argv[])
     */
    if (redirection_done)
    {
-       int         fd = open(NULL_DEV, O_WRONLY, 0);
+       int         fd = open(DEVNULL, O_WRONLY, 0);
 
        /*
         * The closes might look redundant, but they are not: we want to be
@@ -190,9 +190,12 @@ SysLoggerMain(int argc, char *argv[])
         */
        close(fileno(stdout));
        close(fileno(stderr));
-       dup2(fd, fileno(stdout));
-       dup2(fd, fileno(stderr));
-       close(fd);
+       if (fd != -1)
+       {
+           dup2(fd, fileno(stdout));
+           dup2(fd, fileno(stderr));
+           close(fd);
+       }
    }
 
    /* Syslogger's own stderr can't be the syslogPipe, so set it back to
index 61400a7f6824833d40148a19a82f1a7406767aa3..b91f58bf6034bee9ebf472c2c98570915ed915a5 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/c.h,v 1.214.2.1 2007/01/11 02:40:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/c.h,v 1.214.2.2 2010/04/01 20:12:43 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -748,7 +748,11 @@ typedef NameData *Name;
 #include <unistd.h>
 #endif
 
-/* These are for things that are one way on Unix and another on NT */
+/*
+ * This only works on Unix, not on Windows! This isn't used in PostgreSQL
+ * anymore, use the platform-aware DEVNULL instead. This is kept here just
+ * in case a 3rd party module uses it.
+ */
 #define NULL_DEV       "/dev/null"
 
 /*