autofs-5.1.9 - make open_mutex usage more consistent at process spawn

From: Ian Kent <raven@themaw.net>

Using a mutex when spawning a process can be problematic, for example,
if there's a crash during the procedure before the exec() the side
effects aren't specified.

The reason a mutex is used here is described in commit a223d11fa8e3
("autofs-5.1.3 - serialize calls to open_xxxx() functions") so we can't
just remove the mutex usage.

But we are seeing the open_mutex locked without any holder so there must
be some unexpected event that's occurred that has left the mutex locked
without leaving any evidence of what process that was.

All we can do then is tighten up the usage of the mutex over the fork()
and exec() to minimize the possibility of this happening.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG                |    1 +
 lib/mounts.c             |    1 +
 modules/lookup_program.c |    2 ++
 3 files changed, 4 insertions(+)

diff --git a/CHANGELOG b/CHANGELOG
index 016bb2313..5400851b6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -95,6 +95,7 @@
 - fix lookup_hosts module leaks read lock on early return.
 - quiet unset environment variable message on start.
 - improve local mount localion path resolution.
+- make open_mutex usage more consistent at process spawn.
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/lib/mounts.c b/lib/mounts.c
index 0e2152df4..f17bb12db 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -304,6 +304,7 @@ int check_nfs_mount_version(struct nfs_mount_vers *vers,
 		dup2(pipefd[1], STDOUT_FILENO);
 		dup2(pipefd[1], STDERR_FILENO);
 		close(pipefd[1]);
+		open_mutex_unlock();
 
 		execl(PATH_MOUNT_NFS, PATH_MOUNT_NFS, "-V", (char *) NULL);
 		_exit(255);	/* execv() failed */
diff --git a/modules/lookup_program.c b/modules/lookup_program.c
index fd90fb876..d574064bd 100644
--- a/modules/lookup_program.c
+++ b/modules/lookup_program.c
@@ -238,6 +238,8 @@ static char *lookup_one(struct autofs_point *ap,
 		dup2(epipefd[1], STDERR_FILENO);
 		close(pipefd[1]);
 		close(epipefd[1]);
+		open_mutex_unlock();
+
 		if (chdir(ap->path))
 			warn(ap->logopt,
 			     MODPREFIX "failed to set PWD to %s for map %s",
