Use getpwuid_r with the right signature, if available.

1999-01-20  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

	* gutils.c (g_get_any_init): Use getpwuid_r with the right
	signature, if available.

	* configure.in, acconfig.h: Test for existance of getpwuid_r and
	its signature.
This commit is contained in:
Sebastian Wilhelmi 1999-01-20 15:06:46 +00:00 committed by Sebastian Wilhelmi
parent 32dbc0d51c
commit 8c54935c34
12 changed files with 168 additions and 56 deletions

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -1,3 +1,11 @@
1999-01-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gutils.c (g_get_any_init): Use getpwuid_r with the right
signature, if available.
* configure.in, acconfig.h: Test for existance of getpwuid_r and
its signature.
Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi> Tue Jan 19 20:52:43 1999 Tor Lillqvist <tml@iki.fi>
* Makefile.am (EXTRA_DIST): Add new Win32 files. * Makefile.am (EXTRA_DIST): Add new Win32 files.

View File

@ -92,6 +92,7 @@
#undef G_THREAD_SOURCE #undef G_THREAD_SOURCE
#undef HAVE_GETPWUID_R_POSIX
/* #undef PACKAGE */ /* #undef PACKAGE */
/* #undef VERSION */ /* #undef VERSION */

View File

@ -685,6 +685,21 @@ if test x"$have_threads" != xnone; then
glib_save_LIBS="$LIBS" glib_save_LIBS="$LIBS"
LIBS="$LIBS $G_THREAD_LIBS" LIBS="$LIBS $G_THREAD_LIBS"
AC_CHECK_FUNCS(localtime_r rand_r) AC_CHECK_FUNCS(localtime_r rand_r)
if test "$ac_cv_header_pwd_h" = "yes"; then
AC_CHECK_FUNCS(getpwuid_r)
if test "$ac_cv_func_getpwuid_r" = "yes"; then
AC_MSG_CHECKING(whether getpwuid_r is posix like)
# getpwuid_r(0, NULL, NULL, 0) is the signature on
# solaris, if that is not found, the prog below won't
# compile, then the posix signature is assumed as
# the default.
AC_TRY_COMPILE([#include <pwd.h>],
[getpwuid_r(0, NULL, NULL, 0);],
[AC_MSG_RESULT(no)],
[AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_GETPWUID_R_POSIX)])
fi
fi
LIBS="$glib_save_LIBS" LIBS="$glib_save_LIBS"
fi fi

View File

@ -384,10 +384,6 @@ g_get_any_init (void)
{ {
if (!g_tmp_dir) if (!g_tmp_dir)
{ {
#ifdef HAVE_PWD_H
struct passwd *pw;
#endif
g_tmp_dir = g_strdup (g_getenv ("TMPDIR")); g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
if (!g_tmp_dir) if (!g_tmp_dir)
g_tmp_dir = g_strdup (g_getenv ("TMP")); g_tmp_dir = g_strdup (g_getenv ("TMP"));
@ -439,30 +435,50 @@ g_get_any_init (void)
#endif #endif
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
/* FIXME: we must actually use the getpwuid_r function here, as {
getpwuid is not MT-safe, but the prototype doesn't seem to be struct passwd *pw = NULL, pwd;
agreed upon on the different systems, i.e. it is gpointer buffer = NULL;
guint bufsize = sizeof (struct passwd);
struct passwd *getpwuid_r(uid_t uid, struct passwd * pwd, # ifdef HAVE_GETPWUID_R
char *buffer, int buflen); while (TRUE)
{
on solaris, but int error = 0;
buffer = g_realloc (buffer, bufsize);
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, # ifdef HAVE_GETPWUID_R_POSIX
size_t bufsize struct passwd **result); error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
if (error == 0)
on posix. weird. */ break;
setpwent (); # else /* HAVE_GETPWUID_R_POSIX */
pw = getpwuid (getuid ()); pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
endpwent (); if (pw)
break;
if (pw) error = errno;
{ # endif /* HAVE_GETPWUID_R_POSIX */
g_user_name = g_strdup (pw->pw_name); if (error != ERANGE)
g_real_name = g_strdup (pw->pw_gecos); g_error( "Could not read account information: %s",
if (!g_home_dir) g_strerror (error));
g_home_dir = g_strdup (pw->pw_dir); bufsize *= 2;
} }
# else /* HAVE_GETPWUID_R */
# if defined(G_THREADS_ENABLED) && defined(__GNUC__)
# warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'"
# warning "functions will not be MT-safe at their first call"
# warning "because there is no `getpwuid_r' on your system."
# endif
setpwent ();
pw = getpwuid (getuid ());
endpwent ();
# endif /* HAVE_GETPWUID_R */
if (pw)
{
g_user_name = g_strdup (pw->pw_name);
g_real_name = g_strdup (pw->pw_gecos);
if (!g_home_dir)
g_home_dir = g_strdup (pw->pw_dir);
}
g_free (buffer);
}
#else /* !HAVE_PWD_H */ #else /* !HAVE_PWD_H */
# ifdef NATIVE_WIN32 # ifdef NATIVE_WIN32
{ {

View File

@ -384,10 +384,6 @@ g_get_any_init (void)
{ {
if (!g_tmp_dir) if (!g_tmp_dir)
{ {
#ifdef HAVE_PWD_H
struct passwd *pw;
#endif
g_tmp_dir = g_strdup (g_getenv ("TMPDIR")); g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
if (!g_tmp_dir) if (!g_tmp_dir)
g_tmp_dir = g_strdup (g_getenv ("TMP")); g_tmp_dir = g_strdup (g_getenv ("TMP"));
@ -439,30 +435,50 @@ g_get_any_init (void)
#endif #endif
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
/* FIXME: we must actually use the getpwuid_r function here, as {
getpwuid is not MT-safe, but the prototype doesn't seem to be struct passwd *pw = NULL, pwd;
agreed upon on the different systems, i.e. it is gpointer buffer = NULL;
guint bufsize = sizeof (struct passwd);
struct passwd *getpwuid_r(uid_t uid, struct passwd * pwd, # ifdef HAVE_GETPWUID_R
char *buffer, int buflen); while (TRUE)
{
on solaris, but int error = 0;
buffer = g_realloc (buffer, bufsize);
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, # ifdef HAVE_GETPWUID_R_POSIX
size_t bufsize struct passwd **result); error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
if (error == 0)
on posix. weird. */ break;
setpwent (); # else /* HAVE_GETPWUID_R_POSIX */
pw = getpwuid (getuid ()); pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
endpwent (); if (pw)
break;
if (pw) error = errno;
{ # endif /* HAVE_GETPWUID_R_POSIX */
g_user_name = g_strdup (pw->pw_name); if (error != ERANGE)
g_real_name = g_strdup (pw->pw_gecos); g_error( "Could not read account information: %s",
if (!g_home_dir) g_strerror (error));
g_home_dir = g_strdup (pw->pw_dir); bufsize *= 2;
} }
# else /* HAVE_GETPWUID_R */
# if defined(G_THREADS_ENABLED) && defined(__GNUC__)
# warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'"
# warning "functions will not be MT-safe at their first call"
# warning "because there is no `getpwuid_r' on your system."
# endif
setpwent ();
pw = getpwuid (getuid ());
endpwent ();
# endif /* HAVE_GETPWUID_R */
if (pw)
{
g_user_name = g_strdup (pw->pw_name);
g_real_name = g_strdup (pw->pw_gecos);
if (!g_home_dir)
g_home_dir = g_strdup (pw->pw_dir);
}
g_free (buffer);
}
#else /* !HAVE_PWD_H */ #else /* !HAVE_PWD_H */
# ifdef NATIVE_WIN32 # ifdef NATIVE_WIN32
{ {