diff --git a/Makefile.conf.in b/Makefile.conf.in
index ea5fe1d..09c3129 100644
--- a/Makefile.conf.in
+++ b/Makefile.conf.in
@@ -71,6 +71,9 @@ autofsconfdir = @confdir@
# Location for autofs maps
autofsmapdir = @mapdir@
+# Location for autofs fifos
+autofsfifodir = @fifodir@
+
# Where to install the automount program
sbindir = @sbindir@
diff --git a/aclocal.m4 b/aclocal.m4
index ffeb232..118ef0d 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -120,6 +120,22 @@ AC_DEFUN(AF_MAP_D,
done
fi])
+dnl --------------------------------------------------------------------------
+dnl AF_FIFO_D
+dnl
+dnl Check the location of the autofs fifos directory
+dnl --------------------------------------------------------------------------
+AC_DEFUN(AF_FIFO_D,
+[if test -z "$fifodir"; then
+ for fifo_d in /var/run /tmp; do
+ if test -z "$fifodir"; then
+ if test -d "$fifo_d"; then
+ fifodir="$fifo_d"
+ fi
+ fi
+ done
+fi])
+
dnl ----------------------------------- ## -*- Autoconf -*-
dnl Check if --with-dmalloc was given. ##
dnl From Franc,ois Pinard ##
diff --git a/configure b/configure
index 3508224..0360086 100755
--- a/configure
+++ b/configure
@@ -654,6 +654,7 @@ target_alias
initdir
confdir
mapdir
+fifodir
DMALLOCLIB
MOUNT
HAVE_MOUNT
@@ -1293,6 +1294,7 @@ Optional Packages:
--with-path=PATH look in PATH for binaries needed by the automounter
--with-confdir=DIR use DIR for autofs configuration files
--with-mapdir=PATH look in PATH for mount maps used by the automounter
+ --with-fifodir=PATH use PATH as the directory for fifos used by the automounter
--with-dmalloc use dmalloc, as in
http://www.dmalloc.com/dmalloc.tar.gz
--with-hesiod=DIR enable Hesiod support (libs and includes in DIR)
@@ -1844,6 +1846,36 @@ echo "${ECHO_T}$mapdir" >&6; }
#
+# The user can specify --with-fifodir=PATH to specify where autofs fifos go
+#
+if test -z "$fifodir"; then
+ for fifo_d in /var/run /tmp; do
+ if test -z "$fifodir"; then
+ if test -d "$fifo_d"; then
+ fifodir="$fifo_d"
+ fi
+ fi
+ done
+fi
+
+# Check whether --with-fifodir was given.
+if test "${with_fifodir+set}" = set; then
+ withval=$with_fifodir; if test -z "$withval" -o "$withval" = "yes" -o "$withval" = "no"
+ then
+ :
+ else
+ fifodir="${withval}"
+ fi
+
+fi
+
+{ echo "$as_me:$LINENO: checking for autofs fifos directory" >&5
+echo $ECHO_N "checking for autofs fifos directory... $ECHO_C" >&6; }
+{ echo "$as_me:$LINENO: result: $fifodir" >&5
+echo "${ECHO_T}$fifodir" >&6; }
+
+
+#
# Optional include dmalloc
#
{ echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5
@@ -6074,6 +6106,7 @@ target_alias!$target_alias$ac_delim
initdir!$initdir$ac_delim
confdir!$confdir$ac_delim
mapdir!$mapdir$ac_delim
+fifodir!$fifodir$ac_delim
DMALLOCLIB!$DMALLOCLIB$ac_delim
MOUNT!$MOUNT$ac_delim
HAVE_MOUNT!$HAVE_MOUNT$ac_delim
@@ -6124,7 +6157,7 @@ LIBOBJS!$LIBOBJS$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 88; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 89; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/configure.in b/configure.in
index 8cddf90..a83b3f1 100644
--- a/configure.in
+++ b/configure.in
@@ -79,6 +79,23 @@ AC_MSG_RESULT([$mapdir])
AC_SUBST(mapdir)
#
+# The user can specify --with-fifodir=PATH to specify where autofs fifos go
+#
+AF_FIFO_D()
+AC_ARG_WITH(fifodir,
+[ --with-fifodir=PATH use PATH as the directory for fifos used by the automounter],
+ if test -z "$withval" -o "$withval" = "yes" -o "$withval" = "no"
+ then
+ :
+ else
+ fifodir="${withval}"
+ fi
+)
+AC_MSG_CHECKING([for autofs fifos directory])
+AC_MSG_RESULT([$fifodir])
+AC_SUBST(fifodir)
+
+#
# Optional include dmalloc
#
AM_WITH_DMALLOC()
diff --git a/daemon/Makefile b/daemon/Makefile
index 4ee70eb..528a684 100644
--- a/daemon/Makefile
+++ b/daemon/Makefile
@@ -16,6 +16,7 @@ CFLAGS += -rdynamic $(DAEMON_CFLAGS) -D_GNU_SOURCE -I../include
CFLAGS += -DAUTOFS_LIB_DIR=\"$(autofslibdir)\"
CFLAGS += -DAUTOFS_MAP_DIR=\"$(autofsmapdir)\"
CFLAGS += -DAUTOFS_CONF_DIR=\"$(autofsconfdir)\"
+CFLAGS += -DAUTOFS_FIFO_DIR=\"$(autofsfifodir)\"
CFLAGS += -DVERSION_STRING=\"$(version)\"
LDFLAGS += -rdynamic
LIBS = -ldl
diff --git a/daemon/automount.c b/daemon/automount.c
index 7e7d1e6..a12b6da 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -50,6 +50,9 @@ const char *libdir = AUTOFS_LIB_DIR; /* Location of library modules */
const char *mapdir = AUTOFS_MAP_DIR; /* Location of mount maps */
const char *confdir = AUTOFS_CONF_DIR; /* Location of autofs config file */
+/* autofs fifo name prefix */
+const char *fifodir = AUTOFS_FIFO_DIR "/autofs.fifo";
+
const char *global_options; /* Global option, from command line */
static char *pid_file = NULL; /* File in which to keep pid */
@@ -650,14 +653,13 @@ static int fullread(int fd, void *ptr, size_t len)
static char *automount_path_to_fifo(unsigned logopt, const char *path)
{
char *fifo_name, *p;
- int name_len = strlen(path) + strlen(AUTOFS_LOGPRI_FIFO) + 1;
+ int name_len = strlen(path) + strlen(fifodir) + 1;
int ret;
fifo_name = malloc(name_len);
if (!fifo_name)
return NULL;
- ret = snprintf(fifo_name, name_len, "%s%s",
- AUTOFS_LOGPRI_FIFO, path);
+ ret = snprintf(fifo_name, name_len, "%s%s", fifodir, path);
if (ret >= name_len) {
info(logopt,
"fifo path for \"%s\" truncated to \"%s\". This may "
@@ -670,7 +672,7 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
* create the fifo name, we will just replace instances of '/' with
* '-'.
*/
- p = fifo_name + strlen(AUTOFS_LOGPRI_FIFO);
+ p = fifo_name + strlen(fifodir);
while (*p != '\0') {
if (*p == '/')
*p = '-';
@@ -685,8 +687,9 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
static int create_logpri_fifo(struct autofs_point *ap)
{
int ret = -1;
- int fd;
+ int fd, cl_flags;
char *fifo_name;
+ char buf[MAX_ERR_BUF];
fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
if (!fifo_name) {
@@ -704,18 +707,27 @@ static int create_logpri_fifo(struct autofs_point *ap)
ret = mkfifo(fifo_name, S_IRUSR|S_IWUSR);
if (ret != 0) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
crit(ap->logopt,
- "mkfifo for %s returned %d", fifo_name, errno);
+ "mkfifo for %s failed: %s", fifo_name, estr);
goto out_free;
}
fd = open(fifo_name, O_RDWR|O_NONBLOCK);
if (fd < 0) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
crit(ap->logopt,
- "Failed to open %s, errno %d", fifo_name, errno);
+ "Failed to open %s: %s", fifo_name, estr);
+ unlink(fifo_name);
+ ret = -1;
goto out_free;
}
+ if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
+ cl_flags |= FD_CLOEXEC;
+ fcntl(fd, F_SETFD, cl_flags);
+ }
+
ap->logpri_fifo = fd;
out_free:
@@ -728,6 +740,10 @@ static int destroy_logpri_fifo(struct autofs_point *ap)
int ret = -1;
int fd = ap->logpri_fifo;
char *fifo_name;
+ char buf[MAX_ERR_BUF];
+
+ if (fd == -1)
+ return 0;
fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
if (!fifo_name) {
@@ -739,8 +755,9 @@ static int destroy_logpri_fifo(struct autofs_point *ap)
ret = close(fd);
if (ret != 0) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
warn(ap->logopt,
- "close for fifo %s returned %d", fifo_name, errno);
+ "close for fifo %s: %s", fifo_name, estr);
}
ret = unlink(fifo_name);
@@ -760,11 +777,13 @@ static void handle_fifo_message(struct autofs_point *ap, int fd)
char buffer[PIPE_BUF];
char *end;
long pri;
+ char buf[MAX_ERR_BUF];
memset(buffer, 0, sizeof(buffer));
ret = read(fd, &buffer, sizeof(buffer));
if (ret < 0) {
- warn(ap->logopt, "read on fifo returned error %d", errno);
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ warn(ap->logopt, "read on fifo returned error: %s", estr);
return;
}
@@ -846,16 +865,18 @@ static int set_log_priority(const char *path, int priority)
*/
fd = open(fifo_name, O_WRONLY|O_NONBLOCK);
if (fd < 0) {
- fprintf(stderr, "%s: open of %s failed with %d\n",
- __FUNCTION__, fifo_name, errno);
+ fprintf(stderr, "%s: open of %s failed with %s\n",
+ __FUNCTION__, fifo_name, strerror(errno));
+ fprintf(stderr, "%s: perhaps the fifo wasn't setup,"
+ " please check your log for more information\n", __FUNCTION__);
free(fifo_name);
return -1;
}
if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
fprintf(stderr, "Failed to change logging priority. ");
- fprintf(stderr, "write to fifo failed with errno %d.\n",
- errno);
+ fprintf(stderr, "write to fifo failed: %s.\n",
+ strerror(errno));
close(fd);
free(fifo_name);
return -1;
@@ -870,6 +891,7 @@ static int set_log_priority(const char *path, int priority)
static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
{
struct pollfd fds[3];
+ int pollfds = 3;
char buf[MAX_ERR_BUF];
fds[0].fd = ap->pipefd;
@@ -878,9 +900,11 @@ static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
fds[1].events = POLLIN;
fds[2].fd = ap->logpri_fifo;
fds[2].events = POLLIN;
+ if (fds[2].fd == -1)
+ pollfds--;
for (;;) {
- if (poll(fds, 3, -1) == -1) {
+ if (poll(fds, pollfds, -1) == -1) {
char *estr;
if (errno == EINTR)
continue;
@@ -930,7 +954,7 @@ static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
if (fds[0].revents & POLLIN)
return fullread(ap->pipefd, pkt, kpkt_len);
- if (fds[2].revents & POLLIN) {
+ if (fds[2].fd != -1 && fds[2].revents & POLLIN) {
debug(ap->logopt, "message pending on control fifo.");
handle_fifo_message(ap, fds[2].fd);
}
@@ -983,7 +1007,6 @@ static int autofs_init_ap(struct autofs_point *ap)
crit(ap->logopt,
"failed to create commumication pipe for autofs path %s",
ap->path);
- free(ap->path);
return -1;
}
@@ -1006,7 +1029,6 @@ static int autofs_init_ap(struct autofs_point *ap)
"failed create state pipe for autofs path %s", ap->path);
close(ap->pipefd);
close(ap->kpipefd); /* Close kernel pipe end */
- free(ap->path);
return -1;
}
@@ -1021,15 +1043,8 @@ static int autofs_init_ap(struct autofs_point *ap)
}
if (create_logpri_fifo(ap) < 0) {
- crit(ap->logopt,
- "failed to create FIFO for path %s\n", ap->path);
- destroy_logpri_fifo(ap);
- close(ap->pipefd);
- close(ap->kpipefd);
- free(ap->path);
- close(ap->state_pipe[0]);
- close(ap->state_pipe[1]);
- return -1;
+ logmsg("could not create FIFO for path %s\n", ap->path);
+ logmsg("dynamic log level changes not available for %s", ap->path);
}
return 0;
diff --git a/include/automount.h b/include/automount.h
index 37a3c0a..b0d1a9c 100644
--- a/include/automount.h
+++ b/include/automount.h
@@ -223,8 +223,6 @@ int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev);
#define MAPENT_MAX_LEN 4095
#define PARSE_MAX_BUF KEY_MAX_LEN + MAPENT_MAX_LEN + 2
-#define AUTOFS_LOGPRI_FIFO "/tmp/autofs.fifo"
-
int lookup_nss_read_master(struct master *master, time_t age);
int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
int lookup_enumerate(struct autofs_point *ap,
diff --git a/lib/master.c b/lib/master.c
index 2e24ad0..2188bca 100644
--- a/lib/master.c
+++ b/lib/master.c
@@ -56,6 +56,7 @@ int master_add_autofs_point(struct master_mapent *entry,
ap->state_pipe[0] = -1;
ap->state_pipe[1] = -1;
+ ap->logpri_fifo = -1;
ap->path = strdup(entry->path);
if (!ap->path) {