summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>1999-02-05 16:41:02 +0000
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>1999-02-05 16:41:02 +0000
commit28500009d46c3737af3a2e3480e38a5c7561db6b (patch)
treea7df5167af1bf91812aedb587745f5ab636fccdb /glib
parent319fb3361c801455a23c8ddc80943e777226c888 (diff)
downloadglib-28500009d46c3737af3a2e3480e38a5c7561db6b.tar.gz
Make the error message in case of a broken thread system a bit more
1999-02-05 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * configure.in: Make the error message in case of a broken thread system a bit more informative. * gutils.c (g_get_any_init): Changed the error logic again, now only leaving the memory doubling loop, when success is reached or when the user isn't found or when the buffer is 32k big, additionally now getpwuid will be run, if getpwuid_r didn't work out properly. A warning is issued however.
Diffstat (limited to 'glib')
-rw-r--r--glib/gutils.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/glib/gutils.c b/glib/gutils.c
index 321a1311f..04771cc79 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -448,10 +448,11 @@ g_get_any_init (void)
guint bufsize = 64;
gint error;
- do
+ while (1)
{
g_free (buffer);
buffer = g_malloc (bufsize);
+ errno = 0;
# ifdef HAVE_GETPWUID_R_POSIX
error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
@@ -461,21 +462,38 @@ g_get_any_init (void)
error = pw ? 0 : errno;
# endif /* !HAVE_GETPWUID_R_POSIX */
+ /* Now there are actually only 3 cases to leave the loop:
+ 1. pw != NULL -> all went fine.
+ 2. pw == NULL && ( error == 0 || error == ENOENT )
+ -> no such user (unlikely in the case of getuid ())
+ 3. bufsize > 32k -> the problem can't be of ERANGE type */
+ if (pw)
+ break;
+
+ if (pw == NULL && ( error == 0 || error == ENOENT))
+ {
+ g_warning ("getpwuid_r(): failed due to: No such user %d.",
+ getuid ());
+ break;
+ }
+
+ if (bufsize > 32 * 1024)
+ {
+ g_warning ("getpwuid_r(): failed due to: %s.",
+ g_strerror (error));
+ break;
+ }
+
bufsize *= 2;
- }
- while (error == ERANGE);
-
- if (error)
- g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error));
-
-# else /* !HAVE_GETPWUID_R */
-
- setpwent ();
- pw = getpwuid (getuid ());
- endpwent ();
-
+ }
# endif /* !HAVE_GETPWUID_R */
-
+
+ if (!pw)
+ {
+ setpwent ();
+ pw = getpwuid (getuid ());
+ endpwent ();
+ }
if (pw)
{
g_user_name = g_strdup (pw->pw_name);