Blame SOURCES/autofs-5.1.4-use-flags-for-startup-boolean-options.patch

306fa1
autofs-5.1.4 - use flags for startup boolean options
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
The daemon uses a number of boolean flags each stored in unsigned int
306fa1
variables. But a single bit flag is sufficient storage for most of
306fa1
these flags.
306fa1
306fa1
So use bit flags for these where possible.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG           |    1 +
306fa1
 daemon/automount.c  |   45 ++++++++++++++++++++++-----------------------
306fa1
 include/automount.h |    6 ++++++
306fa1
 lib/master.c        |    4 ++--
306fa1
 4 files changed, 31 insertions(+), 25 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -313,6 +313,7 @@
306fa1
 - fix incorrect locking in sss lookup.
306fa1
 - add NULL check in prepare_attempt_prefix().
306fa1
 - update build info with systemd.
306fa1
+- use flags for startup boolean options.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/daemon/automount.c
306fa1
+++ autofs-5.0.7/daemon/automount.c
306fa1
@@ -1197,7 +1197,7 @@ static int handle_packet(struct autofs_p
306fa1
 	return -1;
306fa1
 }
306fa1
 
306fa1
-static void become_daemon(unsigned foreground, unsigned daemon_check)
306fa1
+static void become_daemon(unsigned int flags)
306fa1
 {
306fa1
 	FILE *pidfp;
306fa1
 	char buf[MAX_ERR_BUF];
306fa1
@@ -1212,8 +1212,8 @@ static void become_daemon(unsigned foreg
306fa1
 	}
306fa1
 
306fa1
 	/* Detach from foreground process */
306fa1
-	if (foreground) {
306fa1
-		if (daemon_check && !aquire_flag_file()) {
306fa1
+	if (flags & DAEMON_FLAGS_FOREGROUND) {
306fa1
+		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
306fa1
 			fprintf(stderr, "%s: program is already running.\n",
306fa1
 				program);
306fa1
 			exit(1);
306fa1
@@ -1240,7 +1240,7 @@ static void become_daemon(unsigned foreg
306fa1
 		}
306fa1
 		close(start_pipefd[0]);
306fa1
 
306fa1
-		if (daemon_check && !aquire_flag_file()) {
306fa1
+		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
306fa1
 			fprintf(stderr, "%s: program is already running.\n",
306fa1
 				program);
306fa1
 			/* Return success if already running */
306fa1
@@ -2159,8 +2159,8 @@ int main(int argc, char *argv[])
306fa1
 {
306fa1
 	int res, opt, status;
306fa1
 	int logpri = -1;
306fa1
-	unsigned ghost, logging, daemon_check;
306fa1
-	unsigned dumpmaps, foreground, have_global_options;
306fa1
+	unsigned int flags;
306fa1
+	unsigned int logging;
306fa1
 	unsigned master_read;
306fa1
 	int master_wait;
306fa1
 	time_t timeout;
306fa1
@@ -2203,17 +2203,15 @@ int main(int argc, char *argv[])
306fa1
 
306fa1
 	nfs_mount_uses_string_options = check_nfs_mount_version(&vers, &check);
306fa1
 
306fa1
+	flags = defaults_get_browse_mode() ? DAEMON_FLAGS_GHOST : 0;
306fa1
+	flags |= DAEMON_FLAGS_CHECK_DAEMON;
306fa1
+
306fa1
 	kpkt_len = get_kpkt_len();
306fa1
 	master_wait = defaults_get_master_wait();
306fa1
 	timeout = defaults_get_timeout();
306fa1
-	ghost = defaults_get_browse_mode();
306fa1
 	logging = defaults_get_logging();
306fa1
 	global_selection_options = 0;
306fa1
 	global_options = NULL;
306fa1
-	have_global_options = 0;
306fa1
-	foreground = 0;
306fa1
-	dumpmaps = 0;
306fa1
-	daemon_check = 1;
306fa1
 
306fa1
 	remove_empty_args(argv, &argc);
306fa1
 
306fa1
@@ -2245,7 +2243,7 @@ int main(int argc, char *argv[])
306fa1
 			break;
306fa1
 
306fa1
 		case 'f':
306fa1
-			foreground = 1;
306fa1
+			flags |= DAEMON_FLAGS_FOREGROUND;
306fa1
 			break;
306fa1
 
306fa1
 		case 'V':
306fa1
@@ -2261,7 +2259,7 @@ int main(int argc, char *argv[])
306fa1
 			break;
306fa1
 
306fa1
 		case 'm':
306fa1
-			dumpmaps = 1;
306fa1
+			flags |= DAEMON_FLAGS_DUMP_MAPS;
306fa1
 			break;
306fa1
 
306fa1
 		case 'M':
306fa1
@@ -2269,9 +2267,9 @@ int main(int argc, char *argv[])
306fa1
 			break;
306fa1
 
306fa1
 		case 'O':
306fa1
-			if (!have_global_options) {
306fa1
+			if (!(flags & DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS)) {
306fa1
 				global_options = strdup(optarg);
306fa1
-				have_global_options = 1;
306fa1
+				flags |= DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS;
306fa1
 				break;
306fa1
 			}
306fa1
 			printf("%s: global options already specified.\n",
306fa1
@@ -2296,7 +2294,7 @@ int main(int argc, char *argv[])
306fa1
 			break;
306fa1
 
306fa1
 		case 'C':
306fa1
-			daemon_check = 0;
306fa1
+			flags &= ~DAEMON_FLAGS_CHECK_DAEMON;
306fa1
 			break;
306fa1
 
306fa1
 		case 'F':
306fa1
@@ -2355,7 +2353,8 @@ int main(int argc, char *argv[])
306fa1
 #endif
306fa1
 
306fa1
 	/* Don't need the kernel module just to look at the configured maps */
306fa1
-	if (!dumpmaps && (!query_kproto_ver() || get_kver_major() < 5)) {
306fa1
+	if (!(flags & DAEMON_FLAGS_DUMP_MAPS) &&
306fa1
+	   (!query_kproto_ver() || get_kver_major() < 5)) {
306fa1
 		fprintf(stderr,
306fa1
 			"%s: test mount forbidden or "
306fa1
 			"incorrect kernel protocol version, "
306fa1
@@ -2386,7 +2385,7 @@ int main(int argc, char *argv[])
306fa1
 	/* Get processor information for predefined escapes */
306fa1
 	macro_init();
306fa1
 
306fa1
-	if (dumpmaps) {
306fa1
+	if (flags & DAEMON_FLAGS_DUMP_MAPS) {
306fa1
 		struct master_mapent *entry;
306fa1
 		struct list_head *head, *p;
306fa1
 		struct mapent_cache *nc;
306fa1
@@ -2404,9 +2403,9 @@ int main(int argc, char *argv[])
306fa1
 		}
306fa1
 
306fa1
 		if (master)
306fa1
-			master_list = master_new(NULL, timeout, ghost);
306fa1
+			master_list = master_new(NULL, timeout, flags);
306fa1
 		else
306fa1
-			master_list = master_new(master, timeout, ghost);
306fa1
+			master_list = master_new(master, timeout, flags);
306fa1
 		if (!master_list) {
306fa1
 			printf("%s: can't create master map", program);
306fa1
 			macro_free_global_table();
306fa1
@@ -2452,9 +2451,9 @@ int main(int argc, char *argv[])
306fa1
 	}
306fa1
 
306fa1
 	if (argc == 0)
306fa1
-		master_list = master_new(NULL, timeout, ghost);
306fa1
+		master_list = master_new(NULL, timeout, flags);
306fa1
 	else
306fa1
-		master_list = master_new(argv[0], timeout, ghost);
306fa1
+		master_list = master_new(argv[0], timeout, flags);
306fa1
 
306fa1
 	if (!master_list) {
306fa1
 		printf("%s: can't create master map %s", program, argv[0]);
306fa1
@@ -2462,7 +2461,7 @@ int main(int argc, char *argv[])
306fa1
 		exit(1);
306fa1
 	}
306fa1
 
306fa1
-	become_daemon(foreground, daemon_check);
306fa1
+	become_daemon(flags);
306fa1
 
306fa1
 	if (pthread_attr_init(&th_attr)) {
306fa1
 		logerr("%s: failed to init thread attribute struct!",
306fa1
--- autofs-5.0.7.orig/include/automount.h
306fa1
+++ autofs-5.0.7/include/automount.h
306fa1
@@ -73,6 +73,12 @@ int load_autofs4_module(void);
306fa1
 #define SLOPPY
306fa1
 #endif
306fa1
 
306fa1
+#define DAEMON_FLAGS_FOREGROUND			0x0001
306fa1
+#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS	0x0004
306fa1
+#define DAEMON_FLAGS_GHOST			0x0008
306fa1
+#define DAEMON_FLAGS_CHECK_DAEMON		0x0010
306fa1
+#define DAEMON_FLAGS_DUMP_MAPS			0x0020
306fa1
+
306fa1
 #define AUTOFS_SUPER_MAGIC 0x00000187L
306fa1
 #define SMB_SUPER_MAGIC    0x0000517BL
306fa1
 #define CIFS_MAGIC_NUMBER  0xFF534D42L
306fa1
--- autofs-5.0.7.orig/lib/master.c
306fa1
+++ autofs-5.0.7/lib/master.c
306fa1
@@ -921,7 +921,7 @@ void master_free_mapent(struct master_ma
306fa1
 	return;
306fa1
 }
306fa1
 
306fa1
-struct master *master_new(const char *name, unsigned int timeout, unsigned int ghost)
306fa1
+struct master *master_new(const char *name, unsigned int timeout, unsigned int flags)
306fa1
 {
306fa1
 	struct master *master;
306fa1
 	char *tmp;
306fa1
@@ -947,7 +947,7 @@ struct master *master_new(const char *na
306fa1
 	master->depth = 0;
306fa1
 	master->reading = 0;
306fa1
 	master->read_fail = 0;
306fa1
-	master->default_ghost = ghost;
306fa1
+	master->default_ghost = flags & DAEMON_FLAGS_GHOST;
306fa1
 	master->default_timeout = timeout;
306fa1
 	master->default_logging = defaults_get_logging();
306fa1
 	master->logopt = master->default_logging;