diff --git a/CHANGELOG b/CHANGELOG index 02071a6..d59be77 100644 --- a/CHANGELOG +++ b/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. diff --git a/daemon/direct.c b/daemon/direct.c index c0fc222..f74cfe5 100644 --- a/daemon/direct.c +++ b/daemon/direct.c @@ -298,37 +298,12 @@ static int unlink_mount_tree(struct autofs_point *ap, struct list_head *list) 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_point *ap, 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);