I've recently written to pgsql-ports about a problem with PG7.0 on NT
authorBruce Momjian <bruce@momjian.us>
Tue, 7 Mar 2000 23:49:31 +0000 (23:49 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 7 Mar 2000 23:49:31 +0000 (23:49 +0000)
(Subj: [PORTS] initdb problem on NT with 7.0).  Since nobody helped me,
I had to find out the reson.  The difference between NT and Linux (for
instance) is that "open( path, O_RDWR );" opens a file in text mode.  So
sometime less block can be read than required.

I suggest a following patch.  BTW the situation appeared before, see
hba.c, pqcomm.c and others.

Alexei Zakharov

src/backend/access/transam/xlog.c

index 3bf62d7e50aa1624d7bd3ac857fa3400cd9c6bb8..e8d909f71efd649f7b941d0649b51ed8153e0107 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.10 2000/02/15 03:00:37 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.11 2000/03/07 23:49:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -726,7 +726,11 @@ XLogFileInit(uint32 log, uint32 seg)
        unlink(path);
 
 tryAgain:
+#ifndef __CYGWIN__
        fd = open(path, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+#else
+       fd = open(path, O_RDWR|O_CREAT|O_EXCL|O_BINARY, S_IRUSR|S_IWUSR);
+#endif
        if (fd < 0 && (errno == EMFILE || errno == ENFILE))
        {
                fd = errno;
@@ -767,7 +771,11 @@ XLogFileOpen(uint32 log, uint32 seg, bool econt)
        XLogFileName(path, log, seg);
 
 tryAgain:
+#ifndef __CYGWIN__
        fd = open(path, O_RDWR);
+#else
+       fd = open(path, O_RDWR | O_BINARY);
+#endif
        if (fd < 0 && (errno == EMFILE || errno == ENFILE))
        {
                fd = errno;
@@ -1083,7 +1091,11 @@ UpdateControlFile()
        int             fd;
 
 tryAgain:
+#ifndef __CYGWIN__
        fd = open(ControlFilePath, O_RDWR);
+#else
+       fd = open(ControlFilePath, O_RDWR | O_BINARY);
+#endif
        if (fd < 0 && (errno == EMFILE || errno == ENFILE))
        {
                fd = errno;
@@ -1145,7 +1157,11 @@ BootStrapXLOG()
        CheckPoint              checkPoint;
        XLogRecord         *record;
 
+#ifndef __CYGWIN__
        fd = open(ControlFilePath, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+#else
+       fd = open(ControlFilePath, O_RDWR|O_CREAT|O_EXCL|O_BINARY, S_IRUSR|S_IWUSR);
+#endif
        if (fd < 0)
                elog(STOP, "BootStrapXLOG failed to create control file (%s): %d", 
                                        ControlFilePath, errno);
@@ -1249,7 +1265,11 @@ StartupXLOG()
         * Open/read Control file
         */
 tryAgain:
+#ifndef __CYGWIN__
        fd = open(ControlFilePath, O_RDWR);
+#else
+       fd = open(ControlFilePath, O_RDWR | O_BINARY);
+#endif
        if (fd < 0 && (errno == EMFILE || errno == ENFILE))
        {
                fd = errno;