Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e97f45

Browse files
committed
Document threading status.
Update to POSIX getpwuid_r() function.
1 parenta4a31d3 commit8e97f45

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

‎src/port/thread.c

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,41 @@
77
*
88
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
99
*
10-
* $Id: thread.c,v 1.2 2003/08/08 03:09:56 momjian Exp $
10+
* $Id: thread.c,v 1.3 2003/08/14 05:27:18 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include"postgres.h"
1616

17+
/*
18+
*Threading sometimes requires specially-named versions of functions
19+
*that return data in static buffers, like strerror_r() instead of
20+
*strerror(). Other operating systems use pthread_setspecific()
21+
*and pthread_getspecific() internally to allow standard library
22+
*functions to return static data to threaded applications.
23+
*
24+
*Additional confusion exists because many operating systems that
25+
*use pthread_setspecific/pthread_getspecific() also have *_r versions
26+
*of standard library functions for compatibility with operating systems
27+
*that require them. However, internally, these *_r functions merely
28+
*call the thread-safe standard library functions.
29+
*
30+
*For example, BSD/OS 4.3 uses Bind 8.2.3 for getpwuid(). Internally,
31+
*getpwuid() calls pthread_setspecific/pthread_getspecific() to return
32+
*static data to the caller in a thread-safe manner. However, BSD/OS
33+
*also has getpwuid_r(), which merely calls getpwuid() and shifts
34+
*around the arguments to match the getpwuid_r() function declaration.
35+
*Therefore, while BSD/OS has getpwuid_r(), it isn't required. It also
36+
*doesn't have strerror_r(), so we can't fall back to only using *_r
37+
*functions for threaded programs.
38+
*
39+
*The current setup is to assume either all standard functions are
40+
*thread-safe (NEED_REENTRANT_FUNC_NAMES=no), or the operating system
41+
*requires reentrant function names (NEED_REENTRANT_FUNC_NAMES=yes).
42+
*/
43+
44+
1745
/*
1846
* Wrapper around strerror and strerror_r to use the former if it is
1947
* available and also return a more useful value (the error string).
@@ -34,19 +62,20 @@ pqStrerror(int errnum, char *strerrbuf, size_t buflen)
3462

3563
/*
3664
* Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r()
37-
* behaviour, if it is not available.
65+
* behaviour, if it is not available or required.
3866
*/
3967
int
40-
pqGetpwuid(uid_tuid,structpasswd*resultbuf,char*buffer,
41-
size_tbuflen,structpasswd**result)
68+
pqGetpwuid(uid_tuid,structpasswd*resultbuf,char*buffer,
69+
size_tbuflen,structpasswd**result)
4270
{
4371
#if defined(USE_THREADS)&& defined(HAVE_GETPWUID_R)
44-
4572
/*
46-
* broken (well early POSIX draft) getpwuid_r() which returns 'struct
47-
* passwd *'
73+
* Early POSIX draft of getpwuid_r() returns 'struct passwd *'.
74+
* getpwuid_r(uid, resultbuf, buffer, buflen)
75+
* Do we need to support it? bjm 2003-08-14
4876
*/
49-
*result=getpwuid_r(uid,resultbuf,buffer,buflen);
77+
/* POSIX version */
78+
getpwuid_r(uid,resultbuf,buffer,buflen,result);
5079
#else
5180
/* no getpwuid_r() available, just use getpwuid() */
5281
*result=getpwuid(uid);
@@ -56,13 +85,13 @@ pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
5685

5786
/*
5887
* Wrapper around gethostbyname() or gethostbyname_r() to mimic
59-
* POSIX gethostbyname_r() behaviour, if it is not available.
88+
* POSIX gethostbyname_r() behaviour, if it is not available or required.
6089
*/
6190
int
6291
pqGethostbyname(constchar*name,
63-
structhostent*resbuf,
92+
structhostent*resbuf,
6493
char*buf,size_tbuflen,
65-
structhostent**result,
94+
structhostent**result,
6695
int*herrno)
6796
{
6897
#if defined(USE_THREADS)&& defined(HAVE_GETHOSTBYNAME_R)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp