]> git.pld-linux.org Git - packages/autofs.git/blame - autofs-5.0.2-dynamic-logging-fixes.patch
- 5.0.3 with few official patches. ldap fixes needed
[packages/autofs.git] / autofs-5.0.2-dynamic-logging-fixes.patch
CommitLineData
3d551623
PG
1diff --git a/Makefile.conf.in b/Makefile.conf.in
2index ea5fe1d..09c3129 100644
3--- a/Makefile.conf.in
4+++ b/Makefile.conf.in
5@@ -71,6 +71,9 @@ autofsconfdir = @confdir@
6 # Location for autofs maps
7 autofsmapdir = @mapdir@
8
9+# Location for autofs fifos
10+autofsfifodir = @fifodir@
11+
12 # Where to install the automount program
13 sbindir = @sbindir@
14
15diff --git a/aclocal.m4 b/aclocal.m4
16index ffeb232..118ef0d 100644
17--- a/aclocal.m4
18+++ b/aclocal.m4
19@@ -120,6 +120,22 @@ AC_DEFUN(AF_MAP_D,
20 done
21 fi])
22
23+dnl --------------------------------------------------------------------------
24+dnl AF_FIFO_D
25+dnl
26+dnl Check the location of the autofs fifos directory
27+dnl --------------------------------------------------------------------------
28+AC_DEFUN(AF_FIFO_D,
29+[if test -z "$fifodir"; then
30+ for fifo_d in /var/run /tmp; do
31+ if test -z "$fifodir"; then
32+ if test -d "$fifo_d"; then
33+ fifodir="$fifo_d"
34+ fi
35+ fi
36+ done
37+fi])
38+
39 dnl ----------------------------------- ## -*- Autoconf -*-
40 dnl Check if --with-dmalloc was given. ##
41 dnl From Franc,ois Pinard ##
42diff --git a/configure b/configure
43index 3508224..0360086 100755
44--- a/configure
45+++ b/configure
46@@ -654,6 +654,7 @@ target_alias
47 initdir
48 confdir
49 mapdir
50+fifodir
51 DMALLOCLIB
52 MOUNT
53 HAVE_MOUNT
54@@ -1293,6 +1294,7 @@ Optional Packages:
55 --with-path=PATH look in PATH for binaries needed by the automounter
56 --with-confdir=DIR use DIR for autofs configuration files
57 --with-mapdir=PATH look in PATH for mount maps used by the automounter
58+ --with-fifodir=PATH use PATH as the directory for fifos used by the automounter
59 --with-dmalloc use dmalloc, as in
60 http://www.dmalloc.com/dmalloc.tar.gz
61 --with-hesiod=DIR enable Hesiod support (libs and includes in DIR)
62@@ -1844,6 +1846,36 @@ echo "${ECHO_T}$mapdir" >&6; }
63
64
65 #
66+# The user can specify --with-fifodir=PATH to specify where autofs fifos go
67+#
68+if test -z "$fifodir"; then
69+ for fifo_d in /var/run /tmp; do
70+ if test -z "$fifodir"; then
71+ if test -d "$fifo_d"; then
72+ fifodir="$fifo_d"
73+ fi
74+ fi
75+ done
76+fi
77+
78+# Check whether --with-fifodir was given.
79+if test "${with_fifodir+set}" = set; then
80+ withval=$with_fifodir; if test -z "$withval" -o "$withval" = "yes" -o "$withval" = "no"
81+ then
82+ :
83+ else
84+ fifodir="${withval}"
85+ fi
86+
87+fi
88+
89+{ echo "$as_me:$LINENO: checking for autofs fifos directory" >&5
90+echo $ECHO_N "checking for autofs fifos directory... $ECHO_C" >&6; }
91+{ echo "$as_me:$LINENO: result: $fifodir" >&5
92+echo "${ECHO_T}$fifodir" >&6; }
93+
94+
95+#
96 # Optional include dmalloc
97 #
98 { echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5
99@@ -6074,6 +6106,7 @@ target_alias!$target_alias$ac_delim
100 initdir!$initdir$ac_delim
101 confdir!$confdir$ac_delim
102 mapdir!$mapdir$ac_delim
103+fifodir!$fifodir$ac_delim
104 DMALLOCLIB!$DMALLOCLIB$ac_delim
105 MOUNT!$MOUNT$ac_delim
106 HAVE_MOUNT!$HAVE_MOUNT$ac_delim
107@@ -6124,7 +6157,7 @@ LIBOBJS!$LIBOBJS$ac_delim
108 LTLIBOBJS!$LTLIBOBJS$ac_delim
109 _ACEOF
110
111- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 88; then
112+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 89; then
113 break
114 elif $ac_last_try; then
115 { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
116diff --git a/configure.in b/configure.in
117index 8cddf90..a83b3f1 100644
118--- a/configure.in
119+++ b/configure.in
120@@ -79,6 +79,23 @@ AC_MSG_RESULT([$mapdir])
121 AC_SUBST(mapdir)
122
123 #
124+# The user can specify --with-fifodir=PATH to specify where autofs fifos go
125+#
126+AF_FIFO_D()
127+AC_ARG_WITH(fifodir,
128+[ --with-fifodir=PATH use PATH as the directory for fifos used by the automounter],
129+ if test -z "$withval" -o "$withval" = "yes" -o "$withval" = "no"
130+ then
131+ :
132+ else
133+ fifodir="${withval}"
134+ fi
135+)
136+AC_MSG_CHECKING([for autofs fifos directory])
137+AC_MSG_RESULT([$fifodir])
138+AC_SUBST(fifodir)
139+
140+#
141 # Optional include dmalloc
142 #
143 AM_WITH_DMALLOC()
144diff --git a/daemon/Makefile b/daemon/Makefile
145index 4ee70eb..528a684 100644
146--- a/daemon/Makefile
147+++ b/daemon/Makefile
148@@ -16,6 +16,7 @@ CFLAGS += -rdynamic $(DAEMON_CFLAGS) -D_GNU_SOURCE -I../include
149 CFLAGS += -DAUTOFS_LIB_DIR=\"$(autofslibdir)\"
150 CFLAGS += -DAUTOFS_MAP_DIR=\"$(autofsmapdir)\"
151 CFLAGS += -DAUTOFS_CONF_DIR=\"$(autofsconfdir)\"
152+CFLAGS += -DAUTOFS_FIFO_DIR=\"$(autofsfifodir)\"
153 CFLAGS += -DVERSION_STRING=\"$(version)\"
154 LDFLAGS += -rdynamic
155 LIBS = -ldl
156diff --git a/daemon/automount.c b/daemon/automount.c
157index 7e7d1e6..a12b6da 100644
158--- a/daemon/automount.c
159+++ b/daemon/automount.c
160@@ -50,6 +50,9 @@ const char *libdir = AUTOFS_LIB_DIR; /* Location of library modules */
161 const char *mapdir = AUTOFS_MAP_DIR; /* Location of mount maps */
162 const char *confdir = AUTOFS_CONF_DIR; /* Location of autofs config file */
163
164+/* autofs fifo name prefix */
165+const char *fifodir = AUTOFS_FIFO_DIR "/autofs.fifo";
166+
167 const char *global_options; /* Global option, from command line */
168
169 static char *pid_file = NULL; /* File in which to keep pid */
170@@ -650,14 +653,13 @@ static int fullread(int fd, void *ptr, size_t len)
171 static char *automount_path_to_fifo(unsigned logopt, const char *path)
172 {
173 char *fifo_name, *p;
174- int name_len = strlen(path) + strlen(AUTOFS_LOGPRI_FIFO) + 1;
175+ int name_len = strlen(path) + strlen(fifodir) + 1;
176 int ret;
177
178 fifo_name = malloc(name_len);
179 if (!fifo_name)
180 return NULL;
181- ret = snprintf(fifo_name, name_len, "%s%s",
182- AUTOFS_LOGPRI_FIFO, path);
183+ ret = snprintf(fifo_name, name_len, "%s%s", fifodir, path);
184 if (ret >= name_len) {
185 info(logopt,
186 "fifo path for \"%s\" truncated to \"%s\". This may "
187@@ -670,7 +672,7 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
188 * create the fifo name, we will just replace instances of '/' with
189 * '-'.
190 */
191- p = fifo_name + strlen(AUTOFS_LOGPRI_FIFO);
192+ p = fifo_name + strlen(fifodir);
193 while (*p != '\0') {
194 if (*p == '/')
195 *p = '-';
196@@ -685,8 +687,9 @@ static char *automount_path_to_fifo(unsigned logopt, const char *path)
197 static int create_logpri_fifo(struct autofs_point *ap)
198 {
199 int ret = -1;
200- int fd;
201+ int fd, cl_flags;
202 char *fifo_name;
203+ char buf[MAX_ERR_BUF];
204
205 fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
206 if (!fifo_name) {
207@@ -704,18 +707,27 @@ static int create_logpri_fifo(struct autofs_point *ap)
208
209 ret = mkfifo(fifo_name, S_IRUSR|S_IWUSR);
210 if (ret != 0) {
211+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
212 crit(ap->logopt,
213- "mkfifo for %s returned %d", fifo_name, errno);
214+ "mkfifo for %s failed: %s", fifo_name, estr);
215 goto out_free;
216 }
217
218 fd = open(fifo_name, O_RDWR|O_NONBLOCK);
219 if (fd < 0) {
220+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
221 crit(ap->logopt,
222- "Failed to open %s, errno %d", fifo_name, errno);
223+ "Failed to open %s: %s", fifo_name, estr);
224+ unlink(fifo_name);
225+ ret = -1;
226 goto out_free;
227 }
228
229+ if ((cl_flags = fcntl(fd, F_GETFD, 0)) != -1) {
230+ cl_flags |= FD_CLOEXEC;
231+ fcntl(fd, F_SETFD, cl_flags);
232+ }
233+
234 ap->logpri_fifo = fd;
235
236 out_free:
237@@ -728,6 +740,10 @@ static int destroy_logpri_fifo(struct autofs_point *ap)
238 int ret = -1;
239 int fd = ap->logpri_fifo;
240 char *fifo_name;
241+ char buf[MAX_ERR_BUF];
242+
243+ if (fd == -1)
244+ return 0;
245
246 fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
247 if (!fifo_name) {
248@@ -739,8 +755,9 @@ static int destroy_logpri_fifo(struct autofs_point *ap)
249
250 ret = close(fd);
251 if (ret != 0) {
252+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
253 warn(ap->logopt,
254- "close for fifo %s returned %d", fifo_name, errno);
255+ "close for fifo %s: %s", fifo_name, estr);
256 }
257
258 ret = unlink(fifo_name);
259@@ -760,11 +777,13 @@ static void handle_fifo_message(struct autofs_point *ap, int fd)
260 char buffer[PIPE_BUF];
261 char *end;
262 long pri;
263+ char buf[MAX_ERR_BUF];
264
265 memset(buffer, 0, sizeof(buffer));
266 ret = read(fd, &buffer, sizeof(buffer));
267 if (ret < 0) {
268- warn(ap->logopt, "read on fifo returned error %d", errno);
269+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
270+ warn(ap->logopt, "read on fifo returned error: %s", estr);
271 return;
272 }
273
274@@ -846,16 +865,18 @@ static int set_log_priority(const char *path, int priority)
275 */
276 fd = open(fifo_name, O_WRONLY|O_NONBLOCK);
277 if (fd < 0) {
278- fprintf(stderr, "%s: open of %s failed with %d\n",
279- __FUNCTION__, fifo_name, errno);
280+ fprintf(stderr, "%s: open of %s failed with %s\n",
281+ __FUNCTION__, fifo_name, strerror(errno));
282+ fprintf(stderr, "%s: perhaps the fifo wasn't setup,"
283+ " please check your log for more information\n", __FUNCTION__);
284 free(fifo_name);
285 return -1;
286 }
287
288 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
289 fprintf(stderr, "Failed to change logging priority. ");
290- fprintf(stderr, "write to fifo failed with errno %d.\n",
291- errno);
292+ fprintf(stderr, "write to fifo failed: %s.\n",
293+ strerror(errno));
294 close(fd);
295 free(fifo_name);
296 return -1;
297@@ -870,6 +891,7 @@ static int set_log_priority(const char *path, int priority)
298 static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
299 {
300 struct pollfd fds[3];
301+ int pollfds = 3;
302 char buf[MAX_ERR_BUF];
303
304 fds[0].fd = ap->pipefd;
305@@ -878,9 +900,11 @@ static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
306 fds[1].events = POLLIN;
307 fds[2].fd = ap->logpri_fifo;
308 fds[2].events = POLLIN;
309+ if (fds[2].fd == -1)
310+ pollfds--;
311
312 for (;;) {
313- if (poll(fds, 3, -1) == -1) {
314+ if (poll(fds, pollfds, -1) == -1) {
315 char *estr;
316 if (errno == EINTR)
317 continue;
318@@ -930,7 +954,7 @@ static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
319 if (fds[0].revents & POLLIN)
320 return fullread(ap->pipefd, pkt, kpkt_len);
321
322- if (fds[2].revents & POLLIN) {
323+ if (fds[2].fd != -1 && fds[2].revents & POLLIN) {
324 debug(ap->logopt, "message pending on control fifo.");
325 handle_fifo_message(ap, fds[2].fd);
326 }
327@@ -983,7 +1007,6 @@ static int autofs_init_ap(struct autofs_point *ap)
328 crit(ap->logopt,
329 "failed to create commumication pipe for autofs path %s",
330 ap->path);
331- free(ap->path);
332 return -1;
333 }
334
335@@ -1006,7 +1029,6 @@ static int autofs_init_ap(struct autofs_point *ap)
336 "failed create state pipe for autofs path %s", ap->path);
337 close(ap->pipefd);
338 close(ap->kpipefd); /* Close kernel pipe end */
339- free(ap->path);
340 return -1;
341 }
342
343@@ -1021,15 +1043,8 @@ static int autofs_init_ap(struct autofs_point *ap)
344 }
345
346 if (create_logpri_fifo(ap) < 0) {
347- crit(ap->logopt,
348- "failed to create FIFO for path %s\n", ap->path);
349- destroy_logpri_fifo(ap);
350- close(ap->pipefd);
351- close(ap->kpipefd);
352- free(ap->path);
353- close(ap->state_pipe[0]);
354- close(ap->state_pipe[1]);
355- return -1;
356+ logmsg("could not create FIFO for path %s\n", ap->path);
357+ logmsg("dynamic log level changes not available for %s", ap->path);
358 }
359
360 return 0;
361diff --git a/include/automount.h b/include/automount.h
362index 37a3c0a..b0d1a9c 100644
363--- a/include/automount.h
364+++ b/include/automount.h
365@@ -223,8 +223,6 @@ int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev);
366 #define MAPENT_MAX_LEN 4095
367 #define PARSE_MAX_BUF KEY_MAX_LEN + MAPENT_MAX_LEN + 2
368
369-#define AUTOFS_LOGPRI_FIFO "/tmp/autofs.fifo"
370-
371 int lookup_nss_read_master(struct master *master, time_t age);
372 int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
373 int lookup_enumerate(struct autofs_point *ap,
374diff --git a/lib/master.c b/lib/master.c
375index 2e24ad0..2188bca 100644
376--- a/lib/master.c
377+++ b/lib/master.c
378@@ -56,6 +56,7 @@ int master_add_autofs_point(struct master_mapent *entry,
379
380 ap->state_pipe[0] = -1;
381 ap->state_pipe[1] = -1;
382+ ap->logpri_fifo = -1;
383
384 ap->path = strdup(entry->path);
385 if (!ap->path) {
This page took 0.61194 seconds and 4 git commands to generate.