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

aea863
autofs-5.1.4 - use flags for startup boolean options
aea863
aea863
From: Ian Kent <raven@themaw.net>
aea863
aea863
The daemon uses a number of boolean flags each stored in unsigned int
aea863
variables. But a single bit flag is sufficient storage for most of
aea863
these flags.
aea863
aea863
So use bit flags for these where possible.
aea863
aea863
Signed-off-by: Ian Kent <raven@themaw.net>
aea863
---
aea863
 CHANGELOG           |    1 +
aea863
 daemon/automount.c  |   45 ++++++++++++++++++++++-----------------------
aea863
 include/automount.h |    6 ++++++
aea863
 lib/master.c        |    4 ++--
aea863
 4 files changed, 31 insertions(+), 25 deletions(-)
aea863
aea863
--- autofs-5.1.4.orig/CHANGELOG
aea863
+++ autofs-5.1.4/CHANGELOG
aea863
@@ -41,6 +41,7 @@ xx/xx/2018 autofs-5.1.5
aea863
 - remove autofs4 module load code.
aea863
 - add NULL check in prepare_attempt_prefix().
aea863
 - update build info with systemd.
aea863
+- use flags for startup boolean options.
aea863
 
aea863
 19/12/2017 autofs-5.1.4
aea863
 - fix spec file url.
aea863
--- autofs-5.1.4.orig/daemon/automount.c
aea863
+++ autofs-5.1.4/daemon/automount.c
aea863
@@ -1195,7 +1195,7 @@ static int handle_packet(struct autofs_p
aea863
 	return -1;
aea863
 }
aea863
 
aea863
-static void become_daemon(unsigned foreground, unsigned daemon_check)
aea863
+static void become_daemon(unsigned int flags)
aea863
 {
aea863
 	FILE *pidfp;
aea863
 	char buf[MAX_ERR_BUF];
aea863
@@ -1210,8 +1210,8 @@ static void become_daemon(unsigned foreg
aea863
 	}
aea863
 
aea863
 	/* Detach from foreground process */
aea863
-	if (foreground) {
aea863
-		if (daemon_check && !aquire_flag_file()) {
aea863
+	if (flags & DAEMON_FLAGS_FOREGROUND) {
aea863
+		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
aea863
 			fprintf(stderr, "%s: program is already running.\n",
aea863
 				program);
aea863
 			exit(1);
aea863
@@ -1238,7 +1238,7 @@ static void become_daemon(unsigned foreg
aea863
 		}
aea863
 		close(start_pipefd[0]);
aea863
 
aea863
-		if (daemon_check && !aquire_flag_file()) {
aea863
+		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
aea863
 			fprintf(stderr, "%s: program is already running.\n",
aea863
 				program);
aea863
 			/* Return success if already running */
aea863
@@ -2158,8 +2158,8 @@ int main(int argc, char *argv[])
aea863
 {
aea863
 	int res, opt, status;
aea863
 	int logpri = -1;
aea863
-	unsigned ghost, logging, daemon_check;
aea863
-	unsigned dumpmaps, foreground, have_global_options;
aea863
+	unsigned int flags;
aea863
+	unsigned int logging;
aea863
 	unsigned master_read;
aea863
 	int master_wait;
aea863
 	time_t timeout;
aea863
@@ -2202,17 +2202,15 @@ int main(int argc, char *argv[])
aea863
 
aea863
 	nfs_mount_uses_string_options = check_nfs_mount_version(&vers, &check);
aea863
 
aea863
+	flags = defaults_get_browse_mode() ? DAEMON_FLAGS_GHOST : 0;
aea863
+	flags |= DAEMON_FLAGS_CHECK_DAEMON;
aea863
+
aea863
 	kpkt_len = get_kpkt_len();
aea863
 	master_wait = defaults_get_master_wait();
aea863
 	timeout = defaults_get_timeout();
aea863
-	ghost = defaults_get_browse_mode();
aea863
 	logging = defaults_get_logging();
aea863
 	global_selection_options = 0;
aea863
 	global_options = NULL;
aea863
-	have_global_options = 0;
aea863
-	foreground = 0;
aea863
-	dumpmaps = 0;
aea863
-	daemon_check = 1;
aea863
 
aea863
 	remove_empty_args(argv, &argc);
aea863
 
aea863
@@ -2244,7 +2242,7 @@ int main(int argc, char *argv[])
aea863
 			break;
aea863
 
aea863
 		case 'f':
aea863
-			foreground = 1;
aea863
+			flags |= DAEMON_FLAGS_FOREGROUND;
aea863
 			break;
aea863
 
aea863
 		case 'V':
aea863
@@ -2260,7 +2258,7 @@ int main(int argc, char *argv[])
aea863
 			break;
aea863
 
aea863
 		case 'm':
aea863
-			dumpmaps = 1;
aea863
+			flags |= DAEMON_FLAGS_DUMP_MAPS;
aea863
 			break;
aea863
 
aea863
 		case 'M':
aea863
@@ -2268,9 +2266,9 @@ int main(int argc, char *argv[])
aea863
 			break;
aea863
 
aea863
 		case 'O':
aea863
-			if (!have_global_options) {
aea863
+			if (!(flags & DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS)) {
aea863
 				global_options = strdup(optarg);
aea863
-				have_global_options = 1;
aea863
+				flags |= DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS;
aea863
 				break;
aea863
 			}
aea863
 			printf("%s: global options already specified.\n",
aea863
@@ -2295,7 +2293,7 @@ int main(int argc, char *argv[])
aea863
 			break;
aea863
 
aea863
 		case 'C':
aea863
-			daemon_check = 0;
aea863
+			flags &= ~DAEMON_FLAGS_CHECK_DAEMON;
aea863
 			break;
aea863
 
aea863
 		case 'F':
aea863
@@ -2346,7 +2344,8 @@ int main(int argc, char *argv[])
aea863
 	}
aea863
 
aea863
 	/* Don't need the kernel module just to look at the configured maps */
aea863
-	if (!dumpmaps && (!query_kproto_ver() || get_kver_major() < 5)) {
aea863
+	if (!(flags & DAEMON_FLAGS_DUMP_MAPS) &&
aea863
+	   (!query_kproto_ver() || get_kver_major() < 5)) {
aea863
 		fprintf(stderr,
aea863
 			"%s: test mount forbidden or "
aea863
 			"incorrect kernel protocol version, "
aea863
@@ -2377,7 +2376,7 @@ int main(int argc, char *argv[])
aea863
 	/* Get processor information for predefined escapes */
aea863
 	macro_init();
aea863
 
aea863
-	if (dumpmaps) {
aea863
+	if (flags & DAEMON_FLAGS_DUMP_MAPS) {
aea863
 		struct master_mapent *entry;
aea863
 		struct list_head *head, *p;
aea863
 		struct mapent_cache *nc;
aea863
@@ -2395,9 +2394,9 @@ int main(int argc, char *argv[])
aea863
 		}
aea863
 
aea863
 		if (master)
aea863
-			master_list = master_new(NULL, timeout, ghost);
aea863
+			master_list = master_new(NULL, timeout, flags);
aea863
 		else
aea863
-			master_list = master_new(master, timeout, ghost);
aea863
+			master_list = master_new(master, timeout, flags);
aea863
 		if (!master_list) {
aea863
 			printf("%s: can't create master map", program);
aea863
 			macro_free_global_table();
aea863
@@ -2443,9 +2442,9 @@ int main(int argc, char *argv[])
aea863
 	}
aea863
 
aea863
 	if (argc == 0)
aea863
-		master_list = master_new(NULL, timeout, ghost);
aea863
+		master_list = master_new(NULL, timeout, flags);
aea863
 	else
aea863
-		master_list = master_new(argv[0], timeout, ghost);
aea863
+		master_list = master_new(argv[0], timeout, flags);
aea863
 
aea863
 	if (!master_list) {
aea863
 		printf("%s: can't create master map %s", program, argv[0]);
aea863
@@ -2453,7 +2452,7 @@ int main(int argc, char *argv[])
aea863
 		exit(1);
aea863
 	}
aea863
 
aea863
-	become_daemon(foreground, daemon_check);
aea863
+	become_daemon(flags);
aea863
 
aea863
 	if (pthread_attr_init(&th_attr)) {
aea863
 		logerr("%s: failed to init thread attribute struct!",
aea863
--- autofs-5.1.4.orig/include/automount.h
aea863
+++ autofs-5.1.4/include/automount.h
aea863
@@ -66,6 +66,12 @@
aea863
 #define SLOPPY
aea863
 #endif
aea863
 
aea863
+#define DAEMON_FLAGS_FOREGROUND			0x0001
aea863
+#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS	0x0004
aea863
+#define DAEMON_FLAGS_GHOST			0x0008
aea863
+#define DAEMON_FLAGS_CHECK_DAEMON		0x0010
aea863
+#define DAEMON_FLAGS_DUMP_MAPS			0x0020
aea863
+
aea863
 #define AUTOFS_SUPER_MAGIC 0x00000187L
aea863
 #define SMB_SUPER_MAGIC    0x0000517BL
aea863
 #define CIFS_MAGIC_NUMBER  0xFF534D42L
aea863
--- autofs-5.1.4.orig/lib/master.c
aea863
+++ autofs-5.1.4/lib/master.c
aea863
@@ -922,7 +922,7 @@ void master_free_mapent(struct master_ma
aea863
 	return;
aea863
 }
aea863
 
aea863
-struct master *master_new(const char *name, unsigned int timeout, unsigned int ghost)
aea863
+struct master *master_new(const char *name, unsigned int timeout, unsigned int flags)
aea863
 {
aea863
 	struct master *master;
aea863
 	char *tmp;
aea863
@@ -948,7 +948,7 @@ struct master *master_new(const char *na
aea863
 	master->depth = 0;
aea863
 	master->reading = 0;
aea863
 	master->read_fail = 0;
aea863
-	master->default_ghost = ghost;
aea863
+	master->default_ghost = flags & DAEMON_FLAGS_GHOST;
aea863
 	master->default_timeout = timeout;
aea863
 	master->default_logging = defaults_get_logging();
aea863
 	master->logopt = master->default_logging;