Skip site navigation (1) Skip section navigation (2)

Re: BUG #6166: configure from source fails with 'This platform is not thread-safe.' but was actually /tmp perms

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alex Soto <apsoto(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6166: configure from source fails with 'This platform is not thread-safe.' but was actually /tmp perms
Date: 2011-08-22 01:23:43
Message-ID: 201108220123.p7M1NhF02914@momjian.us (view raw or flat)
Thread:
Lists: pgsql-bugs
Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> (The error message seems to be suffering from a bad case of copy-and-
> >> paste-itis, too.)
> 
> > Actually, it is accurate.  The code is:
> 
> > 	#ifdef WIN32
> > 	    h1 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL);
> > 	    h2 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
> > 	    if (h1 == INVALID_HANDLE_VALUE || GetLastError() != ERROR_FILE_EXISTS)
> > 	#else
> > 	    if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT, 0600) < 0 ||
> > 	        open(TEMP_FILENAME_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
> > 	#endif
> > 	    {
> > 	        fprintf(stderr, "Could not create file in current directory or\n");
> > 	        fprintf(stderr, "could not generate failure for create file in current directory **\nexiting\n");
> > 	        exit(1);
> > 	    }
> 
> > This code generates an errno == EEXIST in one thread, while another
> > thread generates errno == ENOENT, and this is how we test for errno
> > being thread-safe.  If you have a cleaner way to do this, please let me
> > know.  mkdir()?
> 
> The problem with that is you're trying to make one error message serve
> for two extremely different failure conditions.  I think this should be
> coded more like
> 
> 	    if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT, 0600) < 0)
> 	    {
> 		report suitable failure message;
> 		exit(1);
> 	    }
> 	    if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
> 	    {
> 		report suitable failure message;
> 		exit(1);
> 	    }
> 
> You would probably find that the messages could be a lot more clear and
> specific if they were done like that.  Also, a file-related error
> message that doesn't provide the filename nor strerror(errno) is pretty
> much wrong on its face, in my book.

OK, I split apart the two operations with the attached, applied patch. 
There must be an easier way to generate two unique errno values in a
platform-indepentent way, but I can't find it.  I did simplify the
second ENOENT generation by just doing unlink twice.

I can't just set errno to a different value, can I?

I am not able to use strerror because I don't know if that is
thread-safe yet.  I do have a C comment about it:

        /*
         * strerror() might not be thread-safe, and we already spawned thread
         * 1 that uses it, so avoid using it.
         */

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

Attachment: /rtmp/thread.diff
Description: text/x-diff (3.5 KB)

In response to

pgsql-bugs by date

Next:From: Heikki LinnakangasDate: 2011-08-22 06:57:29
Subject: Re: BUG #6170: hot standby wedging on full-WAL disk
Previous:From: Tom LaneDate: 2011-08-21 23:03:40
Subject: Re: BUG #6172: DROP EXTENSION error without CASCADE

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group