Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2366-0006ET-LL for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Sep 2018 23:38:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2365-0007oL-5K for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Sep 2018 23:38:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2364-0007oE-Ql for pgsql-hackers@lists.postgresql.org; Mon, 17 Sep 2018 23:38:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2362-0000dY-Eh for pgsql-hackers@lists.postgresql.org; Mon, 17 Sep 2018 23:38:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w8HNcOB7011149; Mon, 17 Sep 2018 19:38:24 -0400 From: Tom Lane To: Michael Paquier cc: pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Allow concurrent-safe open() and fopen() in frontend code for Wi In-reply-to: <3883.1537200836@sss.pgh.pa.us> References: <23543.1536938575@sss.pgh.pa.us> <20180914224939.GA1178@paquier.xyz> <20180917114113.GA31460@paquier.xyz> <17194.1537191697@sss.pgh.pa.us> <20180917140202.GF31460@paquier.xyz> <19655.1537195712@sss.pgh.pa.us> <3883.1537200836@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 17 Sep 2018 12:13:56 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <11041.1537227334.0@sss.pgh.pa.us> Date: Mon, 17 Sep 2018 19:38:24 -0400 Message-ID: <11148.1537227504@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11041.1537227334.1@sss.pgh.pa.us> So we seem to be out of the woods in terms of 0ba06e0bf breaking the regression tests, but I'm not very happy about the whole thing, because that patch wasn't supposed to change the behavior of open/fopen in any way other than allowing concurrent file access. Obviously, it did. After looking at src/port/open.c a bit, it seems like the problem is that our fopen() requires a nonstandard "t" option to select text mode. I'd always supposed that you got binary mode with "b" and text mode otherwise; is there some third possibility on Windows? Anyway, I'm inclined to propose that we ought to do something like the attached in HEAD and v11 in order to reduce the risk that there are other unexpected behavioral changes. This should also let us revert 0ba06e0bf's change in initdb.c. I wonder whether pgwin32_open() also ought to enforce that either O_BINARY or O_TEXT mode gets selected. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="force-either-binary-or-text-open-mode.patch"; charset="us-ascii" Content-ID: <11041.1537227334.2@sss.pgh.pa.us> Content-Description: force-either-binary-or-text-open-mode.patch diff --git a/src/port/open.c b/src/port/open.c index a3ad946..85ab06e 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -154,7 +154,7 @@ pgwin32_fopen(const char *fileName, const char *mode) if (strchr(mode, 'b')) openmode |= O_BINARY; - if (strchr(mode, 't')) + else openmode |= O_TEXT; fd = pgwin32_open(fileName, openmode); diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index b53d6eb..cb8c745 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -491,15 +491,7 @@ readfile(const char *path) char *buffer; int c; -#ifdef WIN32 - /* - * On Windows, we have to open the file in text mode so that carriage - * returns are stripped. - */ - if ((infile = fopen(path, "rt")) == NULL) -#else if ((infile = fopen(path, "r")) == NULL) -#endif { fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"), progname, path, strerror(errno)); ------- =_aaaaaaaaaa0--