autofs-5.0.9 - add master read wait option

From: Ian Kent <raven@themaw.net>

Add command line and configuration options to set the amount of time to
wait for the master map to become available at program start.
---
 CHANGELOG                      |    1 +
 daemon/automount.c             |   12 +++++++++++-
 include/defaults.h             |    2 ++
 lib/defaults.c                 |   13 +++++++++++++
 man/auto.master.5.in           |    5 +++++
 man/automount.8                |    4 ++++
 redhat/autofs.sysconfig.in     |    7 +++++++
 samples/autofs.conf.default.in |    7 +++++++
 8 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG b/CHANGELOG
index a995dda..48c13f5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@
 - check for non existent negative entries in lookup_ghost().
 - fix reset flex scan buffer on init.
 - wait for master map available at start.
+- add master read wait option.
 
 28/03/2014 autofs-5.0.9
 =======================
diff --git a/daemon/automount.c b/daemon/automount.c
index 3c76c6b..03b1b3d 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -1749,6 +1749,9 @@ static void usage(void)
 		"	-C --dont-check-daemon\n"
 		"			don't check if daemon is already running\n"
 		"	-F --force	forceably clean up known automounts at start\n"
+		"	-M --master-wait n\n"
+		"			maximum time to wait for the master map to\n"
+		"			become available at start up\n"
 		"	-V --version	print version, build config and exit\n"
 		, program);
 }
@@ -1963,10 +1966,11 @@ int main(int argc, char *argv[])
 	unsigned ghost, logging, daemon_check;
 	unsigned dumpmaps, foreground, have_global_options;
 	unsigned master_read;
+	int master_wait;
 	time_t timeout;
 	time_t age = time(NULL);
 	struct rlimit rlim;
-	const char *options = "+hp:t:vmdD:fVrO:l:n:CF";
+	const char *options = "+hp:t:vmdD:fVrO:l:n:CFM";
 	static const struct option long_options[] = {
 		{"help", 0, 0, 'h'},
 		{"pid-file", 1, 0, 'p'},
@@ -1983,6 +1987,7 @@ int main(int argc, char *argv[])
 		{"set-log-priority", 1, 0, 'l'},
 		{"dont-check-daemon", 0, 0, 'C'},
 		{"force", 0, 0, 'F'},
+		{"master-wait", 1, 0, 'M'},
 		{0, 0, 0, 0}
 	};
 
@@ -2003,6 +2008,7 @@ int main(int argc, char *argv[])
 	nfs_mount_uses_string_options = check_nfs_mount_version(&vers, &check);
 
 	kpkt_len = get_kpkt_len();
+	master_wait = defaults_get_master_wait();
 	timeout = defaults_get_timeout();
 	ghost = defaults_get_browse_mode();
 	logging = defaults_get_logging();
@@ -2062,6 +2068,10 @@ int main(int argc, char *argv[])
 			dumpmaps = 1;
 			break;
 
+		case 'M':
+			master_wait = getnumopt(optarg, opt);
+			break;
+
 		case 'O':
 			if (!have_global_options) {
 				global_options = strdup(optarg);
diff --git a/include/defaults.h b/include/defaults.h
index 871e14b..1181d25 100644
--- a/include/defaults.h
+++ b/include/defaults.h
@@ -23,6 +23,7 @@
 #define DEFAULT_MASTER_MAP_NAME	"auto.master"
 
 #define DEFAULT_TIMEOUT			600
+#define DEFAULT_MASTER_WAIT		-1
 #define DEFAULT_NEGATIVE_TIMEOUT	60
 #define DEFAULT_MOUNT_WAIT		-1
 #define DEFAULT_UMOUNT_WAIT		12
@@ -59,6 +60,7 @@ unsigned int defaults_read_config(unsigned int);
 const char *defaults_get_master_map(void);
 int defaults_master_set(void);
 unsigned int defaults_get_timeout(void);
+int defaults_get_master_wait(void);
 unsigned int defaults_get_negative_timeout(void);
 unsigned int defaults_get_browse_mode(void);
 unsigned int defaults_get_logging(void);
diff --git a/lib/defaults.c b/lib/defaults.c
index 7c65387..41945f5 100644
--- a/lib/defaults.c
+++ b/lib/defaults.c
@@ -32,6 +32,7 @@
 #define ENV_NAME_MASTER_MAP		"MASTER_MAP_NAME"
 
 #define ENV_NAME_TIMEOUT		"TIMEOUT"
+#define ENV_NAME_MASTER_WAIT		"MASTER_WAIT"
 #define ENV_NAME_NEGATIVE_TIMEOUT	"NEGATIVE_TIMEOUT"
 #define ENV_NAME_BROWSE_MODE		"BROWSE_MODE"
 #define ENV_NAME_LOGGING		"LOGGING"
@@ -516,6 +517,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
 
 		if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
+		    check_set_config_value(key, ENV_NAME_MASTER_WAIT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_NEGATIVE_TIMEOUT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
@@ -583,6 +585,17 @@ unsigned int defaults_get_timeout(void)
 	return (unsigned int) timeout;
 }
 
+int defaults_get_master_wait(void)
+{
+	long wait;
+
+	wait = get_env_number(ENV_NAME_MASTER_WAIT);
+	if (wait < 0)
+		wait = DEFAULT_MASTER_WAIT;
+
+	return (int) wait;
+}
+
 unsigned int defaults_get_negative_timeout(void)
 {
 	long n_timeout;
diff --git a/man/auto.master.5.in b/man/auto.master.5.in
index 1095406..08ea1dc 100644
--- a/man/auto.master.5.in
+++ b/man/auto.master.5.in
@@ -220,6 +220,11 @@ default is 10 minutes, but the default installed configuration
 overrides this and sets the timeout to 5 minutes to be consistent
 with earlier autofs releases.
 .TP
+.B MASTER_WAIT
+sets the default maximum time to wait for the master map to become
+available if it cannot be read at program start (program default -1,
+wait forever).
+.TP
 .B NEGATIVE_TIMEOUT
 Set the default timeout for caching failed key lookups (program default
 60). If the equivalent command line option is given it will override this
diff --git a/man/automount.8 b/man/automount.8
index 79e53f0..4f2f58b 100644
--- a/man/automount.8
+++ b/man/automount.8
@@ -37,6 +37,10 @@ The internal program default is 10 minutes, but the default
 installed configuration overrides this and sets the timeout
 to 5 minutes to be consistent with earlier autofs releases.
 .TP
+.I "\-M <seconds>, \-\-master-wait <seconds>"
+Set the maximum time to wait for the master map to become available
+if it cannot be read at program start.
+.TP
 .I "\-n <seconds>, \-\-negative\-timeout <seconds>"
 Set the default timeout for caching failed key lookups. The default is 60 seconds.
 .TP
diff --git a/redhat/autofs.sysconfig.in b/redhat/autofs.sysconfig.in
index 9d8d704..1902ade 100644
--- a/redhat/autofs.sysconfig.in
+++ b/redhat/autofs.sysconfig.in
@@ -12,6 +12,13 @@
 #
 TIMEOUT=300
 #
+# MASTER_WAIT - set the default maximum time to wait for the
+# 		master map to become available if it cannot
+# 		be read at program start (default -1, wait
+# 		forever).
+#
+#MASTER_WAIT=-1
+#
 # NEGATIVE_TIMEOUT - set the default negative timeout for
 # 		     failed mount attempts (default 60).
 #
diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
index 695b010..5fa030a 100644
--- a/samples/autofs.conf.default.in
+++ b/samples/autofs.conf.default.in
@@ -12,6 +12,13 @@
 #
 TIMEOUT=300
 #
+# MASTER_WAIT - set the default maximum time to wait for the
+# 		master map to become available if it cannot
+# 		be read at program start (default -1, wait
+# 		forever).
+#
+#MASTER_WAIT=-1
+#
 # NEGATIVE_TIMEOUT - set the default negative timeout for
 # 		     failed mount attempts (default 60).
 #