Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37907940
en ru br
ALT Linux repos
S:5.1.8-alt6
D:5.0.3-alt1.1
5.0: 5.0.4-alt2
4.1: 5.0.1-alt1
4.0: 5.0.1-alt1
3.0: 4.1.4-alt0.3

Other repositories
Upstream:4.1.4

Group :: System/Kernel and hardware
RPM: autofs

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: autofs-4.1.4-log-stderr.patch
Download


diff -uNr autofs-4.1.4-orig/daemon/automount.c autofs-4.1.4/daemon/automount.c
--- autofs-4.1.4-orig/daemon/automount.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/daemon/automount.c	2005-05-08 20:15:42 +0400
@@ -39,7 +39,7 @@
 #include <linux/auto_fs4.h>
 
 #ifndef NDEBUG
-#define assert(x)	do { if (!(x)) { syslog(LOG_CRIT, __FILE__ ":%d: assertion failed: " #x, __LINE__); } } while(0)
+#define assert(x)	do { if (!(x)) { crit(__FILE__ ":%d: assertion failed: " #x, __LINE__); } } while(0)
 #else
 #define assert(x)	do { } while(0)
 #endif
@@ -61,6 +61,7 @@
 int do_verbose = 0;		/* Verbose feedback option */
 int do_debug = 0;		/* Enable full debug output */
 int daemonize = 1;		/* Shall we daemonize? */
+int log_stderr = 0;		/* Use stderr instead of syslog? */
 
 sigset_t ready_sigs;		/* signals only accepted in ST_READY */
 sigset_t lock_sigs;		/* signals blocked for locking */
@@ -160,7 +161,7 @@
 			umount_ok = 1;
 
 		if (umount_ok || is_smbfs) {
-			rv = spawnll(LOG_DEBUG, 
+			rv = spawnll(debug,
 				    PATH_UMOUNT, PATH_UMOUNT, path_buf, NULL);
 		}
 	}
@@ -314,13 +315,13 @@
 		struct stat st;
 		int ret;
 
-		rv = spawnll(LOG_DEBUG,
+		rv = spawnll(debug,
 			    PATH_UMOUNT, PATH_UMOUNT, ap.path, NULL);
 		if (rv & MTAB_NOTUPDATED) {
 			info("umount %s succeeded: "
 			     "mtab not updated, retrying to clean",
 			      ap.path);
-			rv = spawnll(LOG_DEBUG,
+			rv = spawnll(debug,
 				    PATH_UMOUNT, PATH_UMOUNT, ap.path, NULL);
 		}
 		ret = stat(ap.path, &st);
@@ -450,7 +451,7 @@
         }
 	our_name[len] = '\0';
 
-	if (spawnll(LOG_DEBUG, PATH_MOUNT, PATH_MOUNT,
+	if (spawnll(debug, PATH_MOUNT, PATH_MOUNT,
 		   "-t", "autofs", "-o", options, our_name, path, NULL) != 0) {
 		crit("failed to mount autofs path %s", ap.path);
 		rmdir_path(ap.path);
@@ -1020,7 +1021,7 @@
 	pid_t f;
 	struct pending_mount *mt = NULL;
 
-	debug("handle_packet_missing: token %ld, name %s\n",
+	debug("handle_packet_missing: token %ld, name %s",
 		(unsigned long) pkt->wait_queue_token, pkt->name);
 
 	/* Ignore packet if we're trying to shut down */
@@ -1240,7 +1241,7 @@
 {
 	int ret;
 
-	debug("handle_packet_expire_multi: token %ld, name %s\n",
+	debug("handle_packet_expire_multi: token %ld, name %s",
 		  (unsigned long) pkt->wait_queue_token, pkt->name);
 
 	ret = handle_expire(pkt->name, pkt->len, pkt->wait_queue_token);
@@ -1277,7 +1278,6 @@
 {
 	FILE *pidfp;
 	pid_t pid;
-	int nullfd;
 
 	/* Don't BUSY any directories unnecessarily */
 	chdir("/");
@@ -1294,8 +1294,12 @@
 		}
 	}
 
-	/* Open syslog */
-	openlog("automount", LOG_PID, LOG_DAEMON);
+	/* Initialize logging subsystem */
+	if(!log_stderr) {
+		log_to_syslog();
+	} else {
+		log_to_stderr();
+	}
 
 	/* Initialize global data */
 	my_pid = getpid();
@@ -1317,19 +1321,6 @@
 	}
 	my_pgrp = getpgrp();
 
-	/* Redirect all our file descriptors to /dev/null */
-	if ((nullfd = open("/dev/null", O_RDWR)) < 0) {
-		crit("cannot open /dev/null: %s", strerror(errno));
-		exit(1);
-	}
-
-	if (dup2(nullfd, STDIN_FILENO) < 0 ||
-	    dup2(nullfd, STDOUT_FILENO) < 0 || dup2(nullfd, STDERR_FILENO) < 0) {
-		crit("redirecting file descriptors failed: %s", strerror(errno));
-		exit(1);
-	}
-	close(nullfd);
-
 	/* Write pid file if requested */
 	if (pid_file) {
 		if ((pidfp = fopen(pid_file, "wt"))) {
@@ -1388,6 +1379,7 @@
 		"	-p --pid-file f	write process id to file f\n"
 		"	-t --timeout n	auto-unmount in n seconds (0-disable)\n"
 		"	-f --foreground	do not daemonize\n"
+		"	-s --stderr	log to stderr instead of syslog\n"
 		"	-v --verbose	be verbose\n"
 		"	-d --debug	be even more verbose\n"
 		"	-V --version	print version and exit\n"
@@ -1682,6 +1674,7 @@
 		{"pid-file", 1, 0, 'p'},
 		{"timeout", 1, 0, 't'},
 		{"foreground", 0, 0, 'f'},
+		{"stderr", 0, 0, 's'},
 		{"verbose", 0, 0, 'v'},
 		{"debug", 0, 0, 'd'},
 		{"version", 0, 0, 'V'},
@@ -1699,7 +1692,7 @@
 	ap.dir_created = 0; /* We haven't created the main directory yet */
 
 	opterr = 0;
-	while ((opt = getopt_long(argc, argv, "+hp:t:fvdVg", long_options, NULL)) != EOF) {
+	while ((opt = getopt_long(argc, argv, "+hp:t:fsvdVg", long_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage();
@@ -1717,6 +1710,10 @@
 			daemonize = 0;
 			break;
 
+		case 's':
+			log_stderr = 1;
+			break;
+
 		case 'v':
 			do_verbose = 1;
 			break;
@@ -1768,9 +1765,9 @@
 #ifdef DEBUG
 	if (mapargc) {
 		int i;
-		syslog(LOG_DEBUG, "Map argc = %d", mapargc);
+		debug("Map argc = %d", mapargc);
 		for (i = 0; i < mapargc; i++)
-			syslog(LOG_DEBUG, "Map argv[%d] = %s", i, mapargv[i]);
+			debug("Map argv[%d] = %s", i, mapargv[i]);
 	}
 #endif
 
diff -uNr autofs-4.1.4-orig/daemon/spawn.c autofs-4.1.4/daemon/spawn.c
--- autofs-4.1.4-orig/daemon/spawn.c	2005-02-10 15:56:53 +0300
+++ autofs-4.1.4/daemon/spawn.c	2005-05-08 20:15:42 +0400
@@ -199,7 +199,7 @@
 
 #define ERRBUFSIZ 2047		/* Max length of error string excl \0 */
 
-static int do_spawn(int logpri, int use_lock, const char *prog, const char *const *argv)
+static int do_spawn(logger* log, int use_lock, const char *prog, const char *const *argv)
 {
 	pid_t f;
 	int status, pipefd[2];
@@ -260,7 +260,7 @@
 				while (errp && (p = memchr(sp, '\n', errp))) {
 					*p++ = '\0';
 					if (sp[0])	/* Don't output empty lines */
-						syslog(logpri, ">> %s", sp);
+						log(">> %s", sp);
 					errp -= (p - sp);
 					sp = p;
 				}
@@ -271,7 +271,7 @@
 				if (errp >= ERRBUFSIZ) {
 					/* Line too long, split */
 					errbuf[errp] = '\0';
-					syslog(logpri, ">> %s", errbuf);
+					log(">> %s", errbuf);
 					errp = 0;
 				}
 			}
@@ -281,7 +281,7 @@
 		if (errp > 0) {
 			/* End of file without \n */
 			errbuf[errp] = '\0';
-			syslog(logpri, ">> %s", errbuf);
+			log(">> %s", errbuf);
 		}
 
 		if (waitpid(f, &status, 0) != f)
@@ -296,12 +296,12 @@
 	}
 }
 
-int spawnv(int logpri, const char *prog, const char *const *argv)
+int spawnv(logger* log, const char *prog, const char *const *argv)
 {
-	return do_spawn(logpri, 0, prog, argv);
+	return do_spawn(log, 0, prog, argv);
 }
 
-int spawnl(int logpri, const char *prog, ...)
+int spawnl(logger* log, const char *prog, ...)
 {
 	va_list arg;
 	int argc;
@@ -319,10 +319,10 @@
 	while ((*p++ = va_arg(arg, char *)));
 	va_end(arg);
 
-	return do_spawn(logpri, 0, prog, (const char **) argv);
+	return do_spawn(log, 0, prog, (const char **) argv);
 }
 
-int spawnll(int logpri, const char *prog, ...)
+int spawnll(logger* log, const char *prog, ...)
 {
 	va_list arg;
 	int argc;
@@ -340,5 +340,5 @@
 	while ((*p++ = va_arg(arg, char *)));
 	va_end(arg);
 
-	return do_spawn(logpri, 1, prog, (const char **) argv);
+	return do_spawn(log, 1, prog, (const char **) argv);
 }
diff -uNr autofs-4.1.4-orig/include/automount.h autofs-4.1.4/include/automount.h
--- autofs-4.1.4-orig/include/automount.h	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/include/automount.h	2005-05-08 20:15:42 +0400
@@ -117,13 +117,29 @@
 
 extern struct autofs_point ap; 
 
+/* log notification */
+extern int do_verbose;
+extern int do_debug;
+
+extern void (*info)(const char* msg, ...);
+extern void (*notice)(const char* msg, ...);
+extern void (*warn)(const char* msg, ...);
+extern void (*error)(const char* msg, ...);
+extern void (*crit)(const char* msg, ...);
+extern void (*debug)(const char* msg, ...);
+
+typedef void logger(const char* msg, ...);
+
+void log_to_syslog();
+void log_to_stderr();
+
 /* Standard function used by daemon or modules */
 
 int aquire_lock(void);
 void release_lock(void);
-int spawnll(int logpri, const char *prog, ...);
-int spawnl(int logpri, const char *prog, ...);
-int spawnv(int logpri, const char *prog, const char *const *argv);
+int spawnll(logger* log, const char *prog, ...);
+int spawnl(logger* log, const char *prog, ...);
+int spawnv(logger* log, const char *prog, const char *const *argv);
 void reset_signals(void);
 void ignore_signals(void);
 void discard_pending(int sig);
@@ -290,25 +306,4 @@
 int isfilemap(const char *);
 int isypmap(const char *);
 
-/* log notification */
-extern int do_verbose;
-extern int do_debug;
-
-#define info(msg, args...) 		\
-if (do_verbose || do_debug) 		\
-	syslog(LOG_INFO, msg, ##args);
-
-#define warn(msg, args...) 			\
-if (do_verbose || do_debug) 		\
-	syslog(LOG_WARNING, msg, ##args);
-
-#define error(msg, args...)	syslog(LOG_ERR, msg, ##args);
-
-#define crit(msg, args...)	syslog(LOG_CRIT, msg, ##args);
-
-#define debug(msg, args...) 		\
-if (do_debug) 				\
-	syslog(LOG_DEBUG, msg, ##args);
-
 #endif
-
diff -uNr autofs-4.1.4-orig/lib/log.c autofs-4.1.4/lib/log.c
--- autofs-4.1.4-orig/lib/log.c	1970-01-01 03:00:00 +0300
+++ autofs-4.1.4/lib/log.c	2005-05-08 20:15:42 +0400
@@ -0,0 +1,119 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <fcntl.h>	/* open() */
+#include <stdlib.h>	/* exit() */
+#include <string.h>	/* strerror() */
+#include <errno.h>
+
+#include "automount.h"
+
+static void null(const char *msg, ...)
+{
+}
+
+void (*info)(const char* msg, ...) = null;
+void (*notice)(const char* msg, ...) = null;
+void (*warn)(const char* msg, ...) = null;
+void (*error)(const char* msg, ...) = null;
+void (*crit)(const char* msg, ...) = null;
+void (*debug)(const char* msg, ...) = null;
+
+static void syslog_debug(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_DEBUG, msg, ap);
+	va_end(ap);
+}
+
+static void syslog_info(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_INFO, msg, ap);
+	va_end(ap);
+}
+
+static void syslog_notice(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_NOTICE, msg, ap);
+	va_end(ap);
+}
+
+static void syslog_warn(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_WARNING, msg, ap);
+	va_end(ap);
+}
+
+static void syslog_err(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_ERR, msg, ap);
+	va_end(ap);
+}
+
+static void syslog_crit(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vsyslog(LOG_CRIT, msg, ap);
+	va_end(ap);
+}
+
+static void to_stderr(const char *msg, ...)
+{
+	va_list ap;
+	va_start(ap, msg);
+	vfprintf(stderr, msg, ap);
+	fputc('\n',stderr);
+	va_end(ap);
+}
+
+void log_to_syslog()
+{
+	int nullfd;
+
+	openlog("automount", LOG_PID, LOG_DAEMON);
+	if (do_debug) debug = syslog_debug;
+	if (do_verbose || do_debug) {
+		info = syslog_info;
+		notice = syslog_notice;
+		warn = syslog_warn;
+	}
+	error = syslog_err;
+	crit = syslog_crit;
+
+	/* Redirect all our file descriptors to /dev/null */
+	nullfd = open("/dev/null", O_RDWR);
+	if (nullfd < 0) {
+		crit("cannot open /dev/null: %s", strerror(errno));
+		exit(1);
+	}
+	if (dup2(nullfd, STDIN_FILENO) < 0
+	 || dup2(nullfd, STDOUT_FILENO) < 0
+	 || dup2(nullfd, STDERR_FILENO) < 0) {
+		crit("redirecting file descriptors failed: %s", strerror(errno));
+		exit(1);
+	}
+	if (nullfd > 2) close(nullfd);
+}
+
+void log_to_stderr()
+{
+	if (do_debug) debug = to_stderr;
+	if (do_verbose || do_debug) {
+		info = to_stderr;
+		notice = to_stderr;
+		warn = to_stderr;
+	}
+	error = to_stderr;
+	crit = to_stderr;
+}
diff -uNr autofs-4.1.4-orig/lib/Makefile autofs-4.1.4/lib/Makefile
--- autofs-4.1.4-orig/lib/Makefile	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/lib/Makefile	2005-05-08 20:16:01 +0400
@@ -12,7 +12,7 @@
 SRCS = cache.c listmount.c cat_path.c rpc_subs.c mounts.c lock.c nsswitch.c
 RPCS = mount.h mount_clnt.c mount_xdr.c
 OBJS = cache.o mount_clnt.o mount_xdr.o listmount.o \
-	cat_path.o rpc_subs.o mounts.o lock.o nsswitch.o
+	cat_path.o rpc_subs.o mounts.o lock.o nsswitch.o log.o
 
 LIB = autofs.a
 
@@ -48,6 +48,10 @@
 	$(CC) $(CFLAGS) -o listmount.o -c listmount.c
 	$(STRIP) listmount.o
 
+log.o: log.c
+	$(CC) $(CFLAGS) -o log.o -c log.c
+	$(STRIP) log.o
+
 install: all
 
 clean:
diff -uNr autofs-4.1.4-orig/modules/mount_bind.c autofs-4.1.4/modules/mount_bind.c
--- autofs-4.1.4-orig/modules/mount_bind.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/modules/mount_bind.c	2005-05-08 20:15:42 +0400
@@ -59,7 +59,7 @@
 	if (lstat(tmp1, &st1) == -1)
 		goto out;
 
-	err = spawnl(LOG_DEBUG,
+	err = spawnl(debug,
 	    	     PATH_MOUNT, PATH_MOUNT, "-n", "--bind", tmp1, tmp2, NULL);
 
 	if (err == 0 &&
@@ -69,7 +69,7 @@
 	}
 
 	debug(MODPREFIX "bind_works = %d", bind_works);
-	spawnl(LOG_DEBUG,
+	spawnl(debug,
 	       PATH_UMOUNT, PATH_UMOUNT, "-n", tmp2, NULL);
 
       out:
@@ -132,7 +132,7 @@
 		      "calling mount --bind " SLOPPY " -o %s %s %s",
 		      options, what, fullpath);
 
-		err = spawnll(LOG_NOTICE,
+		err = spawnll(notice,
 			     PATH_MOUNT, PATH_MOUNT, "--bind",
 			     SLOPPYOPT "-o", options,
 			     what, fullpath, NULL);
diff -uNr autofs-4.1.4-orig/modules/mount_changer.c autofs-4.1.4/modules/mount_changer.c
--- autofs-4.1.4-orig/modules/mount_changer.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/modules/mount_changer.c	2005-05-08 20:15:42 +0400
@@ -68,7 +68,7 @@
 
 	debug(MODPREFIX "calling umount %s", what);
 
-	err = spawnll(LOG_DEBUG,
+	err = spawnll(debug,
 		     PATH_UMOUNT, PATH_UMOUNT, what, NULL);
 	if (err) {
 		error(MODPREFIX "umount of %s failed (all may be unmounted)",
@@ -99,14 +99,14 @@
 		debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
 		    fstype, options, what, fullpath);
 
-		err = spawnll(LOG_DEBUG,
+		err = spawnll(debug,
 			     PATH_MOUNT, PATH_MOUNT, "-t", fstype,
 			     SLOPPYOPT "-o", options, what, fullpath, NULL);
 	} else {
 		debug(MODPREFIX "calling mount -t %s %s %s",
 			  fstype, what, fullpath);
 
-		err = spawnll(LOG_DEBUG, PATH_MOUNT, PATH_MOUNT,
+		err = spawnll(debug, PATH_MOUNT, PATH_MOUNT,
 			     "-t", fstype, what, fullpath, NULL);
 	}
 
diff -uNr autofs-4.1.4-orig/modules/mount_ext2.c autofs-4.1.4/modules/mount_ext2.c
--- autofs-4.1.4-orig/modules/mount_ext2.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/modules/mount_ext2.c	2005-05-08 20:15:42 +0400
@@ -94,10 +94,10 @@
 #endif
 	if (ro) {
 		debug(MODPREFIX "calling %s -n %s", fsck_prog, what);
-		err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-n", what, NULL);
+		err = spawnl(debug, fsck_prog, fsck_prog, "-n", what, NULL);
 	} else {
 		debug(MODPREFIX "calling %s -p %s", fsck_prog, what);
-		err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-p", what, NULL);
+		err = spawnl(debug, fsck_prog, fsck_prog, "-p", what, NULL);
 	}
 
 	if (err & ~6) {
@@ -109,13 +109,13 @@
 	if (options) {
 		debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
 		      fstype, options, what, fullpath);
-		err = spawnll(LOG_NOTICE,
+		err = spawnll(notice,
 		             PATH_MOUNT, PATH_MOUNT, "-t", fstype,
 			     SLOPPYOPT "-o", options, what, fullpath, NULL);
 	} else {
 		debug(MODPREFIX "calling mount -t %s %s %s",
 		      fstype, what, fullpath);
-		err = spawnll(LOG_NOTICE,
+		err = spawnll(notice,
 			     PATH_MOUNT, PATH_MOUNT, "-t", fstype,
 			     what, fullpath, NULL);
 	}
diff -uNr autofs-4.1.4-orig/modules/mount_generic.c autofs-4.1.4/modules/mount_generic.c
--- autofs-4.1.4-orig/modules/mount_generic.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/modules/mount_generic.c	2005-05-08 20:15:42 +0400
@@ -78,13 +78,13 @@
 		debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
 		      fstype, options, what, fullpath);
 
-		err = spawnll(LOG_NOTICE,
+		err = spawnll(notice,
 			     PATH_MOUNT, PATH_MOUNT, "-t", fstype,
 			     SLOPPYOPT "-o", options, what, fullpath, NULL);
 	} else {
 		debug(MODPREFIX "calling mount -t %s %s %s",
 		      fstype, what, fullpath);
-		err = spawnll(LOG_NOTICE,
+		err = spawnll(notice,
 			     PATH_MOUNT, PATH_MOUNT, "-t", fstype,
 			     what, fullpath, NULL);
 	}
diff -uNr autofs-4.1.4-orig/modules/mount_nfs.c autofs-4.1.4/modules/mount_nfs.c
--- autofs-4.1.4-orig/modules/mount_nfs.c	2005-05-08 20:05:14 +0400
+++ autofs-4.1.4/modules/mount_nfs.c	2005-05-08 20:15:42 +0400
@@ -520,14 +520,14 @@
 			debug(MODPREFIX "calling mount -t nfs " SLOPPY 
 			      " -o %s %s %s", nfsoptions, whatstr, fullpath);
 
-			err = spawnll(LOG_NOTICE,
+			err = spawnll(notice,
 				     PATH_MOUNT, PATH_MOUNT, "-t",
 				     "nfs", SLOPPYOPT "-o", nfsoptions,
 				     whatstr, fullpath, NULL);
 		} else {
 			debug(MODPREFIX "calling mount -t nfs %s %s",
 			      whatstr, fullpath);
-			err = spawnll(LOG_NOTICE,
+			err = spawnll(notice,
 				     PATH_MOUNT, PATH_MOUNT, "-t",
 				     "nfs", whatstr, fullpath, NULL);
 		}
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin