autofs/SOURCES/autofs-5.1.9-refactor-amd-function-do_program_mount.patch

139 lines
3.5 KiB
Diff

autofs-5.1.9 - refactor amd function do_program_mount()
From: Ian Kent <raven@themaw.net>
The amd mounts function do_program_mount() is particularly untidy.
Refactor it to make it a little simpler and to take advantage of the
coming refactoring of the funtion umount_amd_ext_mount().
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
modules/parse_amd.c | 74 ++++++++++++++++++++++++----------------------------
2 files changed, 36 insertions(+), 39 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -158,6 +158,7 @@
- fix amd external mount error handling.
- fix amd external mount mount handling.
- don't free ext mount if mounted.
+- refactor amd function do_program_mount().
xx/xx/2018 autofs-5.1.5
- fix flag file permission.
--- autofs-5.1.4.orig/modules/parse_amd.c
+++ autofs-5.1.4/modules/parse_amd.c
@@ -1407,26 +1407,8 @@ out:
static int do_program_mount(struct autofs_point *ap,
struct amd_entry *entry, const char *name)
{
- char *prog, *str;
- char **argv;
- int argc = -1;
int rv = 1;
- str = strdup(entry->mount);
- if (!str)
- goto out;
-
- prog = NULL;
- argv = NULL;
-
- argc = construct_argv(str, &prog, &argv);
- if (argc == -1) {
- error(ap->logopt, MODPREFIX
- "%s: error creating mount arguments", entry->type);
- free(str);
- goto out;
- }
-
/* The am-utils documentation doesn't actually say that the
* mount (and umount, if given) command need to use ${fs} as
* the mount point in the command.
@@ -1445,6 +1427,25 @@ static int do_program_mount(struct autof
}
rv = 0;
} else {
+ char *prog, *str;
+ char **argv;
+ int argc = -1;
+
+ str = strdup(entry->mount);
+ if (!str)
+ goto out;
+
+ prog = NULL;
+ argv = NULL;
+
+ argc = construct_argv(str, &prog, &argv);
+ if (argc == -1) {
+ error(ap->logopt, MODPREFIX
+ "%s: error creating mount arguments", entry->type);
+ free(str);
+ goto out;
+ }
+
rv = mkdir_path(entry->fs, mp_mode);
if (rv && errno != EEXIST) {
char buf[MAX_ERR_BUF];
@@ -1454,7 +1455,9 @@ static int do_program_mount(struct autof
error(ap->logopt,
MODPREFIX "%s: mkdir_path %s failed: %s",
entry->type, entry->fs, estr);
- goto do_free;
+ free_argv(argc, (const char **) argv);
+ free(str);
+ goto out;
}
rv = spawnv(ap->logopt, prog, (const char * const *) argv);
@@ -1463,33 +1466,26 @@ static int do_program_mount(struct autof
rv = 0;
debug(ap->logopt, MODPREFIX
"%s: mounted %s", entry->type, entry->fs);
- goto do_free;
+ free_argv(argc, (const char **) argv);
+ free(str);
+ goto done;
}
umount_amd_ext_mount(ap, entry->fs);
}
-
- if (!ext_mount_inuse(entry->fs))
- rmdir_path(ap, entry->fs, ap->dev);
error(ap->logopt, MODPREFIX
"%s: failed to mount using %s", entry->type, entry->mount);
- }
-do_free:
- free_argv(argc, (const char **) argv);
- free(str);
-
- if (rv)
+ free_argv(argc, (const char **) argv);
+ free(str);
goto out;
-
+ }
+done:
rv = do_link_mount(ap, name, entry, 0);
- if (!rv)
- goto out;
-
- if (umount_amd_ext_mount(ap, entry->fs)) {
- if (!ext_mount_inuse(entry->fs))
- rmdir_path(ap, entry->fs, ap->dev);
- debug(ap->logopt, MODPREFIX
- "%s: failed to umount external mount at %s",
- entry->type, entry->fs);
+ if (rv) {
+ if (umount_amd_ext_mount(ap, entry->fs)) {
+ debug(ap->logopt, MODPREFIX
+ "%s: failed to cleanup external mount at %s",
+ entry->type, entry->fs);
+ }
}
out:
return rv;