From 65ab84e7ff3092c92a3fcc524dad48981eee353f Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 08:03:58 +0000 Subject: Apply patch autofs-5.1.4-add-systemd-service-command-line-option.patch patch_name: autofs-5.1.4-add-systemd-service-command-line-option.patch present_in_specfile: true --- diff --git a/CHANGELOG b/CHANGELOG index 313ad36..af32a8e 100644 --- a/CHANGELOG +++ b/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. diff --git a/daemon/automount.c b/daemon/automount.c index c1360ed..4628f20 100644 --- a/daemon/automount.c +++ b/daemon/automount.c @@ -1210,13 +1210,21 @@ static void become_daemon(unsigned int flags) } /* 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(); diff --git a/include/automount.h b/include/automount.h index 848fd0b..45fde53 100644 --- a/include/automount.h +++ b/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 diff --git a/man/automount.8 b/man/automount.8 index 1e15ecd..525c460 100644 --- a/man/automount.8 +++ b/man/automount.8 @@ -57,6 +57,10 @@ Define a global macro substitution variable. Global definitions 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 diff --git a/samples/autofs.service.in b/samples/autofs.service.in index 281d31e..175a806 100644 --- a/samples/autofs.service.in +++ b/samples/autofs.service.in @@ -6,7 +6,7 @@ Wants=network-online.target rpc-statd.service rpcbind.service [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