+2019-09-02 Ian Kent <ikent@redhat.com>
+
+ Use autofs "ignore" mount hint in getmntent_r/getmntent.
+ * misc/mntent_r.c (get_mnt_entry): New function, extracted from
+ getmntent_r.
+ (__getmntent_r): Call it. Filter out autofs entries with an
+ "ignore" mount option.
+
2019-08-30 Wilco Dijkstra <wdijkstr@arm.com>
* benchtests/bench-memcpy.c (simple_memcpy): Remove.
#include <alloca.h>
#include <mntent.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdio_ext.h>
#include <string.h>
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 */
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)