summaryrefslogtreecommitdiff
path: root/gio/gunixmounts.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2008-02-10 05:20:00 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-02-10 05:20:00 +0000
commit0766a1ec399f2dcd707249ed45b13dfbd239f382 (patch)
tree1b95874a6b0befe8326eda566e83b1b07af39eac /gio/gunixmounts.c
parent8ad07dcf1c0c3b24bc31086849b7305c7ab6070d (diff)
downloadglib-0766a1ec399f2dcd707249ed45b13dfbd239f382.tar.gz
Consistently use getmntent_r() and fall back to getmntent(). (#515492)
2008-02-09 Matthias Clasen <mclasen@redhat.com> * gunixmounts.c: Consistently use getmntent_r() and fall back to getmntent(). (#515492) svn path=/trunk/; revision=6490
Diffstat (limited to 'gio/gunixmounts.c')
-rw-r--r--gio/gunixmounts.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 70e658f14..222dc9752 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -324,11 +324,17 @@ get_mtab_monitor_file (void)
#endif
}
+#ifndef HAVE_GETMNTENT_R
G_LOCK_DEFINE_STATIC(getmntent);
+#endif
static GList *
_g_get_unix_mounts ()
{
+#ifdef HAVE_GETMNTENT_R
+ struct mntent ent;
+ char buf[1024];
+#endif
struct mntent *mntent;
FILE *file;
char *read_file;
@@ -346,8 +352,12 @@ _g_get_unix_mounts ()
mounts_hash = g_hash_table_new (g_str_hash, g_str_equal);
+#ifdef HAVE_GETMNTENT_R
+ while ((mntent = getmntent_r (file, &ent, buf, sizeof (buf))) != NULL)
+#else
G_LOCK (getmntent);
while ((mntent = getmntent (file)) != NULL)
+#endif
{
/* ignore any mnt_fsname that is repeated and begins with a '/'
*
@@ -392,7 +402,9 @@ _g_get_unix_mounts ()
endmntent (file);
+#ifndef HAVE_GETMNTENT_R
G_UNLOCK (getmntent);
+#endif
return g_list_reverse (return_list);
}
@@ -608,6 +620,10 @@ get_fstab_file (void)
static GList *
_g_get_unix_mount_points (void)
{
+#ifdef HAVE_GETMNTENT_R
+ struct mntent ent;
+ char buf[1024];
+#endif
struct mntent *mntent;
FILE *file;
char *read_file;
@@ -622,8 +638,12 @@ _g_get_unix_mount_points (void)
return_list = NULL;
+#ifdef HAVE_GETMNTENT_R
+ while ((mntent = getmntent_r (file, &ent, buf, sizeof (buf))) != NULL)
+#else
G_LOCK (getmntent);
while ((mntent = getmntent (file)) != NULL)
+#endif
{
if ((strcmp (mntent->mnt_dir, "ignore") == 0) ||
(strcmp (mntent->mnt_dir, "swap") == 0))
@@ -661,7 +681,10 @@ _g_get_unix_mount_points (void)
}
endmntent (file);
+
+#ifndef HAVE_GETMNTENT_R
G_UNLOCK (getmntent);
+#endif
return g_list_reverse (return_list);
}
@@ -2017,19 +2040,28 @@ _resolve_dev_root (void)
*/
f = fopen ("/etc/mtab", "r");
if (f != NULL) {
+ struct mntent *entp;
+#ifdef HAVE_GETMNTENT_R
struct mntent ent;
-
- while (getmntent_r (f, &ent, buf, sizeof (buf)) != NULL) {
-
- if (stat (ent.mnt_fsname, &statbuf) == 0 &&
+ while ((entp = getmntent_r (f, &ent, buf, sizeof (buf))) != NULL) {
+#else
+ G_LOCK (getmntent);
+ while ((entp = getmntent (f)) != NULL) {
+#endif
+ if (stat (entp->mnt_fsname, &statbuf) == 0 &&
statbuf.st_dev == root_dev) {
- strncpy (real_dev_root, ent.mnt_fsname, sizeof (real_dev_root) - 1);
+ strncpy (real_dev_root, entp->mnt_fsname, sizeof (real_dev_root) - 1);
real_dev_root[sizeof (real_dev_root) - 1] = '\0';
fclose (f);
goto found;
}
}
- fclose (f);
+
+ endmntent (f);
+
+#ifndef HAVE_GETMNTENT_R
+ G_UNLOCK (getmntent);
+#endif
}
/* no, that didn't work.. next we could scan /dev ... but I digress.. */