Blame SOURCES/autofs-5.1.4-add-systemd-service-command-line-option.patch

304803
autofs-5.1.4 - add systemd service command line option
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
When run as a systemd service using the systemd notification method to
304803
synchronise startup, logging should be done to syslog so the log entry
304803
format is consistent between daemon and systemd usage.
304803
304803
So, rather than run use the forground option, add an option to tell
304803
the automounter it's being run as a systemd service and use syslog
304803
for logging when its present on the command line.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG                 |    1 +
304803
 daemon/automount.c        |   22 +++++++++++++++++++---
304803
 include/automount.h       |    1 +
304803
 man/automount.8           |    4 ++++
304803
 samples/autofs.service.in |    2 +-
304803
 5 files changed, 26 insertions(+), 4 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -315,6 +315,7 @@
304803
 - update build info with systemd.
304803
 - use flags for startup boolean options.
304803
 - move close stdio descriptors to become_daemon().
304803
+- add systemd service command line option.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/automount.c
304803
+++ autofs-5.0.7/daemon/automount.c
304803
@@ -1212,13 +1212,21 @@ static void become_daemon(unsigned int f
304803
 	}
304803
 
304803
 	/* Detach from foreground process */
304803
-	if (flags & DAEMON_FLAGS_FOREGROUND) {
304803
+	if (flags & DAEMON_FLAGS_FOREGROUND &&
304803
+	   !(flags & DAEMON_FLAGS_SYSTEMD_SERVICE)) {
304803
 		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
304803
 			fprintf(stderr, "%s: program is already running.\n",
304803
 				program);
304803
 			exit(1);
304803
 		}
304803
 		log_to_stderr();
304803
+	} else if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE) {
304803
+		if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
304803
+			fprintf(stderr, "%s: program is already running.\n",
304803
+				program);
304803
+			exit(1);
304803
+		}
304803
+		open_log();
304803
 	} else {
304803
 		int nullfd;
304803
 
304803
@@ -1923,6 +1931,8 @@ static void usage(void)
304803
 		"	-v --verbose	be verbose\n"
304803
 		"	-d --debug	log debuging info\n"
304803
 		"	-D --define	define global macro variable\n"
304803
+		"	-S --systemd-service\n"
304803
+		"			run automounter as a systemd service\n"
304803
 		"	-f --foreground do not fork into background\n"
304803
 		"	-r --random-multimount-selection\n"
304803
 		"			use ramdom replicated server selection\n"
304803
@@ -2191,7 +2201,7 @@ int main(int argc, char *argv[])
304803
 	time_t timeout;
304803
 	time_t age = time(NULL);
304803
 	struct rlimit rlim;
304803
-	const char *options = "+hp:t:vmdD:fVrO:l:n:CFM";
304803
+	const char *options = "+hp:t:vmdD:SfVrO:l:n:CFM";
304803
 	static const struct option long_options[] = {
304803
 		{"help", 0, 0, 'h'},
304803
 		{"pid-file", 1, 0, 'p'},
304803
@@ -2199,6 +2209,7 @@ int main(int argc, char *argv[])
304803
 		{"verbose", 0, 0, 'v'},
304803
 		{"debug", 0, 0, 'd'},
304803
 		{"define", 1, 0, 'D'},
304803
+		{"systemd-service", 0, 0, 'S'},
304803
 		{"foreground", 0, 0, 'f'},
304803
 		{"random-multimount-selection", 0, 0, 'r'},
304803
 		{"negative-timeout", 1, 0, 'n'},
304803
@@ -2267,6 +2278,10 @@ int main(int argc, char *argv[])
304803
 			macro_parse_globalvar(optarg);
304803
 			break;
304803
 
304803
+		case 'S':
304803
+			flags |= DAEMON_FLAGS_SYSTEMD_SERVICE;
304803
+			break;
304803
+
304803
 		case 'f':
304803
 			flags |= DAEMON_FLAGS_FOREGROUND;
304803
 			break;
304803
@@ -2660,7 +2675,8 @@ int main(int argc, char *argv[])
304803
 	}
304803
 
304803
 #ifdef WITH_SYSTEMD
304803
-	sd_notify(1, "READY=1");
304803
+	if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE)
304803
+		sd_notify(1, "READY=1");
304803
 #endif
304803
 
304803
 	state_mach_thid = pthread_self();
304803
--- autofs-5.0.7.orig/include/automount.h
304803
+++ autofs-5.0.7/include/automount.h
304803
@@ -74,6 +74,7 @@ int load_autofs4_module(void);
304803
 #endif
304803
 
304803
 #define DAEMON_FLAGS_FOREGROUND			0x0001
304803
+#define DAEMON_FLAGS_SYSTEMD_SERVICE		0x0002
304803
 #define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS	0x0004
304803
 #define DAEMON_FLAGS_GHOST			0x0008
304803
 #define DAEMON_FLAGS_CHECK_DAEMON		0x0010
304803
--- autofs-5.0.7.orig/man/automount.8
304803
+++ autofs-5.0.7/man/automount.8
304803
@@ -57,6 +57,10 @@ Define a global macro substitution varia
304803
 are over-ridden macro definitions of the same name specified in
304803
 mount entries.
304803
 .TP
304803
+.I \-S, \-\-systemd-service
304803
+Used when running the automounter as a systemd service to ensure log entry
304803
+format is consistent with the log entry format when running as a daemon.
304803
+.TP
304803
 .I "\-f, \-\-foreground"
304803
 Run the daemon in the foreground and log to stderr instead of syslog."
304803
 .TP
304803
--- autofs-5.0.7.orig/samples/autofs.service.in
304803
+++ autofs-5.0.7/samples/autofs.service.in
304803
@@ -6,7 +6,7 @@ Wants=network-online.target rpc-statd.se
304803
 [Service]
304803
 Type=notify
304803
 EnvironmentFile=-@@autofsconfdir@@/autofs
304803
-ExecStart=@@sbindir@@/automount $OPTIONS --foreground --dont-check-daemon
304803
+ExecStart=@@sbindir@@/automount $OPTIONS --systemd-service --dont-check-daemon
304803
 ExecReload=/usr/bin/kill -HUP $MAINPID
304803
 KillMode=process
304803
 TimeoutSec=180