From c5fd4a3dc46d186f815e4ac71578938d62544f01 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Sun, 24 Jan 1999 10:32:56 +0000 Subject: [PATCH] reverted raja's changes, since they leaked a struct passwd contents buffer Sun Jan 24 10:33:30 1999 Tim Janik * gutils.c (g_get_any_init): reverted raja's changes, since they leaked a struct passwd contents buffer and for the rest mostly substituted a while loop with a bunch of gotos. restored the getpwuid() code to what we had after my recent clean ups ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. to feature solaris behaviour of directly returning errno, we don't modify error anymore if it's > 0 and simply reset errno. don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. --- ChangeLog | 11 +++++++ ChangeLog.pre-2-0 | 11 +++++++ ChangeLog.pre-2-10 | 11 +++++++ ChangeLog.pre-2-12 | 11 +++++++ ChangeLog.pre-2-2 | 11 +++++++ ChangeLog.pre-2-4 | 11 +++++++ ChangeLog.pre-2-6 | 11 +++++++ ChangeLog.pre-2-8 | 11 +++++++ glib/gutils.c | 79 +++++++++++++--------------------------------- gutils.c | 79 +++++++++++++--------------------------------- 10 files changed, 132 insertions(+), 114 deletions(-) diff --git a/ChangeLog b/ChangeLog index abce29135..79be861ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index abce29135..79be861ad 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +Sun Jan 24 10:33:30 1999 Tim Janik + + * gutils.c (g_get_any_init): reverted raja's changes, since they leaked + a struct passwd contents buffer and for the rest mostly substituted a + while loop with a bunch of gotos. + restored the getpwuid() code to what we had after my recent clean ups + ("Sat Jan 23 02:14:28 1999 Tim Janik"), module yosh's recent changes. + to feature solaris behaviour of directly returning errno, we don't + modify error anymore if it's > 0 and simply reset errno. + don't reset g_home_dir for !NATIVE_WIN32 && !NATIVE_WIN32. + 1999-01-24 Raja R Harinath * gutils.c diff --git a/glib/gutils.c b/glib/gutils.c index da4b3d1d5..2dc06a47f 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -442,67 +442,36 @@ g_get_any_init (void) gpointer buffer = NULL; # ifdef HAVE_GETPWUID_R - struct passwd pwd; - guint bufsize = 1; /* sizeof (struct passwd); */ - gint error; + struct passwd pwd; + guint bufsize = 1; /* sizeof (struct passwd); */ + gint error; - pw_retry: - buffer = g_malloc (bufsize); - + do + { + g_free (buffer); + buffer = g_malloc (bufsize); + + errno = 0; # ifdef HAVE_GETPWUID_R_POSIX - /* There appears to be some confusion about what the return - value should be, and whether errno is set or not. - So, we are careful about it. */ - errno = 0; - error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - - if (error == 0) - goto pw_out; - - /* Some kind of error. - - SUSv2 says returned value is an error code; says nothing - about `errno'. GNU Libc says some non-null (sic) value and - errno is set. Either way, this code path is chosen. - - If `errno' isn't changed, the return value contains the - error code (like ERANGE). - - If `errno' is changed, then it must be right, irrespective - of whether the return value follows SUSv2 or not. */ - if (errno != 0) - error = errno; - + error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); + error = error < 1 ? errno : error; # else /* !HAVE_GETPWUID_R_POSIX */ - pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - if (pw != NULL) - goto pw_out; - /* If it got here, there is an error. The `uid' should be - valid, so there must be something else wrong. */ - error = errno; + pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); + error = pw ? 0 : errno; # endif /* !HAVE_GETPWUID_R_POSIX */ - /* If it came here, there's some kind of error. */ - g_free (buffer); + bufsize *= 2; + } + while (error == ERANGE); - if (error == ERANGE) - { - bufsize *= 2; - goto pw_retry; - } + if (error) + g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); - g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); - /* Make any subsequent g_free (buffer) a no-op. */ - buffer = NULL; - - pw_out: - ; - # else /* !HAVE_GETPWUID_R */ - setpwent (); - pw = getpwuid (getuid ()); - endpwent (); + setpwent (); + pw = getpwuid (getuid ()); + endpwent (); # endif /* !HAVE_GETPWUID_R */ @@ -529,11 +498,7 @@ g_get_any_init (void) g_real_name = g_strdup (buffer); } } -# else /* !NATIVE_WIN32 */ - /* why are we forcefully setting g_home_dir to NULL here? */ - g_free (g_home_dir); - g_home_dir = NULL; -# endif /* !NATIVE_WIN32 */ +# endif /* NATIVE_WIN32 */ #endif /* !HAVE_PWD_H */ diff --git a/gutils.c b/gutils.c index da4b3d1d5..2dc06a47f 100644 --- a/gutils.c +++ b/gutils.c @@ -442,67 +442,36 @@ g_get_any_init (void) gpointer buffer = NULL; # ifdef HAVE_GETPWUID_R - struct passwd pwd; - guint bufsize = 1; /* sizeof (struct passwd); */ - gint error; + struct passwd pwd; + guint bufsize = 1; /* sizeof (struct passwd); */ + gint error; - pw_retry: - buffer = g_malloc (bufsize); - + do + { + g_free (buffer); + buffer = g_malloc (bufsize); + + errno = 0; # ifdef HAVE_GETPWUID_R_POSIX - /* There appears to be some confusion about what the return - value should be, and whether errno is set or not. - So, we are careful about it. */ - errno = 0; - error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - - if (error == 0) - goto pw_out; - - /* Some kind of error. - - SUSv2 says returned value is an error code; says nothing - about `errno'. GNU Libc says some non-null (sic) value and - errno is set. Either way, this code path is chosen. - - If `errno' isn't changed, the return value contains the - error code (like ERANGE). - - If `errno' is changed, then it must be right, irrespective - of whether the return value follows SUSv2 or not. */ - if (errno != 0) - error = errno; - + error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); + error = error < 1 ? errno : error; # else /* !HAVE_GETPWUID_R_POSIX */ - pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - if (pw != NULL) - goto pw_out; - /* If it got here, there is an error. The `uid' should be - valid, so there must be something else wrong. */ - error = errno; + pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); + error = pw ? 0 : errno; # endif /* !HAVE_GETPWUID_R_POSIX */ - /* If it came here, there's some kind of error. */ - g_free (buffer); + bufsize *= 2; + } + while (error == ERANGE); - if (error == ERANGE) - { - bufsize *= 2; - goto pw_retry; - } + if (error) + g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); - g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); - /* Make any subsequent g_free (buffer) a no-op. */ - buffer = NULL; - - pw_out: - ; - # else /* !HAVE_GETPWUID_R */ - setpwent (); - pw = getpwuid (getuid ()); - endpwent (); + setpwent (); + pw = getpwuid (getuid ()); + endpwent (); # endif /* !HAVE_GETPWUID_R */ @@ -529,11 +498,7 @@ g_get_any_init (void) g_real_name = g_strdup (buffer); } } -# else /* !NATIVE_WIN32 */ - /* why are we forcefully setting g_home_dir to NULL here? */ - g_free (g_home_dir); - g_home_dir = NULL; -# endif /* !NATIVE_WIN32 */ +# endif /* NATIVE_WIN32 */ #endif /* !HAVE_PWD_H */