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

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