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

138 lines
4.5 KiB
Diff

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