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

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