|
|
306fa1 |
autofs-5.1.3 - serialize calls to open_xxxx() functions
|
|
|
306fa1 |
|
|
|
306fa1 |
From: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
|
|
|
306fa1 |
This patch is the second part of the change described in "move
|
|
|
306fa1 |
open_xxxx() functions to spawn.c" to serialize the open_xxxx()
|
|
|
306fa1 |
functions wrt. to fork(2).
|
|
|
306fa1 |
|
|
|
306fa1 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
---
|
|
|
306fa1 |
CHANGELOG | 1
|
|
|
306fa1 |
daemon/spawn.c | 61 ++++++++++++++++++++++++++++++++++++++++-------
|
|
|
306fa1 |
include/automount.h | 2 +
|
|
|
306fa1 |
lib/mounts.c | 2 +
|
|
|
306fa1 |
modules/lookup_program.c | 3 ++
|
|
|
306fa1 |
5 files changed, 61 insertions(+), 8 deletions(-)
|
|
|
306fa1 |
|
|
|
306fa1 |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
306fa1 |
+++ autofs-5.0.7/CHANGELOG
|
|
|
306fa1 |
@@ -288,6 +288,7 @@
|
|
|
306fa1 |
- update configure to check for pipe2(2).
|
|
|
306fa1 |
- fix open calls not using open_xxxx() calls.
|
|
|
306fa1 |
- move open_xxxx() functions to spawn.c.
|
|
|
306fa1 |
+- serialize calls to open_xxxx() functions.
|
|
|
306fa1 |
|
|
|
306fa1 |
25/07/2012 autofs-5.0.7
|
|
|
306fa1 |
=======================
|
|
|
306fa1 |
--- autofs-5.0.7.orig/daemon/spawn.c
|
|
|
306fa1 |
+++ autofs-5.0.7/daemon/spawn.c
|
|
|
306fa1 |
@@ -29,6 +29,7 @@
|
|
|
306fa1 |
#include "automount.h"
|
|
|
306fa1 |
|
|
|
306fa1 |
static pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
306fa1 |
+static pthread_mutex_t open_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
306fa1 |
|
|
|
306fa1 |
#define SPAWN_OPT_NONE 0x0000
|
|
|
306fa1 |
#define SPAWN_OPT_LOCK 0x0001
|
|
|
306fa1 |
@@ -48,6 +49,20 @@ void dump_core(void)
|
|
|
306fa1 |
raise(SIGSEGV);
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
+void open_mutex_lock(void)
|
|
|
306fa1 |
+{
|
|
|
306fa1 |
+ int _o_lock = pthread_mutex_lock(&open_mutex);
|
|
|
306fa1 |
+ if (_o_lock)
|
|
|
306fa1 |
+ fatal(_o_lock);
|
|
|
306fa1 |
+}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+void open_mutex_unlock(void)
|
|
|
306fa1 |
+{
|
|
|
306fa1 |
+ int _o_unlock = pthread_mutex_unlock(&open_mutex);
|
|
|
306fa1 |
+ if (_o_unlock)
|
|
|
306fa1 |
+ fatal(_o_unlock);
|
|
|
306fa1 |
+}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
/*
|
|
|
306fa1 |
* Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
|
|
|
306fa1 |
* socket() if possible.
|
|
|
306fa1 |
@@ -71,14 +86,18 @@ int open_fd(const char *path, int flags)
|
|
|
306fa1 |
{
|
|
|
306fa1 |
int fd;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
|
|
|
306fa1 |
if (cloexec_works != -1)
|
|
|
306fa1 |
flags |= O_CLOEXEC;
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
fd = open(path, flags);
|
|
|
306fa1 |
- if (fd == -1)
|
|
|
306fa1 |
+ if (fd == -1) {
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return -1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
check_cloexec(fd);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return fd;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -86,14 +105,18 @@ int open_fd_mode(const char *path, int f
|
|
|
306fa1 |
{
|
|
|
306fa1 |
int fd;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
|
|
|
306fa1 |
if (cloexec_works != -1)
|
|
|
306fa1 |
flags |= O_CLOEXEC;
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
fd = open(path, flags, mode);
|
|
|
306fa1 |
- if (fd == -1)
|
|
|
306fa1 |
+ if (fd == -1) {
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return -1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
check_cloexec(fd);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return fd;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -101,35 +124,45 @@ int open_pipe(int pipefd[2])
|
|
|
306fa1 |
{
|
|
|
306fa1 |
int ret;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_PIPE2)
|
|
|
306fa1 |
if (cloexec_works != -1) {
|
|
|
306fa1 |
ret = pipe2(pipefd, O_CLOEXEC);
|
|
|
306fa1 |
if (ret != -1)
|
|
|
306fa1 |
- return 0;
|
|
|
306fa1 |
+ goto done;
|
|
|
306fa1 |
if (errno != EINVAL)
|
|
|
306fa1 |
- return -1;
|
|
|
306fa1 |
+ goto err;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
ret = pipe(pipefd);
|
|
|
306fa1 |
if (ret == -1)
|
|
|
306fa1 |
- return -1;
|
|
|
306fa1 |
+ goto err;
|
|
|
306fa1 |
check_cloexec(pipefd[0]);
|
|
|
306fa1 |
check_cloexec(pipefd[1]);
|
|
|
306fa1 |
+done:
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
+err:
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
+ return -1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
int open_sock(int domain, int type, int protocol)
|
|
|
306fa1 |
{
|
|
|
306fa1 |
int fd;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#ifdef SOCK_CLOEXEC
|
|
|
306fa1 |
if (cloexec_works != -1)
|
|
|
306fa1 |
type |= SOCK_CLOEXEC;
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
fd = socket(domain, type, protocol);
|
|
|
306fa1 |
- if (fd == -1)
|
|
|
306fa1 |
+ if (fd == -1) {
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return -1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
check_cloexec(fd);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return fd;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -137,19 +170,24 @@ FILE *open_fopen_r(const char *path)
|
|
|
306fa1 |
{
|
|
|
306fa1 |
FILE *f;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
|
|
|
306fa1 |
if (cloexec_works != -1) {
|
|
|
306fa1 |
f = fopen(path, "re");
|
|
|
306fa1 |
if (f != NULL) {
|
|
|
306fa1 |
check_cloexec(fileno(f));
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return f;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
}
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
f = fopen(path, "r");
|
|
|
306fa1 |
- if (f == NULL)
|
|
|
306fa1 |
+ if (f == NULL) {
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return NULL;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
check_cloexec(fileno(f));
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return f;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -157,19 +195,24 @@ FILE *open_setmntent_r(const char *table
|
|
|
306fa1 |
{
|
|
|
306fa1 |
FILE *tab;
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
|
|
|
306fa1 |
if (cloexec_works != -1) {
|
|
|
306fa1 |
tab = setmntent(table, "re");
|
|
|
306fa1 |
if (tab != NULL) {
|
|
|
306fa1 |
check_cloexec(fileno(tab));
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return tab;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
}
|
|
|
306fa1 |
#endif
|
|
|
306fa1 |
tab = fopen(table, "r");
|
|
|
306fa1 |
- if (tab == NULL)
|
|
|
306fa1 |
+ if (tab == NULL) {
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return NULL;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
check_cloexec(fileno(tab));
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
return tab;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -283,6 +326,7 @@ static int do_spawn(unsigned logopt, uns
|
|
|
306fa1 |
egid = tsv->gid;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
f = fork();
|
|
|
306fa1 |
if (f == 0) {
|
|
|
306fa1 |
char **pargv = (char **) argv;
|
|
|
306fa1 |
@@ -377,6 +421,7 @@ done:
|
|
|
306fa1 |
|
|
|
306fa1 |
sigaddset(&tmpsig, SIGCHLD);
|
|
|
306fa1 |
pthread_sigmask(SIG_SETMASK, &tmpsig, NULL);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
|
|
|
306fa1 |
close(pipefd[1]);
|
|
|
306fa1 |
|
|
|
306fa1 |
--- autofs-5.0.7.orig/include/automount.h
|
|
|
306fa1 |
+++ autofs-5.0.7/include/automount.h
|
|
|
306fa1 |
@@ -257,6 +257,8 @@ int spawnv(unsigned logopt, const char *
|
|
|
306fa1 |
int spawn_mount(unsigned logopt, ...);
|
|
|
306fa1 |
int spawn_bind_mount(unsigned logopt, ...);
|
|
|
306fa1 |
int spawn_umount(unsigned logopt, ...);
|
|
|
306fa1 |
+void open_mutex_lock(void);
|
|
|
306fa1 |
+void open_mutex_unlock(void);
|
|
|
306fa1 |
int open_fd(const char *, int);
|
|
|
306fa1 |
int open_fd_mode(const char *, int, int);
|
|
|
306fa1 |
int open_pipe(int[2]);
|
|
|
306fa1 |
--- autofs-5.0.7.orig/lib/mounts.c
|
|
|
306fa1 |
+++ autofs-5.0.7/lib/mounts.c
|
|
|
306fa1 |
@@ -230,6 +230,7 @@ int check_nfs_mount_version(struct nfs_m
|
|
|
306fa1 |
sigfillset(&allsigs);
|
|
|
306fa1 |
pthread_sigmask(SIG_BLOCK, &allsigs, &oldsig);
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
f = fork();
|
|
|
306fa1 |
if (f == 0) {
|
|
|
306fa1 |
reset_signals();
|
|
|
306fa1 |
@@ -248,6 +249,7 @@ int check_nfs_mount_version(struct nfs_m
|
|
|
306fa1 |
|
|
|
306fa1 |
sigaddset(&tmpsig, SIGCHLD);
|
|
|
306fa1 |
pthread_sigmask(SIG_SETMASK, &tmpsig, NULL);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
|
|
|
306fa1 |
close(pipefd[1]);
|
|
|
306fa1 |
|
|
|
306fa1 |
--- autofs-5.0.7.orig/modules/lookup_program.c
|
|
|
306fa1 |
+++ autofs-5.0.7/modules/lookup_program.c
|
|
|
306fa1 |
@@ -225,6 +225,7 @@ static char *lookup_one(struct autofs_po
|
|
|
306fa1 |
goto out_error;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
+ open_mutex_lock();
|
|
|
306fa1 |
f = fork();
|
|
|
306fa1 |
if (f < 0) {
|
|
|
306fa1 |
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
306fa1 |
@@ -233,6 +234,7 @@ static char *lookup_one(struct autofs_po
|
|
|
306fa1 |
close(pipefd[1]);
|
|
|
306fa1 |
close(epipefd[0]);
|
|
|
306fa1 |
close(epipefd[1]);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
goto out_error;
|
|
|
306fa1 |
} else if (f == 0) {
|
|
|
306fa1 |
reset_signals();
|
|
|
306fa1 |
@@ -262,6 +264,7 @@ static char *lookup_one(struct autofs_po
|
|
|
306fa1 |
}
|
|
|
306fa1 |
close(pipefd[1]);
|
|
|
306fa1 |
close(epipefd[1]);
|
|
|
306fa1 |
+ open_mutex_unlock();
|
|
|
306fa1 |
|
|
|
306fa1 |
mapp = mapent;
|
|
|
306fa1 |
errp = errbuf;
|