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