Blame SOURCES/autofs-5.1.6-cleanup-stale-logpri-fifo-pipes-on-unlink-and-exit.patch

d702dc
autofs-5.1.6 - cleanup stale logpri fifo pipes on unlink and exit
d702dc
d702dc
From: Ian Kent <raven@themaw.net>
d702dc
d702dc
If the unlink and exit option is given then stale fifo pipe files
d702dc
need to be cleaned up since the entire tree of mounts below autofs
d702dc
managed directories will be unlinked as well as the autofs mounts
d702dc
themselves.
d702dc
d702dc
Signed-off-by: Ian Kent <raven@themaw.net>
d702dc
---
d702dc
 CHANGELOG          |    1 +
d702dc
 daemon/automount.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
d702dc
 2 files changed, 52 insertions(+), 2 deletions(-)
d702dc
d702dc
--- autofs-5.1.4.orig/CHANGELOG
d702dc
+++ autofs-5.1.4/CHANGELOG
d702dc
@@ -90,6 +90,7 @@ xx/xx/2018 autofs-5.1.5
d702dc
 - improve force unlink option description.
d702dc
 - remove command fifo on autofs mount fail.
d702dc
 - add force unlink mounts and exit option.
d702dc
+- cleanup stale logpri fifo pipes on unlink and exit.
d702dc
 
d702dc
 19/12/2017 autofs-5.1.4
d702dc
 - fix spec file url.
d702dc
--- autofs-5.1.4.orig/daemon/automount.c
d702dc
+++ autofs-5.1.4/daemon/automount.c
d702dc
@@ -60,7 +60,8 @@ unsigned int nfs_mount_uses_string_optio
d702dc
 static struct nfs_mount_vers vers, check = {1, 1, 1};
d702dc
 
d702dc
 /* autofs fifo name prefix */
d702dc
-const char *fifodir = AUTOFS_FIFO_DIR "/autofs.fifo";
d702dc
+#define FIFO_NAME_PREFIX "autofs.fifo"
d702dc
+const char *fifodir = AUTOFS_FIFO_DIR "/" FIFO_NAME_PREFIX;
d702dc
 
d702dc
 const char *global_options;		/* Global option, from command line */
d702dc
 
d702dc
@@ -887,6 +888,48 @@ out_free:
d702dc
 	return ret;
d702dc
 }
d702dc
 
d702dc
+static void cleanup_stale_logpri_fifo_pipes(void)
d702dc
+{
d702dc
+	size_t prefix_len = strlen(FIFO_NAME_PREFIX);
d702dc
+	char *dir = AUTOFS_FIFO_DIR;
d702dc
+	size_t dir_len = strlen(dir);
d702dc
+	struct dirent *dent;
d702dc
+	DIR *dfd;
d702dc
+	int ret;
d702dc
+
d702dc
+	dfd = opendir(dir);
d702dc
+	if (!dfd) {
d702dc
+		warn(LOGOPT_ANY, "failed to open fifo dir %s", dir);
d702dc
+		return;
d702dc
+	}
d702dc
+
d702dc
+	while ((dent = readdir(dfd))) {
d702dc
+		char fifo_path[PATH_MAX];
d702dc
+
d702dc
+		if (!(dent->d_type & DT_FIFO))
d702dc
+			continue;
d702dc
+		if (strncmp(FIFO_NAME_PREFIX, dent->d_name, prefix_len))
d702dc
+			continue;
d702dc
+		if ((dir_len + 1 + strlen(dent->d_name)) >= PATH_MAX) {
d702dc
+			warn(LOGOPT_ANY, "fifo path too long for buffer");
d702dc
+			continue;
d702dc
+		}
d702dc
+
d702dc
+		strcpy(fifo_path, dir);
d702dc
+		strcat(fifo_path, "/");
d702dc
+		strcat(fifo_path, dent->d_name);
d702dc
+
d702dc
+		ret = unlink(fifo_path);
d702dc
+		if (ret == -1) {
d702dc
+			char buf[MAX_ERR_BUF];
d702dc
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
d702dc
+			warn(LOGOPT_ANY, "unlink of fifo failed: %s", estr);
d702dc
+		}
d702dc
+	}
d702dc
+
d702dc
+	closedir(dfd);
d702dc
+}
d702dc
+
d702dc
 static void handle_fifo_message(struct autofs_point *ap, int fd)
d702dc
 {
d702dc
 	int ret;
d702dc
@@ -2670,7 +2713,13 @@ int main(int argc, char *argv[])
d702dc
 		}
d702dc
 	}
d702dc
 
d702dc
-	if (!(do_force_unlink & UNLINK_AND_EXIT)) {
d702dc
+	/* If the option to unlink all autofs mounts and exit has
d702dc
+	 * been given remove logpri fifo files as all the  mounts
d702dc
+	 * will be detached leaving them stale.
d702dc
+	 */
d702dc
+	if (do_force_unlink & UNLINK_AND_EXIT)
d702dc
+		cleanup_stale_logpri_fifo_pipes();
d702dc
+	else {
d702dc
 		/*
d702dc
 		 * Mmm ... reset force unlink umount so we don't also do
d702dc
 		 * this in future when we receive a HUP signal.