|
|
1c5f92 |
autofs-5.1.5 - use local_getmntent_r() for unlink_mount_tree()
|
|
|
1c5f92 |
|
|
|
1c5f92 |
From: Ian Kent <raven@themaw.net>
|
|
|
1c5f92 |
|
|
|
1c5f92 |
Now that unlink_mount_tree() is located in a single location and
|
|
|
1c5f92 |
only one function is used for this, change it to use our local
|
|
|
1c5f92 |
getmntent_r() function so that if glibc is changed to support the
|
|
|
1c5f92 |
autofs "ignore" hint automount(8) won't be affected.
|
|
|
1c5f92 |
|
|
|
1c5f92 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
1c5f92 |
---
|
|
|
1c5f92 |
CHANGELOG | 1 +
|
|
|
1c5f92 |
daemon/direct.c | 24 ++++++------------------
|
|
|
1c5f92 |
daemon/indirect.c | 17 ++++++-----------
|
|
|
1c5f92 |
include/mounts.h | 2 +-
|
|
|
1c5f92 |
lib/mounts.c | 45 ++++++++++++++++++++++++++++++++++-----------
|
|
|
1c5f92 |
5 files changed, 48 insertions(+), 41 deletions(-)
|
|
|
1c5f92 |
|
|
|
1c5f92 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
1c5f92 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
1c5f92 |
@@ -72,6 +72,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
1c5f92 |
- don't use tree_is_mounted() for mounted checks.
|
|
|
1c5f92 |
- use single unlink_umount_tree() for both direct and indirect mounts.
|
|
|
1c5f92 |
- move unlink_mount_tree() to lib/mounts.c.
|
|
|
1c5f92 |
+- use local_getmntent_r() for unlink_mount_tree().
|
|
|
1c5f92 |
|
|
|
1c5f92 |
19/12/2017 autofs-5.1.4
|
|
|
1c5f92 |
- fix spec file url.
|
|
|
1c5f92 |
--- autofs-5.1.4.orig/daemon/direct.c
|
|
|
1c5f92 |
+++ autofs-5.1.4/daemon/direct.c
|
|
|
1c5f92 |
@@ -286,8 +286,6 @@ int do_mount_autofs_direct(struct autofs
|
|
|
1c5f92 |
if (ret == 0)
|
|
|
1c5f92 |
return -1;
|
|
|
1c5f92 |
} else {
|
|
|
1c5f92 |
- struct mnt_list *mnts;
|
|
|
1c5f92 |
-
|
|
|
1c5f92 |
if (ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
|
|
|
1c5f92 |
time_t tout = get_exp_timeout(ap, me->source);
|
|
|
1c5f92 |
int save_ioctlfd, ioctlfd;
|
|
|
1c5f92 |
@@ -313,22 +311,12 @@ int do_mount_autofs_direct(struct autofs
|
|
|
1c5f92 |
return 0;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
|
|
|
1c5f92 |
- mnts = get_mnt_list(me->key, 1);
|
|
|
1c5f92 |
- if (mnts) {
|
|
|
1c5f92 |
- /*
|
|
|
1c5f92 |
- * A return of 1 indicates we successfully unlinked
|
|
|
1c5f92 |
- * the mount tree if there was one. A return of 0
|
|
|
1c5f92 |
- * indicates we failed to unlink the mount tree so
|
|
|
1c5f92 |
- * we have to return a failure.
|
|
|
1c5f92 |
- */
|
|
|
1c5f92 |
- ret = unlink_mount_tree(ap, mnts);
|
|
|
1c5f92 |
- free_mnt_list(mnts);
|
|
|
1c5f92 |
- if (!ret) {
|
|
|
1c5f92 |
- error(ap->logopt,
|
|
|
1c5f92 |
- "already mounted as other than autofs "
|
|
|
1c5f92 |
- "or failed to unlink entry in tree");
|
|
|
1c5f92 |
- return -1;
|
|
|
1c5f92 |
- }
|
|
|
1c5f92 |
+ ret = unlink_mount_tree(ap, ap->path);
|
|
|
1c5f92 |
+ if (!ret) {
|
|
|
1c5f92 |
+ error(ap->logopt,
|
|
|
1c5f92 |
+ "already mounted as other than autofs "
|
|
|
1c5f92 |
+ "or failed to unlink entry in tree");
|
|
|
1c5f92 |
+ goto out_err;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
|
|
|
1c5f92 |
if (me->ioctlfd != -1) {
|
|
|
1c5f92 |
--- autofs-5.1.4.orig/daemon/indirect.c
|
|
|
1c5f92 |
+++ autofs-5.1.4/daemon/indirect.c
|
|
|
1c5f92 |
@@ -50,7 +50,6 @@ static int do_mount_autofs_indirect(stru
|
|
|
1c5f92 |
const char *map_name = hosts_map_name;
|
|
|
1c5f92 |
const char *type;
|
|
|
1c5f92 |
struct stat st;
|
|
|
1c5f92 |
- struct mnt_list *mnts;
|
|
|
1c5f92 |
int ret;
|
|
|
1c5f92 |
int err;
|
|
|
1c5f92 |
|
|
|
1c5f92 |
@@ -70,16 +69,12 @@ static int do_mount_autofs_indirect(stru
|
|
|
1c5f92 |
if (ret == 0)
|
|
|
1c5f92 |
return -1;
|
|
|
1c5f92 |
} else {
|
|
|
1c5f92 |
- mnts = get_mnt_list(ap->path, 1);
|
|
|
1c5f92 |
- if (mnts) {
|
|
|
1c5f92 |
- ret = unlink_mount_tree(ap, mnts);
|
|
|
1c5f92 |
- free_mnt_list(mnts);
|
|
|
1c5f92 |
- if (!ret) {
|
|
|
1c5f92 |
- error(ap->logopt,
|
|
|
1c5f92 |
- "already mounted as other than autofs "
|
|
|
1c5f92 |
- "or failed to unlink entry in tree");
|
|
|
1c5f92 |
- goto out_err;
|
|
|
1c5f92 |
- }
|
|
|
1c5f92 |
+ ret = unlink_mount_tree(ap, ap->path);
|
|
|
1c5f92 |
+ if (!ret) {
|
|
|
1c5f92 |
+ error(ap->logopt,
|
|
|
1c5f92 |
+ "already mounted as other than autofs "
|
|
|
1c5f92 |
+ "or failed to unlink entry in tree");
|
|
|
1c5f92 |
+ goto out_err;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
|
|
|
1c5f92 |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
1c5f92 |
+++ autofs-5.1.4/include/mounts.h
|
|
|
1c5f92 |
@@ -100,7 +100,7 @@ int ext_mount_add(struct list_head *, co
|
|
|
1c5f92 |
int ext_mount_remove(struct list_head *, const char *);
|
|
|
1c5f92 |
int ext_mount_inuse(const char *);
|
|
|
1c5f92 |
struct mnt_list *get_mnt_list(const char *path, int include);
|
|
|
1c5f92 |
-int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts);
|
|
|
1c5f92 |
+int unlink_mount_tree(struct autofs_point *ap, const char *mp);
|
|
|
1c5f92 |
void free_mnt_list(struct mnt_list *list);
|
|
|
1c5f92 |
int is_mounted(const char *mp, unsigned int type);
|
|
|
1c5f92 |
void tree_free_mnt_tree(struct mnt_list *tree);
|
|
|
1c5f92 |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
1c5f92 |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
1c5f92 |
@@ -881,21 +881,44 @@ local_getmntent_r(FILE *tab, struct mnte
|
|
|
1c5f92 |
return mnt;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
|
|
|
1c5f92 |
-int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
|
|
|
1c5f92 |
+int unlink_mount_tree(struct autofs_point *ap, const char *mp)
|
|
|
1c5f92 |
{
|
|
|
1c5f92 |
- struct mnt_list *this;
|
|
|
1c5f92 |
- int rv, ret;
|
|
|
1c5f92 |
+ FILE *tab;
|
|
|
1c5f92 |
+ struct mntent *mnt;
|
|
|
1c5f92 |
+ struct mntent mnt_wrk;
|
|
|
1c5f92 |
+ char buf[PATH_MAX * 3];
|
|
|
1c5f92 |
+ unsigned int mp_len = strlen(mp);
|
|
|
1c5f92 |
+ int rv, ret = 1;
|
|
|
1c5f92 |
|
|
|
1c5f92 |
- ret = 1;
|
|
|
1c5f92 |
- this = mnts;
|
|
|
1c5f92 |
- while (this) {
|
|
|
1c5f92 |
- if (this->flags & MNTS_AUTOFS)
|
|
|
1c5f92 |
- rv = umount2(this->mp, MNT_DETACH);
|
|
|
1c5f92 |
+ tab = open_fopen_r(_PROC_MOUNTS);
|
|
|
1c5f92 |
+ if (!tab) {
|
|
|
1c5f92 |
+ char *estr = strerror_r(errno, buf, PATH_MAX - 1);
|
|
|
1c5f92 |
+ logerr("fopen: %s", estr);
|
|
|
1c5f92 |
+ return 0;
|
|
|
1c5f92 |
+ }
|
|
|
1c5f92 |
+
|
|
|
1c5f92 |
+ while ((mnt = local_getmntent_r(tab, &mnt_wrk, buf, PATH_MAX * 3))) {
|
|
|
1c5f92 |
+ unsigned int mnt_dir_len;
|
|
|
1c5f92 |
+ int is_autofs;
|
|
|
1c5f92 |
+
|
|
|
1c5f92 |
+ if (strncmp(mnt->mnt_dir, mp, mp_len))
|
|
|
1c5f92 |
+ continue;
|
|
|
1c5f92 |
+
|
|
|
1c5f92 |
+ mnt_dir_len = strlen(mnt->mnt_dir);
|
|
|
1c5f92 |
+ is_autofs = !strcmp(mnt->mnt_type, "autofs");
|
|
|
1c5f92 |
+
|
|
|
1c5f92 |
+ if (mnt_dir_len == mp_len && !is_autofs) {
|
|
|
1c5f92 |
+ ret = 0;
|
|
|
1c5f92 |
+ break;
|
|
|
1c5f92 |
+ }
|
|
|
1c5f92 |
+
|
|
|
1c5f92 |
+ if (is_autofs)
|
|
|
1c5f92 |
+ rv = umount2(mnt->mnt_dir, MNT_DETACH);
|
|
|
1c5f92 |
else
|
|
|
1c5f92 |
- rv = spawn_umount(ap->logopt, "-l", this->mp, NULL);
|
|
|
1c5f92 |
+ rv = spawn_umount(ap->logopt, "-l", mnt->mnt_dir, NULL);
|
|
|
1c5f92 |
if (rv == -1) {
|
|
|
1c5f92 |
debug(ap->logopt,
|
|
|
1c5f92 |
- "can't unlink %s from mount tree", this->mp);
|
|
|
1c5f92 |
+ "can't unlink %s from mount tree", mnt->mnt_dir);
|
|
|
1c5f92 |
|
|
|
1c5f92 |
switch (errno) {
|
|
|
1c5f92 |
case EINVAL:
|
|
|
1c5f92 |
@@ -910,8 +933,8 @@ int unlink_mount_tree(struct autofs_poin
|
|
|
1c5f92 |
break;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
- this = this->next;
|
|
|
1c5f92 |
}
|
|
|
1c5f92 |
+ fclose(tab);
|
|
|
1c5f92 |
|
|
|
1c5f92 |
return ret;
|
|
|
1c5f92 |
}
|