2010-07-16 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 16 Jul 2010 18:32:53 +0000 (18:32 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 16 Jul 2010 18:32:53 +0000 (18:32 -0000)
* src/gmisc-unix.c: include config.h. Fixes bug #609632.
Use getpwuid_r instead of getpwent_r.

svn path=/trunk/mono/; revision=160501

eglib/ChangeLog
eglib/configure.ac
eglib/src/gmisc-unix.c

index 1ae1f13e6b333606de3f9ed0a984ab913cf44ab6..5a0009926a0ea4244d3f55265f93d893c41cdaef 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-16 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * src/gmisc-unix.c: include config.h. Fixes bug #609632.
+       Use getpwuid_r instead of getpwent_r.
+
 2010-07-02  Zoltan Varga  <vargaz@gmail.com>
 
        * src/glib.h: Define gboolean as int32_t to match mono_bool.
index 6e10e94759e530014e82e96efd77f29a603f7e31..2447c5a9c91b2f29b2e913a0a7d29eaaf0f396a8 100644 (file)
@@ -72,7 +72,7 @@ AM_CONDITIONAL(TARGET_WIN32, test x$OS = xWIN32)
 
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(void *)
-AC_CHECK_FUNCS(strndup strlcpy getpwent_r strtok_r rewinddir vasprintf)
+AC_CHECK_FUNCS(strndup strlcpy getpwuid_r strtok_r rewinddir vasprintf)
 AM_CONDITIONAL(NEED_VASPRINTF, test x$have_vasprintf = x )
 AC_CHECK_LIB(iconv, iconv_open, LIBS="$LIBS -liconv")
 AC_CHECK_LIB(iconv, libiconv_open, LIBS="$LIBS -liconv")
index 26c20a8983cb88e33285ac5c0c1cac5e484b97d8..5d8cd2a739f807eb7ed4ec25de360a7eb3de25f9 100644 (file)
@@ -26,6 +26,7 @@
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <config.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <pthread.h>
@@ -81,27 +82,18 @@ g_get_home_dir (void)
        if (home_dir == NULL){
                pthread_mutex_lock (&home_lock);
                if (home_dir == NULL){
-#ifdef HAVE_GETPWENT_R
-                       struct passwd pwbuf, *track;
+#ifdef HAVE_GETPWUID_R
+                       struct passwd pw;
+                       struct passwd *result;
                        char buf [4096];
-                       uid_t uid;
-                       
-                       uid = getuid ();
-
-                       setpwent ();
-                       
-                       while (getpwent_r (&pwbuf, buf, sizeof (buf), &track) == 0){
-                               if (pwbuf.pw_uid == uid){
-                                       home_dir = g_strdup (pwbuf.pw_dir);
-                                       break;
-                               }
-                       }
-                       endpwent ();
+
+                       if (getpwuid_r (getuid (), &pw, buf, 4096, &result) == 0)
+                               home_dir = g_strdup (pw.pw_dir);
 #endif
                        if (home_dir == NULL)
                                home_dir = g_getenv ("HOME");
-                       pthread_mutex_unlock (&home_lock);
                }
+               pthread_mutex_unlock (&home_lock);
        }
        return home_dir;
 }