autofs-5.0.5 - add dump maps option

From: Ondrej Valousek <webserv@s3group.cz>

Modified by Ian Kent <raven@themaw.net>
---

 CHANGELOG          |    1 
 daemon/automount.c |   52 ++++++++++++++++-----
 include/log.h      |    1 
 include/master.h   |    1 
 lib/log.c          |   14 ++++--
 lib/master.c       |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/automount.8    |    3 +
 7 files changed, 180 insertions(+), 18 deletions(-)


Index: autofs-5.0.5/CHANGELOG
===================================================================
--- autofs-5.0.5.orig/CHANGELOG
+++ autofs-5.0.5/CHANGELOG
@@ -54,7 +54,6 @@
 - fix direct map not updating on reread.
 - add external bind method.
 - fix add simple bind auth.
-- add option to dump configured automount maps.
 
 03/09/2009 autofs-5.0.5
 -----------------------
Index: autofs-5.0.5/daemon/automount.c
===================================================================
--- autofs-5.0.5.orig/daemon/automount.c
+++ autofs-5.0.5/daemon/automount.c
@@ -1664,7 +1664,6 @@ static void usage(void)
 		"	-f --foreground do not fork into background\n"
 		"	-r --random-multimount-selection\n"
 		"			use ramdom replicated server selection\n"
-		"	-m --dumpmaps	dump automounter maps and exit\n"
 		"	-n --negative-timeout n\n"
 		"			set the timeout for failed key lookups.\n"
 		"	-O --global-options\n"
@@ -1814,7 +1813,7 @@ int main(int argc, char *argv[])
 	int res, opt, status;
 	int logpri = -1;
 	unsigned ghost, logging, daemon_check;
-	unsigned dumpmaps, foreground, have_global_options;
+	unsigned foreground, have_global_options;
 	time_t timeout;
 	time_t age = time(NULL);
 	struct rlimit rlim;
@@ -1828,7 +1827,6 @@ int main(int argc, char *argv[])
 		{"foreground", 0, 0, 'f'},
 		{"random-multimount-selection", 0, 0, 'r'},
 		{"negative-timeout", 1, 0, 'n'},
-		{"dumpmaps", 0, 0, 'm'},
 		{"global-options", 1, 0, 'O'},
 		{"version", 0, 0, 'V'},
 		{"set-log-priority", 1, 0, 'l'},
@@ -1859,11 +1857,10 @@ int main(int argc, char *argv[])
 	global_options = NULL;
 	have_global_options = 0;
 	foreground = 0;
-	dumpmaps = 0;
 	daemon_check = 1;
 
 	opterr = 0;
-	while ((opt = getopt_long(argc, argv, "+hp:t:vmdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
+	while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage();
@@ -1905,10 +1902,6 @@ int main(int argc, char *argv[])
 			global_negative_timeout = getnumopt(optarg, opt);
 			break;
 
-		case 'm':
-			dumpmaps = 1;
-			break;
-
 		case 'O':
 			if (!have_global_options) {
 				global_options = strdup(optarg);
@@ -1995,8 +1988,7 @@ int main(int argc, char *argv[])
 	}
 #endif
 
-	/* Don't need the kernel module just to look at the configured maps */
-	if (!dumpmaps && (!query_kproto_ver() || get_kver_major() < 5)) {
+	if (!query_kproto_ver() || get_kver_major() < 5) {
 		fprintf(stderr,
 			"%s: test mount forbidden or "
 			"incorrect kernel protocol version, "
@@ -2009,50 +2001,34 @@ int main(int argc, char *argv[])
 	rlim.rlim_max = MAX_OPEN_FILES;
 	res = setrlimit(RLIMIT_NOFILE, &rlim);
 	if (res)
-		printf("%s: can't increase open file limit - continuing",
-			argv[0]);
+		warn(logging,
+		     "can't increase open file limit - continuing");
 
 #if ENABLE_CORES
 	rlim.rlim_cur = RLIM_INFINITY;
 	rlim.rlim_max = RLIM_INFINITY;
 	res = setrlimit(RLIMIT_CORE, &rlim);
 	if (res)
-		printf("%s: can't increase core file limit - continuing",
-			argv[0]);
+		warn(logging,
+		     "can't increase core file limit - continuing");
 #endif
 
+	become_daemon(foreground, daemon_check);
+
 	if (argc == 0)
 		master_list = master_new(NULL, timeout, ghost);
 	else
 		master_list = master_new(argv[0], timeout, ghost);
 
 	if (!master_list) {
-		printf("%s: can't create master map %s", program, argv[0]);
+		logerr("%s: can't create master map %s",
+			program, argv[0]);
+		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
+		close(start_pipefd[1]);
+		release_flag_file();
 		exit(1);
 	}
 
-	if (dumpmaps) {
-		struct mapent_cache *nc;
-
-		open_log();
-
-		master_init_scan();
-
-		nc = cache_init_null_cache(master_list);
-		if (!nc) {
-			printf("%s: failed to init null map cache for %s",
-				master_list->name, argv[0]);
-			exit(1);
-		}
-		master_list->nc = nc;
-
-		lookup_nss_read_master(master_list, 0);
-		master_show_mounts(master_list);
-		exit(0);
-	}
-
-	become_daemon(foreground, daemon_check);
-
 	if (pthread_attr_init(&th_attr)) {
 		logerr("%s: failed to init thread attribute struct!",
 		     program);
Index: autofs-5.0.5/include/log.h
===================================================================
--- autofs-5.0.5.orig/include/log.h
+++ autofs-5.0.5/include/log.h
@@ -35,7 +35,6 @@ extern void set_log_verbose_ap(struct au
 extern void set_log_debug_ap(struct autofs_point *ap);
 extern void set_mnt_logging(unsigned global_logopt);
 
-extern void open_log(void);
 extern void log_to_syslog(void);
 extern void log_to_stderr(void);
  
Index: autofs-5.0.5/include/master.h
===================================================================
--- autofs-5.0.5.orig/include/master.h
+++ autofs-5.0.5/include/master.h
@@ -110,7 +110,6 @@ int master_submount_list_empty(struct au
 int master_notify_submount(struct autofs_point *, const char *path, enum states);
 void master_notify_state_change(struct master *, int);
 int master_mount_mounts(struct master *, time_t, int);
-int master_show_mounts(struct master *);
 extern inline unsigned int master_get_logopt(void);
 int master_list_empty(struct master *);
 int master_done(struct master *);
Index: autofs-5.0.5/lib/log.c
===================================================================
--- autofs-5.0.5.orig/lib/log.c
+++ autofs-5.0.5/lib/log.c
@@ -193,23 +193,17 @@ void logmsg(const char *msg, ...)
 	return;
 }
 
-void open_log(void)
+void log_to_syslog(void)
 {
+	char buf[MAX_ERR_BUF];
+	int nullfd;
+
 	if (!syslog_open) {
 		syslog_open = 1;
 		openlog("automount", LOG_PID, LOG_DAEMON);
 	}
 
 	logging_to_syslog = 1;
-	return;
-}
-
-void log_to_syslog(void)
-{
-	char buf[MAX_ERR_BUF];
-	int nullfd;
-
-	open_log();
 
 	/* Redirect all our file descriptors to /dev/null */
 	nullfd = open("/dev/null", O_RDWR);
Index: autofs-5.0.5/lib/master.c
===================================================================
--- autofs-5.0.5.orig/lib/master.c
+++ autofs-5.0.5/lib/master.c
@@ -30,7 +30,6 @@
 /* The root of the map entry tree */
 struct master *master_list = NULL;
 
-extern const char *global_options;
 extern long global_negative_timeout;
 
 /* Attribute to create a joinable thread */
@@ -1192,131 +1191,6 @@ int master_mount_mounts(struct master *m
 
 	return 1;
 }
-
-/* The nss source instances end up in reverse order. */
-static void list_source_instances(struct map_source *source, struct map_source *instance)
-{
-	if (!source || !instance) {
-		printf("none");
-		return;
-	}
-
-	if (instance->next)
-		list_source_instances(source, instance->next);
-
-	/*
-	 * For convienience we map nss instance type "files" to "file".
-	 * Check for that and report corrected instance type.
-	 */
-	if (strcmp(instance->type, "file"))
-		printf("%s ", instance->type);
-	else {
-		if (source->argv && *(source->argv[0]) != '/')
-			printf("files ");
-		else
-			printf("%s ", instance->type);
-	}
-
-	return;
-}
-
-int master_show_mounts(struct master *master)
-{
-	struct list_head *p, *head;
-
-	printf("\nautofs dump map information\n"
-		 "===========================\n\n");
-
-	printf("global options: ");
-	if (!global_options)
-		printf("none configured\n");
-	else {
-		printf("%s\n", global_options);
-		unsigned int append_options = defaults_get_append_options();
-		const char *append = append_options ? "will" : "will not";
-		printf("global options %s be appended to map entries\n", append);
-	}
-
-	if (list_empty(&master->mounts)) {
-		printf("no master map entries found\n\n");
-		return 1;
-	}
-
-	head = &master->mounts;
-	p = head->next;
-	while (p != head) {
-		struct map_source *source;
-		struct master_mapent *this;
-		struct autofs_point *ap;
-		time_t now = time(NULL);
-		int i;
-
-		this = list_entry(p, struct master_mapent, list);
-		p = p->next;
-
-		ap = this->ap;
-
-		printf("\nMount point: %s\n", ap->path);
-		printf("\nsource(s):\n");
-
-		/* Read the map content into the cache */
-		if (lookup_nss_read_map(ap, NULL, now))
-			lookup_prune_cache(ap, now);
-		else {
-			printf("  failed to read map\n\n");
-			continue;
-		}
-
-		if (!this->maps) {
-			printf("  no map sources found\n\n");
-			continue;
-		}
-
-		source = this->maps;
-		while (source) {
-			struct mapent *me;
-
-			if (source->type)
-				printf("\n  type: %s\n", source->type);
-			else {
-				printf("\n  instance type(s): ");
-				list_source_instances(source, source->instance);
-				printf("\n");
-			}
-
-			if (source->argc >= 1) {
-				i = 0;
-				if (source->argv[0] && *source->argv[0] != '-') {
-					printf("  map: %s\n", source->argv[0]);
-					i = 1;
-				}
-				if (source->argc > 1) {
-					printf("  arguments: ");
-					for (; i < source->argc; i++)
-						printf("%s ", source->argv[i]);
-					printf("\n");
-				}
-			}
-
-			printf("\n");
-
-			me = cache_lookup_first(source->mc);
-			if (!me)
-				printf("  no keys found in map\n");
-			else {
-				do {
-					printf("  %s | %s\n", me->key, me->mapent);
-				} while ((me = cache_lookup_next(source->mc, me)));
-			}
-
-			source = source->next;
-		}
-
-		printf("\n");
-	}
-
-	return 1;
-}
 
 int master_list_empty(struct master *master)
 {
Index: autofs-5.0.5/man/automount.8
===================================================================
--- autofs-5.0.5.orig/man/automount.8
+++ autofs-5.0.5/man/automount.8
@@ -57,9 +57,6 @@ Run the daemon in the forground and log
 Enables the use of ramdom selection when choosing a host from a
 list of replicated servers.
 .TP
-.I "\-m, \-\-dumpmaps"
-Dump configured automounter maps, then exit.
-.TP
 .I "\-O, \-\-global-options"
 Allows the specification of global mount options used for all master
 map entries. These options will either replace or be appened to options
