From 1b7f3cc431ca53962506e6d96e7a4938c4388416 Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Fri, 1 Jul 2022 13:29:16 +0200 Subject: [PATCH] build: add FENCETMPDIR for state files --- Makefile.am | 3 ++- configure.ac | 30 ++++++++++++++++++++++++++++++ fence-agents.spec.in | 16 +++++++++++++++- m4/PKG_CHECK_VAR.m4 | 24 ++++++++++++++++++++++++ make/fencebuild.mk | 1 + systemd/Makefile.am | 24 ++++++++++++++++++++++++ systemd/fence-agents.conf.in | 1 + 7 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 m4/PKG_CHECK_VAR.m4 create mode 100644 systemd/Makefile.am create mode 100644 systemd/fence-agents.conf.in diff --git a/Makefile.am b/Makefile.am index c1091b93a..1d115e5aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ TARFILES = $(PACKAGE_NAME)-$(VERSION).tar.bz2 \ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = lib agents doc +SUBDIRS = lib agents doc systemd .PHONY: $(SUBDIRS) @@ -34,6 +34,7 @@ doc: agents install-exec-local: $(INSTALL) -d $(DESTDIR)/$(LOGDIR) $(INSTALL) -d $(DESTDIR)/$(CLUSTERVARRUN) + $(INSTALL) -d -m 1755 $(DESTDIR)$(FENCETMPDIR) uninstall-local: rmdir $(DESTDIR)/$(LOGDIR) || :; diff --git a/configure.ac b/configure.ac index 1bad8e3b0..d7afb8dbe 100644 --- a/configure.ac +++ b/configure.ac @@ -135,10 +135,38 @@ AC_ARG_WITH([agents], [ AGENTS_LIST="$withval" ], [ AGENTS_LIST="all" ]) +FENCETMPDIR=${localstatedir}/run/fence-agents +AC_ARG_WITH(fencetmpdir, + [ --with-fencetmpdir=DIR directory for fence agents state files [${FENCETMPDIR}]], + [ FENCETMPDIR="$withval" ]) + +# Expand $prefix +eval FENCETMPDIR="`eval echo ${FENCETMPDIR}`" +AC_DEFINE_UNQUOTED(FENCETMPDIR,"$FENCETMPDIR", Where Fence agents keep state files) +AC_SUBST(FENCETMPDIR) + + if test "x$AGENTS_LIST" = x; then AC_ERROR([No agents selected]) fi +# PKG_CHECK_MODULES will fail if systemd is not found by default, so make sure +# we set the proper vars and deal with it +PKG_CHECK_MODULES([systemd], [systemd], [HAS_SYSTEMD=yes], [HAS_SYSTEMD=no]) +if test "x$HAS_SYSTEMD" == "xyes"; then + PKG_CHECK_VAR([SYSTEMD_TMPFILES_DIR], [systemd], [tmpfilesdir]) + if test "x$SYSTEMD_TMPFILES_DIR" == "x"; then + AC_MSG_ERROR([Unable to detect systemd tmpfiles directory automatically]) + fi + + # sanitize systed vars when using non standard prefix + if test "$prefix" != "/usr"; then + SYSTEMD_TMPFILES_DIR="$prefix/$SYSTEMD_TMPFILES_DIR" + AC_SUBST([SYSTEMD_TMPFILES_DIR]) + fi +fi +AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$HAS_SYSTEMD" == xyes ]) + FENCE_KDUMP=0 if echo "$AGENTS_LIST" | grep -q -E "all|kdump"; then case "$host_os" in @@ -552,6 +580,8 @@ AC_CONFIG_FILES([Makefile agents/Makefile lib/Makefile doc/Makefile + systemd/Makefile + systemd/fence-agents.conf agents/virt/Makefile agents/virt/config/Makefile agents/virt/common/Makefile diff --git a/fence-agents.spec.in b/fence-agents.spec.in index a31767e81..9bf009ff9 100644 --- a/fence-agents.spec.in +++ b/fence-agents.spec.in @@ -189,7 +189,13 @@ sed -i.orig 's|FENCE_ZVM=1|FENCE_ZVM=0|' configure.ac %endif ./autogen.sh -%{configure} --disable-libvirt-qmf-plugin +%{configure} \ +%if %{defined _tmpfilesdir} + SYSTEMD_TMPFILES_DIR=%{_tmpfilesdir} \ + --with-fencetmpdir=/run/fence-agents \ +%endif + --disable-libvirt-qmf-plugin + CFLAGS="$(echo '%{optflags}')" make %{_smp_mflags} %install @@ -277,6 +283,14 @@ This package contains support files including the Python fencing library. %{_datadir}/pkgconfig/%{name}.pc %exclude %{_sbindir}/* %exclude %{_mandir}/man8/* +%if %{defined _tmpfilesdir} +%{_tmpfilesdir}/%{name}.conf +%endif +%if %{defined _tmpfilesdir} +%dir %attr (1755, root, root) /run/%{name} +%else +%dir %attr (1755, root, root) %{_var}/run/%{name} +%endif %package all License: GPLv2+ and LGPLv2+ and ASL 2.0 diff --git a/m4/PKG_CHECK_VAR.m4 b/m4/PKG_CHECK_VAR.m4 new file mode 100644 index 000000000..2221a69eb --- /dev/null +++ b/m4/PKG_CHECK_VAR.m4 @@ -0,0 +1,24 @@ +dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, +dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +dnl ------------------------------------------- +dnl Since: 0.28 +dnl +dnl Retrieves the value of the pkg-config variable for the given module. +dnl +dnl Origin (declared license: GPLv2+ with less restrictive exception): +dnl https://cgit.freedesktop.org/pkg-config/tree/pkg.m4.in?h=pkg-config-0.29.1#n261 +dnl (AS_VAR_COPY replaced with backward-compatible equivalent and guard +dnl to prefer system-wide variant by Jan Pokorny ) + +m4_ifndef([PKG_CHECK_VAR],[ +AC_DEFUN([PKG_CHECK_VAR], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl + +_PKG_CONFIG([$1], [variable="][$3]["], [$2]) +dnl AS_VAR_COPY([$1], [pkg_cv_][$1]) +$1=AS_VAR_GET([pkg_cv_][$1]) + +AS_VAR_IF([$1], [""], [$5], [$4])dnl +])dnl PKG_CHECK_VAR +])dnl m4_ifndef diff --git a/make/fencebuild.mk b/make/fencebuild.mk index 762db62c4..9a3c6d6dd 100644 --- a/make/fencebuild.mk +++ b/make/fencebuild.mk @@ -8,6 +8,7 @@ define gen_agent_from_py -e 's#@''LOGDIR@#${LOGDIR}#g' \ -e 's#@''SBINDIR@#${sbindir}#g' \ -e 's#@''LIBEXECDIR@#${libexecdir}#g' \ + -e 's#@''FENCETMPDIR@#${FENCETMPDIR}#g' \ -e 's#@''IPMITOOL_PATH@#${IPMITOOL_PATH}#g' \ -e 's#@''OPENSTACK_PATH@#${OPENSTACK_PATH}#g' \ -e 's#@''AMTTOOL_PATH@#${AMTTOOL_PATH}#g' \ diff --git a/systemd/Makefile.am b/systemd/Makefile.am new file mode 100644 index 000000000..aa3a01679 --- /dev/null +++ b/systemd/Makefile.am @@ -0,0 +1,24 @@ +# +# Copyright (C) 2017 Oyvind Albrigtsen +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +MAINTAINERCLEANFILES = Makefile.in + +if HAVE_SYSTEMD +tmpfilesdir = $(SYSTEMD_TMPFILES_DIR) +tmpfiles_DATA = fence-agents.conf +endif diff --git a/systemd/fence-agents.conf.in b/systemd/fence-agents.conf.in new file mode 100644 index 000000000..4181287da --- /dev/null +++ b/systemd/fence-agents.conf.in @@ -0,0 +1 @@ +d @FENCETMPDIR@ 1755 root root