From ee97c5c6334df4bfc523be375bcc3ce580be4357 Mon Sep 17 00:00:00 2001
From: Su Yue <glass.su@suse.com>
Date: Tue, 26 Nov 2024 14:23:04 +0800
Subject: [PATCH 3/5] configure.ac: add option disable/enable-sd-notify

Since commit d106ac04ab34 ("configure.ac: use LIBSYSTEMD"),
lvmlockd is not built with SD_NOTIFY by default but depending
on LIBSYSTEMD_LIBS. There are three prerequisites of
nonempty LIBSYSTEMD_LIBS:
NOTIFYDBUS_SUPPORT, SYSTEMD_JOURNAL_SUPPORT and SYSTEMD_JOURNAL_SUPPORT.

If ./configure is called with options ' --disable-systemd-journal
--disable-app-machineid --enable-lvmlockd-sanlock
--disable-notify-dbus', the lvmlockd built is without sd_notify
support which causes hang of start lvmlockd service in notify type.

This commit adds options disable-sd-notify and enable-sd-notify.
The default value is autodetected and when the lvm2 is build with
systemd then sd-notify is enabled.
If systemd/sd-daemon.h is existed, call PKG_CHECK_MODULES libsystemd.

Signed-off-by: Su Yue <glass.su@suse.com>
Modified-by: Zdenek Kabelac <zkabelac@redhat.com>
---
 configure.ac | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index acbb1f8fbcd2..fe5703bb7e06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1046,8 +1046,9 @@ SYSTEMD_MIN_VERSION=0
 NOTIFYDBUS_SUPPORT="no"
 SYSTEMD_JOURNAL_SUPPORT="no"
 APP_MACHINEID_SUPPORT="no"
+SD_NOTIFY_SUPPORT="no"
 AS_IF([test "$with_systemd" = "yes"],
-      PKG_CHECK_EXISTS(systemd >= 221, [SYSTEMD_MIN_VERSION=221 NOTIFYDBUS_SUPPORT="maybe" SYSTEMD_JOURNAL_SUPPORT="maybe"])
+      PKG_CHECK_EXISTS(systemd >= 221, [SYSTEMD_MIN_VERSION=221 NOTIFYDBUS_SUPPORT="maybe" SD_NOTIFY_SUPPORT="maybe" SYSTEMD_JOURNAL_SUPPORT="maybe"])
       PKG_CHECK_EXISTS(systemd >= 234, [SYSTEMD_MIN_VERSION=234 APP_MACHINEID_SUPPORT="maybe"]))
 
 ################################################################################
@@ -1082,6 +1083,22 @@ AC_MSG_RESULT([$APP_MACHINEID_SUPPORT])
 AS_IF([test "$APP_MACHINEID_SUPPORT" = "yes"],
       AC_DEFINE([APP_MACHINEID_SUPPORT], 1, [Define to 1 to include code that uses libsystemd machine-id apis.]))
 
+################################################################################
+dnl -- Build with sd_notify when the header file sd-daemon.h is present
+AS_IF([test "$SD_NOTIFY_SUPPORT" != "no"],
+      AC_CHECK_HEADER([systemd/sd-daemon.h], [SD_NOTIFY_SUPPORT="yes"], [SD_NOTIFY_SUPPORT="no"]))
+AC_ARG_ENABLE(sd-notify,
+	      AS_HELP_STRING([--disable-sd-notify],
+			     [disable LVM sd_notify]),
+	      AS_IF([test "$enableval" = "yes" && test "$SD_NOTIFY_SUPPORT" = "no"],
+		    AC_MSG_ERROR([--enable-sd-notify requires systemd/sd-daemon.h. (--with-systemd=$with_systemd)]))
+	      SD_NOTIFY_SUPPORT=$enableval, [])
+AC_MSG_CHECKING([whether to enable to sd_notify])
+AC_MSG_RESULT([$SD_NOTIFY_SUPPORT])
+
+AS_IF([test "$SD_NOTIFY_SUPPORT" = "yes"],
+      AC_DEFINE([SD_NOTIFY_SUPPORT], 1, [Define to 1 to include code that uses sd_notify.]))
+
 ################################################################################
 dnl -- Support override for systemd-run path if they need to (NixOS builds)
 AC_ARG_WITH(systemd-run,
@@ -1234,7 +1251,7 @@ AC_ARG_ENABLE(notify-dbus,
 	      [NOTIFYDBUS_SUPPORT=$enableval])
 
 AS_IF([test "$NOTIFYDBUS_SUPPORT" = "maybe"],
-      [AS_IF([test "$BUILD_LVMDBUSD" = "yes" || test "$BUILD_LVMLOCKD" = "yes"],
+      [AS_IF([test "$BUILD_LVMDBUSD" = "yes"],
       [NOTIFYDBUS_SUPPORT="yes"], [NOTIFYDBUS_SUPPORT="no"])])
 
 AS_IF([test "$NOTIFYDBUS_SUPPORT" = "yes"],
@@ -1247,9 +1264,9 @@ AC_MSG_RESULT([$NOTIFYDBUS_SUPPORT])
 
 ################################################################################
 dnl -- Look for libsystemd libraries if needed
-AS_IF([test "$NOTIFYDBUS_SUPPORT" = "yes" || test "$SYSTEMD_JOURNAL_SUPPORT" = "yes" || test "$APP_MACHINEID_SUPPORT" = "yes"], [
-	PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd])
-])
+AS_IF([test "$NOTIFYDBUS_SUPPORT" = "yes" || test "$SYSTEMD_JOURNAL_SUPPORT" = "yes" ||
+       test "$APP_MACHINEID_SUPPORT" = "yes" || test "$SD_NOTIFY_SUPPORT" = "yes"],
+       [PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd])])
 
 ################################################################################
 dnl -- Enable Python dbus library
@@ -1939,6 +1956,7 @@ AC_SUBST(PYTHON3)
 AC_SUBST(PYTHON3DIR)
 AC_SUBST(RT_LIBS)
 AC_SUBST(SBINDIR)
+AC_SUBST(SD_NOTIFY_SUPPORT)
 AC_SUBST(SELINUX_LIBS)
 AC_SUBST(SELINUX_PC)
 AC_SUBST(SELINUX_STATIC_LIBS)
@@ -2077,5 +2095,5 @@ AS_IF([test "$ODIRECT" != "yes"],
 AS_IF([test "$BUILD_LVMDBUSD" = "yes" && test "$NOTIFYDBUS_SUPPORT" = "no"],
       [AC_MSG_WARN([Building D-Bus support without D-Bus notifications!])])
 
-AS_IF([test "$BUILD_LVMLOCKD" = "yes" && test "$NOTIFYDBUS_SUPPORT" = "no"],
-      [AC_MSG_WARN([Building lvmlockd without D-Bus notifications may block!])])
+AS_IF([test "$BUILD_LVMLOCKD" = "yes" && test "$SD_NOTIFY_SUPPORT" = "no"],
+      [AC_MSG_WARN([Building lvmlockd without sd-notify support may block!])])
-- 
2.39.5 (Apple Git-154)

