Re: thread safety tests - Mailing list pgsql-hackers

From Jan Wieck
Subject Re: thread safety tests
Date
Msg-id 40C7311F.20201@Yahoo.com
Whole thread Raw
In response to Re: thread safety tests  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: thread safety tests
List pgsql-hackers
On 6/9/2004 11:16 AM, Bruce Momjian wrote:

> Jan Wieck wrote:
>> On 6/9/2004 9:36 AM, Bruce Momjian wrote:
>> 
>> > Jan Wieck wrote:
>> >> I am wondering why thread_test.c is checking for mktemp()? That function 
>> >> is nowhere used in the libpq.
>> > 
>> > Uh, it isn't checking for mktemp, it is using it, and it is using it
>> > because someone didn't like hard-coded paths I was using in the past. 
>> > Is there something wrong with using mktemp?  I have heard of no
>> > portability problems, except some need six X's, and we updated that.
>> 
>> There seems to be a portability issue here. Stefan Kaltenbrunner 
>> reported a configure failure on sparc64-unknown-openbsd3.5 and the 
>> config.log says:
>> 
>> /tmp//ccx22029.o: In function `main':
>> /tmp//ccx22029.o(.text+0x8c): warning: mktemp() possibly used unsafely; 
>> consider
>>   using mkstemp()
> 
> Yes, I was wondering how mktemp was going to guard against concurrent
> access.  I have applied the following patch to use mkstemp().
> 
>> Which is only a warning at this time, it fails later on getpwuid().
> 
> Oh, I will need to hear more about that failure.

The relevant part of the config.log is:

configure:17942: checking thread safety of required library functions
configure:17967: gcc -o conftest -O2 -fno-strict-aliasing -pthread 
-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS -DIN_CONFIGURE   conftest.c -lz -lreadline -lcurses -lresolv
-lcompat-lm
 
-lutil   >&5
/tmp//ccx22029.o: In function `main':
/tmp//ccx22029.o(.text+0x8c): warning: mktemp() possibly used unsafely; 
consider using mkstemp()
configure:17970: $? = 0
configure:17972: ./conftest
Your errno is thread-safe.
Your system has sterror_r();  it does not need strerror().
Your system uses getpwuid() which is not thread-safe. **
Your system has getaddrinfo();  it does not need gethostbyname()  or gethostbyname_r().

** YOUR PLATFORM IS NOT THREAD-SAFE. **
configure:17975: $? = 1
configure: program exited with status 1
configure: failed program was:
#line 17961 "configure"
#include "confdefs.h"
#include "./src/tools/thread/thread_test.c"
configure:17984: result: no
configure:17986: error:
*** Thread test program failed.  Your platform is not thread-safe.
*** Check the file 'config.log'for the exact reason.



> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/tools/thread/thread_test.c
> ===================================================================
> RCS file: /cvsroot/pgsql-server/src/tools/thread/thread_test.c,v
> retrieving revision 1.30
> diff -c -c -r1.30 thread_test.c
> *** src/tools/thread/thread_test.c    28 May 2004 18:37:10 -0000    1.30
> --- src/tools/thread/thread_test.c    9 Jun 2004 15:03:29 -0000
> ***************
> *** 104,110 ****
>   {
>       pthread_t    thread1,
>                   thread2;
> ! 
>       if (argc > 1)
>       {
>           fprintf(stderr, "Usage: %s\n", argv[0]);
> --- 104,111 ----
>   {
>       pthread_t    thread1,
>                   thread2;
> !     int            fd;
> !     
>       if (argc > 1)
>       {
>           fprintf(stderr, "Usage: %s\n", argv[0]);
> ***************
> *** 120,130 ****
>       /* Make temp filenames, might not have strdup() */
>       temp_filename_1 = malloc(strlen(TEMP_FILENAME_1) + 1);
>       strcpy(temp_filename_1, TEMP_FILENAME_1);
> !     mktemp(temp_filename_1);
>   
>       temp_filename_2 = malloc(strlen(TEMP_FILENAME_2) + 1);
>       strcpy(temp_filename_2, TEMP_FILENAME_2);
> !     mktemp(temp_filename_2);
>       
>   #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R)
>       if (gethostname(myhostname, MAXHOSTNAMELEN) != 0)
> --- 121,133 ----
>       /* Make temp filenames, might not have strdup() */
>       temp_filename_1 = malloc(strlen(TEMP_FILENAME_1) + 1);
>       strcpy(temp_filename_1, TEMP_FILENAME_1);
> !     fd = mkstemp(temp_filename_1);
> !     close(fd);
>   
>       temp_filename_2 = malloc(strlen(TEMP_FILENAME_2) + 1);
>       strcpy(temp_filename_2, TEMP_FILENAME_2);
> !     fd = mkstemp(temp_filename_2);
> !     close(fd);
>       
>   #if !defined(HAVE_GETADDRINFO) && !defined(HAVE_GETHOSTBYNAME_R)
>       if (gethostname(myhostname, MAXHOSTNAMELEN) != 0)


-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Assignment to array elements
Next
From: Bruce Momjian
Date:
Subject: Re: thread safety tests