Blame SOURCES/autofs-5.1.5-add-glibc-getmntent.patch

306fa1
autofs-5.1.5 - add glibc getmntent_r()
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Add a slightly modified version of the glibc getmntent_r() function
306fa1
so autofs can read the proc mount table directly.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG    |    1 
306fa1
 lib/mounts.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
306fa1
 2 files changed, 96 insertions(+)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -340,6 +340,7 @@
306fa1
 - use bit flags for autofs mount types in mnt_list.
306fa1
 - use mp instead of path in mnt_list entries.
306fa1
 - always use PROC_MOUNTS to make mount lists.
306fa1
+- add glibc getmntent_r().
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/lib/mounts.c
306fa1
+++ autofs-5.0.7/lib/mounts.c
306fa1
@@ -787,6 +787,101 @@ done:
306fa1
 	return ret;
306fa1
 }
306fa1
 
306fa1
+/* From glibc decode_name() */
306fa1
+/* Since the values in a line are separated by spaces, a name cannot
306fa1
+ * contain a space.  Therefore some programs encode spaces in names
306fa1
+ * by the strings "\040".  We undo the encoding when reading an entry.
306fa1
+ * The decoding happens in place.
306fa1
+ */
306fa1
+static char *local_decode_name(char *buf)
306fa1
+{
306fa1
+	char *rp = buf;
306fa1
+	char *wp = buf;
306fa1
+
306fa1
+	do {
306fa1
+		if (rp[0] == '\\' && rp[1] == '0' &&
306fa1
+		    rp[2] == '4' && rp[3] == '0') {
306fa1
+			/* \040 is a SPACE.  */
306fa1
+			*wp++ = ' ';
306fa1
+			rp += 3;
306fa1
+		} else if (rp[0] == '\\' && rp[1] == '0' &&
306fa1
+			   rp[2] == '1' && rp[3] == '1') {
306fa1
+			/* \011 is a TAB.  */
306fa1
+			*wp++ = '\t';
306fa1
+			rp += 3;
306fa1
+		} else if (rp[0] == '\\' && rp[1] == '0' &&
306fa1
+			   rp[2] == '1' && rp[3] == '2') {
306fa1
+			/* \012 is a NEWLINE.  */
306fa1
+			*wp++ = '\n';
306fa1
+			rp += 3;
306fa1
+		} else if (rp[0] == '\\' && rp[1] == '\\') {
306fa1
+			/*
306fa1
+			 * We have to escape \\ to be able to represent
306fa1
+			 * all characters.
306fa1
+			 */
306fa1
+			*wp++ = '\\';
306fa1
+			rp += 1;
306fa1
+		} else if (rp[0] == '\\' && rp[1] == '1' &&
306fa1
+			   rp[2] == '3' && rp[3] == '4') {
306fa1
+			/* \134 is also \\.  */
306fa1
+			*wp++ = '\\';
306fa1
+			rp += 3;
306fa1
+		} else
306fa1
+			*wp++ = *rp;
306fa1
+	} while (*rp++ != '\0');
306fa1
+
306fa1
+	return buf;
306fa1
+}
306fa1
+
306fa1
+/* From glibc getmntent_r() */
306fa1
+static struct mntent *
306fa1
+local_getmntent_r(FILE *tab, struct mntent *mnt, char *buf, int size)
306fa1
+{
306fa1
+	char *cp, *head;
306fa1
+
306fa1
+	do {
306fa1
+		char *end_ptr;
306fa1
+
306fa1
+		if (fgets(buf, size, tab) == NULL)
306fa1
+			return 0;
306fa1
+
306fa1
+		end_ptr = strchr(buf, '\n');
306fa1
+		if (end_ptr != NULL) {
306fa1
+			while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
306fa1
+				end_ptr--;
306fa1
+			*end_ptr = '\0';
306fa1
+		} else {
306fa1
+			/* Whole line was not read. Do it now but forget it. */
306fa1
+			char tmp[1024];
306fa1
+			while (fgets(tmp, sizeof tmp, tab) != NULL)
306fa1
+				if (strchr(tmp, '\n') != NULL)
306fa1
+					break;
306fa1
+		}
306fa1
+
306fa1
+		head = buf + strspn(buf, " \t");
306fa1
+	/* skip empty lines and comment lines */
306fa1
+	} while (head[0] == '\0' || head[0] == '#');
306fa1
+
306fa1
+	cp = strsep(&head, " \t");
306fa1
+	mnt->mnt_fsname = cp != NULL ? local_decode_name(cp) : (char *) "";
306fa1
+	if (head)
306fa1
+		head += strspn(head, " \t");
306fa1
+	cp = strsep(&head, " \t");
306fa1
+	mnt->mnt_dir = cp != NULL ? local_decode_name (cp) : (char *) "";
306fa1
+	if (head)
306fa1
+		head += strspn(head, " \t");
306fa1
+	cp = strsep(&head, " \t");
306fa1
+	mnt->mnt_type = cp != NULL ? local_decode_name (cp) : (char *) "";
306fa1
+	if (head)
306fa1
+		head += strspn (head, " \t");
306fa1
+	cp = strsep (&head, " \t");
306fa1
+	mnt->mnt_opts = cp != NULL ? local_decode_name (cp) : (char *) "";
306fa1
+
306fa1
+	/* autofs doesn't need freq or passno */
306fa1
+
306fa1
+	return mnt;
306fa1
+}
306fa1
+
306fa1
 /*
306fa1
  * Get list of mounts under path in longest->shortest order
306fa1
  */