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

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