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

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