fa1179c
From d1b1f91a7982be28acdfb580996c93aafcc76cc2 Mon Sep 17 00:00:00 2001
b5d7414
From: Pavel Zhukov <pzhukov@redhat.com>
b5d7414
Date: Thu, 7 Nov 2019 14:47:45 +0100
fa1179c
Subject: [PATCH 27/28] Add missed sd notify patch to manage dhcpd with systemd
b5d7414
b5d7414
---
b5d7414
 configure.ac     | 11 +++++++++++
b5d7414
 relay/dhcrelay.c | 12 ++++++++++++
b5d7414
 server/dhcpd.c   | 12 ++++++++++++
b5d7414
 3 files changed, 35 insertions(+)
b5d7414
b5d7414
diff --git a/configure.ac b/configure.ac
fa1179c
index 300117f..f644e71 100644
b5d7414
--- a/configure.ac
b5d7414
+++ b/configure.ac
fa1179c
@@ -1005,6 +1005,17 @@ if test x$ldap = xyes || test x$ldapcrypto = xyes || test x$ldap_gssapi = xyes;
b5d7414
     AC_SUBST(LDAP_CFLAGS, [$LDAP_CFLAGS])
b5d7414
 fi
b5d7414
 
b5d7414
+AC_ARG_WITH(systemd,
b5d7414
+        AC_HELP_STRING([--with-systemd],
b5d7414
+                       [enable sending status notifications to systemd daemon (default is no)]),
b5d7414
+        [systemd=$withval],
b5d7414
+        [systemd=no])
b5d7414
+
b5d7414
+if test x$systemd = xyes ; then
b5d7414
+   AC_CHECK_LIB(systemd, sd_notifyf, ,
b5d7414
+                AC_MSG_FAILURE([*** systemd library not present - do you need to install systemd-libs package?]))
b5d7414
+fi
b5d7414
+
b5d7414
 # Append selected warning levels to CFLAGS before substitution (but after
b5d7414
 # AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[],[]) & etc).
b5d7414
 CFLAGS="$CFLAGS $STD_CWARNINGS"
b5d7414
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
fa1179c
index 0dc17d6..d3ad31e 100644
b5d7414
--- a/relay/dhcrelay.c
b5d7414
+++ b/relay/dhcrelay.c
b5d7414
@@ -37,6 +37,10 @@
b5d7414
    int keep_capabilities = 0;
b5d7414
 #endif
b5d7414
 
b5d7414
+#ifdef HAVE_LIBSYSTEMD
b5d7414
+#include <systemd/sd-daemon.h>
b5d7414
+#endif
b5d7414
+
b5d7414
 TIME default_lease_time = 43200; /* 12 hours... */
b5d7414
 TIME max_lease_time = 86400; /* 24 hours... */
b5d7414
 struct tree_cache *global_options[256];
fa1179c
@@ -869,6 +873,14 @@ main(int argc, char **argv) {
b5d7414
 	}
b5d7414
 #endif
b5d7414
 
b5d7414
+#ifdef HAVE_LIBSYSTEMD
b5d7414
+        /* We are ready to process incomming packets. Let's notify systemd */
b5d7414
+        sd_notifyf(0, "READY=1\n"
b5d7414
+                   "STATUS=Dispatching packets...\n"
b5d7414
+                   "MAINPID=%lu",
b5d7414
+                   (unsigned long) getpid());
b5d7414
+#endif
b5d7414
+
b5d7414
 	/* Start dispatching packets and timeouts... */
b5d7414
 	dispatch();
b5d7414
 
b5d7414
diff --git a/server/dhcpd.c b/server/dhcpd.c
fa1179c
index 3b3bd3b..9223d5b 100644
b5d7414
--- a/server/dhcpd.c
b5d7414
+++ b/server/dhcpd.c
b5d7414
@@ -60,6 +60,10 @@ gid_t set_gid = 0;
b5d7414
 struct class unknown_class;
b5d7414
 struct class known_class;
b5d7414
 
b5d7414
+#ifdef HAVE_LIBSYSTEMD
b5d7414
+#include <systemd/sd-daemon.h>
b5d7414
+#endif
b5d7414
+
b5d7414
 struct iaddr server_identifier;
b5d7414
 int server_identifier_matched;
b5d7414
 
b5d7414
@@ -1057,6 +1061,14 @@ main(int argc, char **argv) {
b5d7414
 	/* Log that we are about to start working */
b5d7414
 	log_info("Server starting service.");
b5d7414
 
b5d7414
+#ifdef HAVE_LIBSYSTEMD
b5d7414
+        /* We are ready to process incomming packets. Let's notify systemd */
b5d7414
+        sd_notifyf(0, "READY=1\n"
b5d7414
+                   "STATUS=Dispatching packets...\n"
b5d7414
+                   "MAINPID=%lu",
b5d7414
+                   (unsigned long) getpid());
b5d7414
+#endif
b5d7414
+
b5d7414
 	/*
b5d7414
 	 * Receive packets and dispatch them...
b5d7414
 	 * dispatch() will never return.
b5d7414
-- 
fa1179c
2.35.1
b5d7414