autofs/SOURCES/autofs-5.1.5-refactor-unlink_active_mounts-in-direct_c.patch
2021-10-08 09:50:53 +00:00

117 lines
3.2 KiB
Diff

autofs-5.1.5 - refactor unlink_active_mounts() in direct_c
From: Ian Kent <raven@themaw.net>
In daemon/direct.c:unlink_active_mounts() the tree_get_mnt_list() call
returns 1 for a non-empty list which amounts to a mounted check and then
handles the case where the map is being read.
But the check that's carried out is to distinguish between a readmap
and a mount activity which should be handled by the caller instead of
burying the check away in the unlink_active_mounts() function.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
daemon/direct.c | 63 +++++++++++++++++++++++++++-----------------------------
2 files changed, 32 insertions(+), 32 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -68,6 +68,7 @@ xx/xx/2018 autofs-5.1.5
- always use PROC_MOUNTS to make mount lists.
- add glibc getmntent_r().
- use local getmntent_r in table_is_mounted().
+- refactor unlink_active_mounts() in direct.c.
19/12/2017 autofs-5.1.4
- fix spec file url.
--- autofs-5.1.4.orig/daemon/direct.c
+++ autofs-5.1.4/daemon/direct.c
@@ -298,37 +298,12 @@ static int unlink_mount_tree(struct auto
static int unlink_active_mounts(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
{
- struct ioctl_ops *ops = get_ioctl_ops();
struct list_head list;
INIT_LIST_HEAD(&list);
- if (tree_get_mnt_list(mnts, &list, me->key, 1)) {
- if (ap->state == ST_READMAP) {
- time_t tout = get_exp_timeout(ap, me->source);
- int save_ioctlfd, ioctlfd;
-
- save_ioctlfd = ioctlfd = me->ioctlfd;
-
- if (ioctlfd == -1)
- ops->open(ap->logopt,
- &ioctlfd, me->dev, me->key);
-
- if (ioctlfd < 0) {
- error(ap->logopt,
- "failed to create ioctl fd for %s",
- me->key);
- return 0;
- }
-
- ops->timeout(ap->logopt, ioctlfd, tout);
-
- if (save_ioctlfd == -1)
- ops->close(ap->logopt, ioctlfd);
-
- return 0;
- }
- }
+ if (!tree_get_mnt_list(mnts, &list, me->key, 1))
+ return 1;
if (!unlink_mount_tree(ap, &list)) {
debug(ap->logopt,
@@ -371,16 +346,40 @@ int do_mount_autofs_direct(struct autofs
if (ret == 0)
return -1;
} else {
+ if (ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
+ time_t tout = get_exp_timeout(ap, me->source);
+ int save_ioctlfd, ioctlfd;
+
+ save_ioctlfd = ioctlfd = me->ioctlfd;
+
+ if (ioctlfd == -1)
+ ops->open(ap->logopt,
+ &ioctlfd, me->dev, me->key);
+
+ if (ioctlfd < 0) {
+ error(ap->logopt,
+ "failed to create ioctl fd for %s",
+ me->key);
+ return 0;
+ }
+
+ ops->timeout(ap->logopt, ioctlfd, tout);
+
+ if (save_ioctlfd == -1)
+ ops->close(ap->logopt, ioctlfd);
+
+ return 0;
+ }
+
/*
- * A return of 0 indicates we're re-reading the map.
* A return of 1 indicates we successfully unlinked
- * the mount tree if there was one. A return of -1
- * inducates we failed to unlink the mount tree so
+ * the mount tree if there was one. A return of 0
+ * indicates we failed to unlink the mount tree so
* we have to return a failure.
*/
ret = unlink_active_mounts(ap, mnts, me);
- if (ret == -1 || ret == 0)
- return ret;
+ if (!ret)
+ return -1;
if (me->ioctlfd != -1) {
error(ap->logopt, "active direct mount %s", me->key);