From 65958072f06f731385c70777776d9ce8546c310b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 28 May 2021 16:58:35 +0200 Subject: [PATCH] configure.ac: generate scripts/systemd/nut-common.in based on current config --- autogen.sh | 4 +++ configure.ac | 45 +++++++++++++++++++++++--- scripts/systemd/.gitignore | 2 ++ scripts/systemd/nut-common.tmpfiles.in | 7 ---- 4 files changed, 47 insertions(+), 11 deletions(-) delete mode 100644 scripts/systemd/nut-common.tmpfiles.in diff --git a/autogen.sh b/autogen.sh index 83367f3286..99d8a9bf96 100755 --- a/autogen.sh +++ b/autogen.sh @@ -39,6 +39,10 @@ then fi fi +if [ ! -e scripts/systemd/nut-common.tmpfiles.in ]; then + echo '# autoconf requires this file exists before generating configure script' > scripts/systemd/nut-common.tmpfiles.in +fi + # now we can safely call autoreconf echo "Calling autoreconf..." autoreconf -iv && { diff --git a/configure.ac b/configure.ac index cd61faf16d..1c2d25e2d4 100644 --- a/configure.ac +++ b/configure.ac @@ -1483,14 +1483,27 @@ if test -n "${systemdsystemunitdir}"; then esac fi +dnl Note: if (systemd-)tmpfiles tech is present, it can be useful even for +dnl daemons starting not as systemd units +AC_MSG_CHECKING([whether to install systemd tmpfiles files (${systemdtmpfilesdir})]) AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR], [Directory for systemd tmpfiles scripts (auto)]), - [systemdtmpfilesdir=${withval}]) -if test -n "${systemdsystemunitdir}"; then - case "${systemdtmpfilesdir}" in + [systemdshutdowndir=${withval}]) +case "${systemdtmpfilesdir}" in yes|auto|"") systemdtmpfilesdir=`$PKG_CONFIG --variable=tmpfilesdir systemd` - esac + ;; + no) + systemdtmpfilesdir="" + ;; + *) + systemdtmpfilesdir="${withval}" + ;; +esac +if test -n "${systemdtmpfilesdir}"; then + AC_MSG_RESULT(using ${systemdtmpfilesdir}) +else + AC_MSG_RESULT(no) fi dnl @@ -2026,6 +2039,30 @@ AC_MSG_RESULT(["${nut_enable_Werror}"]) dnl Finally restore warnings settings that the caller might have provided in CFLAGS etc NUT_POP_WARNINGS +dnl Due to possibly repetitive content, generate unique settings: +AS_IF([test -n "$systemdtmpfilesdir"], + [cat > scripts/systemd/nut-common.tmpfiles.in << EOF +# State file (e.g. upsd to driver) and pidfile location for NUT: +d @STATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @STATEPATH@/nut +EOF + AS_IF([test "$STATEPATH" != "$PIDPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @PIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @PIDPATH@/nut +EOF]) + AS_IF([test -n "$ALTPIDPATH" && test "$STATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTPIDPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @ALTPIDPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @ALTPIDPATH@/nut +EOF]) + AS_IF([test -n "$ALTSTATEPATH" && test "$STATEPATH" != "$ALTSTATEPATH" && test "$ALTSTATEPATH" != "$ALTPIDPATH" && test "$PIDPATH" != "$ALTSTATEPATH"], + [cat >> scripts/systemd/nut-common.tmpfiles.in << EOF +d @ALTSTATEPATH@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - +X @ALTSTATEPATH@/nut +EOF]) +]) + AC_OUTPUT([ clients/Makefile common/Makefile diff --git a/scripts/systemd/.gitignore b/scripts/systemd/.gitignore index 4c06f648e9..aca233407d 100644 --- a/scripts/systemd/.gitignore +++ b/scripts/systemd/.gitignore @@ -1,3 +1,5 @@ +# Note: nut-common.tmpfiles.in is also generated, by configure script +/nut-common.tmpfiles.in /nut-common.tmpfiles /nut-driver.service /nut-driver@.service diff --git a/scripts/systemd/nut-common.tmpfiles.in b/scripts/systemd/nut-common.tmpfiles.in deleted file mode 100644 index e98dfb8893..0000000000 --- a/scripts/systemd/nut-common.tmpfiles.in +++ /dev/null @@ -1,7 +0,0 @@ -# State file (e.g. upsd to driver) and pidfile location for NUT: -d @runbasedir@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @runbasedir@/nut -d @statepath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @statepath@/nut -d @pidpath@/nut 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - - -X @pidpath@/nut