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

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