about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/mntent_r.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/misc/mntent_r.c b/misc/mntent_r.c
index 5d88c45c6f..d90e8d7087 100644
--- a/misc/mntent_r.c
+++ b/misc/mntent_r.c
@@ -18,6 +18,7 @@
 
 #include <alloca.h>
 #include <mntent.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdio_ext.h>
 #include <string.h>
@@ -112,26 +113,18 @@ decode_name (char *buf)
   return buf;
 }
 
-
-/* Read one mount table entry from STREAM.  Returns a pointer to storage
-   reused on the next call, or null for EOF or error (use feof/ferror to
-   check).  */
-struct mntent *
-__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
+static bool
+get_mnt_entry (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
 {
   char *cp;
   char *head;
 
-  flockfile (stream);
   do
     {
       char *end_ptr;
 
       if (__fgets_unlocked (buffer, bufsiz, stream) == NULL)
-	{
-	  funlockfile (stream);
-	  return NULL;
-	}
+	  return false;
 
       end_ptr = strchr (buffer, '\n');
       if (end_ptr != NULL)	/* chop newline */
@@ -181,9 +174,40 @@ __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
     case 2:
       break;
     }
+
+  return true;
+}
+
+/* Read one mount table entry from STREAM.  Returns a pointer to storage
+   reused on the next call, or null for EOF or error (use feof/ferror to
+   check).  */
+struct mntent *
+__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
+{
+  struct mntent *result;
+
+  flockfile (stream);
+  while (true)
+    if (get_mnt_entry (stream, mp, buffer, bufsiz))
+      {
+	/* If the file system is autofs look for a mount option hint
+	   ("ignore") to skip the entry.  */
+	if (strcmp (mp->mnt_type, "autofs") == 0 && __hasmntopt (mp, "ignore"))
+	  memset (mp, 0, sizeof (*mp));
+	else
+	  {
+	    result = mp;
+	    break;
+	  }
+      }
+    else
+      {
+	result = NULL;
+	break;
+      }
   funlockfile (stream);
 
-  return mp;
+  return result;
 }
 libc_hidden_def (__getmntent_r)
 weak_alias (__getmntent_r, getmntent_r)