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