1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../autofs/3-syslog.patch
5 # Copyright (C) 2006 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
15 # --- T2-COPYRIGHT-NOTE-END ---
17 add -s --stderr option which makes automounter send all log output to stderr
18 adapted from: http://lkml.org/lkml/2004/10/7/217 by Denis Vlasenko
20 diff -urpN autofs-4.1.4-fg/daemon/automount.c autofs-4.1.4-syslog/daemon/automount.c
21 --- autofs-4.1.4-fg/daemon/automount.c 2006-02-12 10:21:38.000000000 -0300
22 +++ autofs-4.1.4-syslog/daemon/automount.c 2006-02-12 10:22:03.000000000 -0300
24 #include <linux/auto_fs4.h>
27 -#define assert(x) do { if (!(x)) { syslog(LOG_CRIT, __FILE__ ":%d: assertion failed: " #x, __LINE__); } } while(0)
28 +#define assert(x) do { if (!(x)) { crit(__FILE__ ":%d: assertion failed: " #x, __LINE__); } } while(0)
30 #define assert(x) do { } while(0)
32 @@ -62,6 +62,8 @@ int do_verbose = 0; /* Verbose feedback
33 int do_debug = 0; /* Enable full debug output */
34 int daemonize = 1; /* Shall we daemonize? */
36 +int log_stderr; /* Use stderr instead of syslog? */
38 sigset_t ready_sigs; /* signals only accepted in ST_READY */
39 sigset_t lock_sigs; /* signals blocked for locking */
40 sigset_t sigchld_mask;
41 @@ -160,7 +162,7 @@ static int umount_ent(const char *root,
44 if (umount_ok || is_smbfs) {
45 - rv = spawnll(LOG_DEBUG,
47 PATH_UMOUNT, PATH_UMOUNT, path_buf, NULL);
50 @@ -314,13 +316,13 @@ static int do_umount_autofs(void)
54 - rv = spawnll(LOG_DEBUG,
56 PATH_UMOUNT, PATH_UMOUNT, ap.path, NULL);
57 if (rv & MTAB_NOTUPDATED) {
58 info("umount %s succeeded: "
59 "mtab not updated, retrying to clean\n",
61 - rv = spawnll(LOG_DEBUG,
63 PATH_UMOUNT, PATH_UMOUNT, ap.path, NULL);
65 ret = stat(ap.path, &st);
66 @@ -450,7 +452,7 @@ static int mount_autofs(char *path)
70 - if (spawnll(LOG_DEBUG, PATH_MOUNT, PATH_MOUNT,
71 + if (spawnll(debug, PATH_MOUNT, PATH_MOUNT,
72 "-t", "autofs", "-o", options, our_name, path, NULL) != 0) {
73 crit("failed to mount autofs path %s", ap.path);
75 @@ -542,7 +544,7 @@ static int send_fail(unsigned int wait_q
77 debug("send_fail: token=%d\n", wait_queue_token);
78 if (ioctl(ap.ioctlfd, AUTOFS_IOC_FAIL, wait_queue_token) < 0) {
79 - syslog(LOG_ERR, "AUTOFS_IOC_FAIL: %m");
80 + error("AUTOFS_IOC_FAIL: %m");
84 @@ -948,7 +950,7 @@ static int get_pkt(int fd, union autofs_
85 if (poll(fds, 2, -1) == -1) {
88 - syslog(LOG_ERR, "get_pkt: poll failed: %m");
89 + error("get_pkt: poll failed: %s", strerror(errno));
93 @@ -1277,7 +1279,6 @@ static void become_daemon(void)
99 /* Don't BUSY any directories unnecessarily */
101 @@ -1293,9 +1294,12 @@ static void become_daemon(void)
107 - openlog("automount", LOG_PID, LOG_DAEMON);
108 + /* Initialize logging subsystem */
115 /* Initialize global data */
117 @@ -1317,26 +1321,14 @@ static void become_daemon(void)
121 - /* Redirect all our file descriptors to /dev/null */
122 - if ((nullfd = open("/dev/null", O_RDWR)) < 0) {
123 - crit("cannot open /dev/null: %m");
127 - if (dup2(nullfd, STDIN_FILENO) < 0 ||
128 - dup2(nullfd, STDOUT_FILENO) < 0 || dup2(nullfd, STDERR_FILENO) < 0) {
129 - crit("redirecting file descriptors failed: %m");
132 - if (nullfd > 2) close(nullfd);
134 /* Write pid file if requested */
136 if ((pidfp = fopen(pid_file, "wt"))) {
137 fprintf(pidfp, "%lu\n", (unsigned long) my_pid);
140 - warn("failed to write pid file %s: %m", pid_file);
141 + warn("failed to write pid file %s: %s", pid_file,
146 @@ -1386,6 +1378,7 @@ static void usage(void)
147 " -p --pid-file f write process id to file f\n"
148 " -t --timeout n auto-unmount in n seconds (0-disable)\n"
149 " -f --foreground do not daemonize\n"
150 + " -s --stderr log to stderr instead of syslog\n"
151 " -v --verbose be verbose\n"
152 " -d --debug be even more verbose\n"
153 " -V --version print version and exit\n"
154 @@ -1680,6 +1673,7 @@ int main(int argc, char *argv[])
155 {"pid-file", 1, 0, 'p'},
156 {"timeout", 1, 0, 't'},
157 {"foreground", 0, 0, 'f'},
158 + {"stderr", 0, 0, 's'},
159 {"verbose", 0, 0, 'v'},
160 {"debug", 0, 0, 'd'},
161 {"version", 0, 0, 'V'},
162 @@ -1697,7 +1691,7 @@ int main(int argc, char *argv[])
163 ap.dir_created = 0; /* We haven't created the main directory yet */
166 - while ((opt = getopt_long(argc, argv, "+hp:t:fvdVg", long_options, NULL)) != EOF) {
167 + while ((opt = getopt_long(argc, argv, "+hp:t:fsvdVg", long_options, NULL)) != EOF) {
171 @@ -1715,6 +1709,10 @@ int main(int argc, char *argv[])
182 @@ -1739,7 +1737,7 @@ int main(int argc, char *argv[])
185 if (geteuid() != 0) {
186 - fprintf(stderr, "%s: This program must be run by root.\n", program);
187 + fprintf(stderr, "%s: This program must be run by root\n", program);
191 @@ -1766,9 +1764,9 @@ int main(int argc, char *argv[])
195 - syslog(LOG_DEBUG, "Map argc = %d", mapargc);
196 + debug("Map argc = %d", mapargc);
197 for (i = 0; i < mapargc; i++)
198 - syslog(LOG_DEBUG, "Map argv[%d] = %s", i, mapargv[i]);
199 + debug("Map argv[%d] = %s", i, mapargv[i]);
203 diff -urpN autofs-4.1.4-fg/daemon/spawn.c autofs-4.1.4-syslog/daemon/spawn.c
204 --- autofs-4.1.4-fg/daemon/spawn.c 2005-02-10 09:56:53.000000000 -0300
205 +++ autofs-4.1.4-syslog/daemon/spawn.c 2006-02-12 10:22:03.000000000 -0300
206 @@ -199,7 +199,7 @@ out:
208 #define ERRBUFSIZ 2047 /* Max length of error string excl \0 */
210 -static int do_spawn(int logpri, int use_lock, const char *prog, const char *const *argv)
211 +static int do_spawn(logger* log, int use_lock, const char *prog, const char *const *argv)
214 int status, pipefd[2];
215 @@ -260,7 +260,7 @@ static int do_spawn(int logpri, int use_
216 while (errp && (p = memchr(sp, '\n', errp))) {
218 if (sp[0]) /* Don't output empty lines */
219 - syslog(logpri, ">> %s", sp);
224 @@ -271,7 +271,7 @@ static int do_spawn(int logpri, int use_
225 if (errp >= ERRBUFSIZ) {
226 /* Line too long, split */
228 - syslog(logpri, ">> %s", errbuf);
229 + log(">> %s", errbuf);
233 @@ -281,7 +281,7 @@ static int do_spawn(int logpri, int use_
235 /* End of file without \n */
237 - syslog(logpri, ">> %s", errbuf);
238 + log(">> %s", errbuf);
241 if (waitpid(f, &status, 0) != f)
242 @@ -296,12 +296,12 @@ static int do_spawn(int logpri, int use_
246 -int spawnv(int logpri, const char *prog, const char *const *argv)
247 +int spawnv(logger* log, const char *prog, const char *const *argv)
249 - return do_spawn(logpri, 0, prog, argv);
250 + return do_spawn(log, 0, prog, argv);
253 -int spawnl(int logpri, const char *prog, ...)
254 +int spawnl(logger* log, const char *prog, ...)
258 @@ -319,10 +319,10 @@ int spawnl(int logpri, const char *prog,
259 while ((*p++ = va_arg(arg, char *)));
262 - return do_spawn(logpri, 0, prog, (const char **) argv);
263 + return do_spawn(log, 0, prog, (const char **) argv);
266 -int spawnll(int logpri, const char *prog, ...)
267 +int spawnll(logger* log, const char *prog, ...)
271 @@ -340,5 +340,5 @@ int spawnll(int logpri, const char *prog
272 while ((*p++ = va_arg(arg, char *)));
275 - return do_spawn(logpri, 1, prog, (const char **) argv);
276 + return do_spawn(log, 1, prog, (const char **) argv);
278 diff -urpN autofs-4.1.4-fg/include/automount.h autofs-4.1.4-syslog/include/automount.h
279 --- autofs-4.1.4-fg/include/automount.h 2005-01-26 10:03:02.000000000 -0300
280 +++ autofs-4.1.4-syslog/include/automount.h 2006-02-12 10:22:03.000000000 -0300
281 @@ -117,13 +117,30 @@ struct autofs_point {
283 extern struct autofs_point ap;
285 + /* log notification */
287 +extern int do_verbose;
288 +extern int do_debug;
290 +typedef void logger(const char* msg, ...);
292 +extern void (*info)(const char* msg, ...);
293 +extern void (*notice)(const char* msg, ...);
294 +extern void (*warn)(const char* msg, ...);
295 +extern void (*error)(const char* msg, ...);
296 +extern void (*crit)(const char* msg, ...);
297 +extern void (*debug)(const char* msg, ...);
299 +void log_to_syslog();
300 +void log_to_stderr();
302 /* Standard function used by daemon or modules */
304 int aquire_lock(void);
305 void release_lock(void);
306 -int spawnll(int logpri, const char *prog, ...);
307 -int spawnl(int logpri, const char *prog, ...);
308 -int spawnv(int logpri, const char *prog, const char *const *argv);
309 +int spawnll(logger *log, const char *prog, ...);
310 +int spawnl(logger *log, const char *prog, ...);
311 +int spawnv(logger *log, const char *prog, const char *const *argv);
312 void reset_signals(void);
313 void ignore_signals(void);
314 void discard_pending(int sig);
315 @@ -282,25 +299,6 @@ int is_mounted(const char *table, const
316 int has_fstab_option(const char *path, const char *opt);
317 int allow_owner_mount(const char *);
319 -/* log notification */
320 -extern int do_verbose;
321 -extern int do_debug;
323 -#define info(msg, args...) \
324 -if (do_verbose || do_debug) \
325 - syslog(LOG_INFO, msg, ##args);
327 -#define warn(msg, args...) \
328 -if (do_verbose || do_debug) \
329 - syslog(LOG_WARNING, msg, ##args);
331 -#define error(msg, args...) syslog(LOG_ERR, msg, ##args);
333 -#define crit(msg, args...) syslog(LOG_CRIT, msg, ##args);
335 -#define debug(msg, args...) \
337 - syslog(LOG_DEBUG, msg, ##args);
341 diff -urpN autofs-4.1.4-fg/lib/Makefile autofs-4.1.4-syslog/lib/Makefile
342 --- autofs-4.1.4-fg/lib/Makefile 2005-01-09 06:16:43.000000000 -0300
343 +++ autofs-4.1.4-syslog/lib/Makefile 2006-02-12 11:06:37.000000000 -0300
344 @@ -12,7 +12,7 @@ RANLIB = /usr/bin/ranlib
345 SRCS = cache.c listmount.c cat_path.c rpc_subs.c mounts.c lock.c
346 RPCS = mount.h mount_clnt.c mount_xdr.c
347 OBJS = cache.o mount_clnt.o mount_xdr.o listmount.o \
348 - cat_path.o rpc_subs.o mounts.o lock.o
349 + cat_path.o rpc_subs.o mounts.o lock.o log.o
353 @@ -48,6 +48,10 @@ listmount.o: listmount.c
354 $(CC) $(CFLAGS) -o listmount.o -c listmount.c
358 + $(CC) $(CFLAGS) -o log.o -c log.c
364 diff -urpN autofs-4.1.4-fg/lib/log.c autofs-4.1.4-syslog/lib/log.c
365 --- autofs-4.1.4-fg/lib/log.c 1969-12-31 21:00:00.000000000 -0300
366 +++ autofs-4.1.4-syslog/lib/log.c 2006-02-12 10:22:03.000000000 -0300
372 +#include <fcntl.h> /* open() */
373 +#include <stdlib.h> /* exit() */
375 +#include "automount.h"
377 +static void null(const char *msg, ...)
381 +void (*info)(const char* msg, ...) = null;
382 +void (*notice)(const char* msg, ...) = null;
383 +void (*warn)(const char* msg, ...) = null;
384 +void (*error)(const char* msg, ...) = null;
385 +void (*crit)(const char* msg, ...) = null;
386 +void (*debug)(const char* msg, ...) = null;
388 +static void syslog_debug(const char *msg, ...)
392 + syslog(LOG_DEBUG, msg, ap);
396 +static void syslog_info(const char *msg, ...)
400 + syslog(LOG_INFO, msg, ap);
404 +static void syslog_notice(const char *msg, ...)
408 + syslog(LOG_NOTICE, msg, ap);
412 +static void syslog_warn(const char *msg, ...)
416 + syslog(LOG_WARNING, msg, ap);
420 +static void syslog_err(const char *msg, ...)
424 + syslog(LOG_ERR, msg, ap);
428 +static void syslog_crit(const char *msg, ...)
432 + syslog(LOG_CRIT, msg, ap);
436 +static void to_stderr(const char *msg, ...)
440 + vfprintf(stderr, msg, ap);
441 + fputc('\n',stderr);
445 +void log_to_syslog()
449 + openlog("automount", LOG_PID, LOG_DAEMON);
450 + if (do_debug) debug = syslog_debug;
451 + if (do_verbose || do_debug) {
452 + info = syslog_info;
453 + notice = syslog_notice;
454 + warn = syslog_warn;
456 + error = syslog_err;
457 + crit = syslog_crit;
459 + /* Redirect all our file descriptors to /dev/null */
460 + nullfd = open("/dev/null", O_RDWR);
462 + crit("cannot open /dev/null: %m");
465 + if (dup2(nullfd, STDIN_FILENO) < 0 ||
466 + dup2(nullfd, STDOUT_FILENO) < 0 || dup2(nullfd, STDERR_FILENO) < 0) {
467 + crit("redirecting file descriptors failed: %m");
470 + if (nullfd > 2) close(nullfd);
473 +void log_to_stderr()
475 + if (do_debug) debug = to_stderr;
476 + if (do_verbose || do_debug) {
478 + notice = to_stderr;
484 diff -urpN autofs-4.1.4-fg/modules/lookup_yp.c autofs-4.1.4-syslog/modules/lookup_yp.c
485 --- autofs-4.1.4-fg/modules/lookup_yp.c 2005-02-10 07:59:59.000000000 -0300
486 +++ autofs-4.1.4-syslog/modules/lookup_yp.c 2006-02-12 10:22:03.000000000 -0300
487 @@ -69,7 +69,7 @@ int lookup_init(const char *mapfmt, int
488 /* This should, but doesn't, take a const char ** */
489 err = yp_get_default_domain((char **) &ctxt->domainname);
491 - crit(MODPREFIX "map %s: %s\n", ctxt->mapname,
492 + crit(MODPREFIX "map %s: %s", ctxt->mapname,
496 diff -urpN autofs-4.1.4-fg/modules/mount_bind.c autofs-4.1.4-syslog/modules/mount_bind.c
497 --- autofs-4.1.4-fg/modules/mount_bind.c 2005-01-10 10:28:29.000000000 -0300
498 +++ autofs-4.1.4-syslog/modules/mount_bind.c 2006-02-12 11:08:06.000000000 -0300
499 @@ -59,7 +59,7 @@ int mount_init(void **context)
500 if (lstat(tmp1, &st1) == -1)
503 - err = spawnl(LOG_DEBUG,
504 + err = spawnl(debug,
505 PATH_MOUNT, PATH_MOUNT, "-n", "--bind", tmp1, tmp2, NULL);
508 @@ -69,7 +69,7 @@ int mount_init(void **context)
511 debug(MODPREFIX "bind_works = %d\n", bind_works);
514 PATH_UMOUNT, PATH_UMOUNT, "-n", tmp2, NULL);
517 @@ -131,7 +131,7 @@ int mount_mount(const char *root, const
518 "calling mount --bind " SLOPPY " -o %s %s %s",
519 options, what, fullpath);
521 - err = spawnll(LOG_NOTICE,
522 + err = spawnll(notice,
523 PATH_MOUNT, PATH_MOUNT, "--bind",
524 SLOPPYOPT "-o", options,
525 what, fullpath, NULL);
526 diff -urpN autofs-4.1.4-fg/modules/mount_changer.c autofs-4.1.4-syslog/modules/mount_changer.c
527 --- autofs-4.1.4-fg/modules/mount_changer.c 2005-01-09 06:16:43.000000000 -0300
528 +++ autofs-4.1.4-syslog/modules/mount_changer.c 2006-02-12 11:09:46.000000000 -0300
529 @@ -68,7 +68,7 @@ int mount_mount(const char *root, const
531 debug(MODPREFIX "calling umount %s", what);
533 - err = spawnll(LOG_DEBUG,
534 + err = spawnll(debug,
535 PATH_UMOUNT, PATH_UMOUNT, what, NULL);
537 error(MODPREFIX "umount of %s failed (all may be unmounted)",
538 @@ -98,14 +98,14 @@ int mount_mount(const char *root, const
539 debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
540 fstype, options, what, fullpath);
542 - err = spawnll(LOG_DEBUG,
543 + err = spawnll(debug,
544 PATH_MOUNT, PATH_MOUNT, "-t", fstype,
545 SLOPPYOPT "-o", options, what, fullpath, NULL);
547 debug(MODPREFIX "calling mount -t %s %s %s",
548 fstype, what, fullpath);
550 - err = spawnll(LOG_DEBUG, PATH_MOUNT, PATH_MOUNT,
551 + err = spawnll(debug, PATH_MOUNT, PATH_MOUNT,
552 "-t", fstype, what, fullpath, NULL);
555 diff -urpN autofs-4.1.4-fg/modules/mount_ext2.c autofs-4.1.4-syslog/modules/mount_ext2.c
556 --- autofs-4.1.4-fg/modules/mount_ext2.c 2005-01-10 10:28:29.000000000 -0300
557 +++ autofs-4.1.4-syslog/modules/mount_ext2.c 2006-02-12 11:10:21.000000000 -0300
558 @@ -93,10 +93,10 @@ int mount_mount(const char *root, const
561 debug(MODPREFIX "calling %s -n %s", fsck_prog, what);
562 - err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-n", what, NULL);
563 + err = spawnl(debug, fsck_prog, fsck_prog, "-n", what, NULL);
565 debug(MODPREFIX "calling %s -p %s", fsck_prog, what);
566 - err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-p", what, NULL);
567 + err = spawnl(debug, fsck_prog, fsck_prog, "-p", what, NULL);
571 @@ -108,13 +108,13 @@ int mount_mount(const char *root, const
573 debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
574 fstype, options, what, fullpath);
575 - err = spawnll(LOG_NOTICE,
576 + err = spawnll(notice,
577 PATH_MOUNT, PATH_MOUNT, "-t", fstype,
578 SLOPPYOPT "-o", options, what, fullpath, NULL);
580 debug(MODPREFIX "calling mount -t %s %s %s",
581 fstype, what, fullpath);
582 - err = spawnll(LOG_NOTICE,
583 + err = spawnll(notice,
584 PATH_MOUNT, PATH_MOUNT, "-t", fstype,
585 what, fullpath, NULL);
587 diff -urpN autofs-4.1.4-fg/modules/mount_generic.c autofs-4.1.4-syslog/modules/mount_generic.c
588 --- autofs-4.1.4-fg/modules/mount_generic.c 2005-01-10 10:28:29.000000000 -0300
589 +++ autofs-4.1.4-syslog/modules/mount_generic.c 2006-02-12 11:07:28.000000000 -0300
590 @@ -77,13 +77,13 @@ int mount_mount(const char *root, const
591 debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
592 fstype, options, what, fullpath);
594 - err = spawnll(LOG_NOTICE,
595 + err = spawnll(notice,
596 PATH_MOUNT, PATH_MOUNT, "-t", fstype,
597 SLOPPYOPT "-o", options, what, fullpath, NULL);
599 debug(MODPREFIX "calling mount -t %s %s %s",
600 fstype, what, fullpath);
601 - err = spawnll(LOG_NOTICE,
602 + err = spawnll(notice,
603 PATH_MOUNT, PATH_MOUNT, "-t", fstype,
604 what, fullpath, NULL);
606 diff -urpN autofs-4.1.4-fg/modules/mount_nfs.c autofs-4.1.4-syslog/modules/mount_nfs.c
607 --- autofs-4.1.4-fg/modules/mount_nfs.c 2005-04-05 08:42:42.000000000 -0400
608 +++ autofs-4.1.4-syslog/modules/mount_nfs.c 2006-02-12 11:09:09.000000000 -0300
609 @@ -449,14 +449,14 @@ int mount_mount(const char *root, const
610 debug(MODPREFIX "calling mount -t nfs " SLOPPY
611 " -o %s %s %s", nfsoptions, whatstr, fullpath);
613 - err = spawnll(LOG_NOTICE,
614 + err = spawnll(notice,
615 PATH_MOUNT, PATH_MOUNT, "-t",
616 "nfs", SLOPPYOPT "-o", nfsoptions,
617 whatstr, fullpath, NULL);
619 debug(MODPREFIX "calling mount -t nfs %s %s",
621 - err = spawnll(LOG_NOTICE,
622 + err = spawnll(notice,
623 PATH_MOUNT, PATH_MOUNT, "-t",
624 "nfs", whatstr, fullpath, NULL);