summaryrefslogtreecommitdiffstats
path: root/debian/patches/0002-Add-support-for-reporting-status-via-sd_notify.patch
blob: dec22c75d949e83510d8b0b1a21c84b2a465373e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
From: Debian DNS Team <team+dns@tracker.debian.org>
Date: Wed, 25 Jan 2023 15:51:06 +0100
Subject: Add-support-for-reporting-status-via-sd_notify

---
 bin/named/Makefile.am |  8 +++++++-
 bin/named/server.c    | 44 +++++++++++++++++++++++++++++++++++++++++---
 configure.ac          | 20 ++++++++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/bin/named/Makefile.am b/bin/named/Makefile.am
index 57a023b..38045f0 100644
--- a/bin/named/Makefile.am
+++ b/bin/named/Makefile.am
@@ -14,6 +14,7 @@ AM_CPPFLAGS +=				\
 	$(MAXMINDDB_CFLAGS)		\
 	$(DNSTAP_CFLAGS)		\
 	$(LIBUV_CFLAGS)			\
+	$(LIBSYSTEMD_CFLAGS)		\
 	$(ZLIB_CFLAGS)
 
 if HAVE_JSON_C
@@ -109,7 +110,7 @@ named_LDADD =					\
 	$(MAXMINDDB_LIBS)			\
 	$(DNSTAP_LIBS)				\
 	$(LIBUV_LIBS)				\
-	$(LIBXML2_LIBS)				\
+	$(LIBSYSTEMD_LIBS)			\
 	$(ZLIB_LIBS)
 
 if HAVE_JSON_C
@@ -121,3 +122,8 @@ if HAVE_LIBNGHTTP2
 named_LDADD +=					\
 	$(LIBNGHTTP2_LIBS)
 endif HAVE_LIBNGHTTP2
+
+if HAVE_LIBXML2
+named_LDADD +=					\
+	$(LIBXML2_LIBS)
+endif HAVE_LIBXML2
diff --git a/bin/named/server.c b/bin/named/server.c
index 2f21fc5..6930d98 100644
--- a/bin/named/server.c
+++ b/bin/named/server.c
@@ -26,6 +26,10 @@
 #include <fstrm.h>
 #endif
 
+#ifdef HAVE_LIBSYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 #include <isc/aes.h>
 #include <isc/app.h>
 #include <isc/attributes.h>
@@ -219,11 +223,12 @@
 	} while (0)
 
 #define CHECKFATAL(op, msg)                         \
-	do {                                        \
+	{                                           \
 		result = (op);                      \
-		if (result != ISC_R_SUCCESS)        \
+		if (result != ISC_R_SUCCESS) {      \
 			fatal(server, msg, result); \
-	} while (0)
+		}                                   \
+	}
 
 /*%
  * Maximum ADB size for views that share a cache.  Use this limit to suppress
@@ -9929,6 +9934,15 @@ view_loaded(void *arg) {
 			      "FIPS mode is %s",
 			      FIPS_mode() ? "enabled" : "disabled");
 #endif /* ifdef HAVE_FIPS_MODE */
+
+#if HAVE_LIBSYSTEMD
+		sd_notifyf(0,
+			   "READY=1\n"
+			   "STATUS=running\n"
+			   "MAINPID=%" PRId64 "\n",
+			   (int64_t)getpid());
+#endif /* HAVE_LIBSYSTEMD */
+
 		atomic_store(&server->reload_status, NAMED_RELOAD_DONE);
 
 		isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
@@ -10108,6 +10122,10 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
 	UNUSED(task);
 	INSIST(task == server->task);
 
+#if HAVE_LIBSYSTEMD
+	sd_notify(0, "STOPPING=1\n");
+#endif /* HAVE_LIBSYSTEMD */
+
 	/*
 	 * We need to shutdown the interface before going
 	 * exclusive (which would pause the netmgr).
@@ -10528,6 +10546,10 @@ reload(named_server_t *server) {
 	isc_result_t result;
 
 	atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS);
+#if HAVE_LIBSYSTEMD
+	sd_notify(0, "RELOADING=1\n"
+		     "STATUS=reload command received\n");
+#endif /* HAVE_LIBSYSTEMD */
 
 	CHECK(loadconfig(server));
 
@@ -10544,6 +10566,12 @@ reload(named_server_t *server) {
 		atomic_store(&server->reload_status, NAMED_RELOAD_FAILED);
 	}
 cleanup:
+#if HAVE_LIBSYSTEMD
+	sd_notifyf(0,
+		   "READY=1\n"
+		   "STATUS=reload command finished: %s\n",
+		   isc_result_totext(result));
+#endif /* HAVE_LIBSYSTEMD */
 	return (result);
 }
 
@@ -10903,6 +10931,10 @@ isc_result_t
 named_server_reconfigcommand(named_server_t *server) {
 	isc_result_t result;
 	atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS);
+#if HAVE_LIBSYSTEMD
+	sd_notify(0, "RELOADING=1\n"
+		     "STATUS=reconfig command received\n");
+#endif /* HAVE_LIBSYSTEMD */
 
 	CHECK(loadconfig(server));
 
@@ -10919,6 +10951,12 @@ named_server_reconfigcommand(named_server_t *server) {
 		atomic_store(&server->reload_status, NAMED_RELOAD_FAILED);
 	}
 cleanup:
+#if HAVE_LIBSYSTEMD
+	sd_notifyf(0,
+		   "READY=1\n"
+		   "STATUS=reconfig command finished: %s\n",
+		   isc_result_totext(result));
+#endif /* HAVE_LIBSYSTEMD */
 	return (result);
 }
 
diff --git a/configure.ac b/configure.ac
index dc61f79..c3cd5d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -872,6 +872,26 @@ AS_CASE([$with_zlib],
 AC_SUBST([ZLIB_CFLAGS])
 AC_SUBST([ZLIB_LIBS])
 
+#
+# was --with-libsystemd specified?
+#
+# [pairwise: --with-libsystemd=auto, --with-libsystemd=yes, --without-libsystemd]
+AC_ARG_WITH([libsystemd],
+	    [AS_HELP_STRING([--with-libsystemd],
+			    [build with libsystemd integration [default=auto]])],
+	    [], [with_libsystemd=auto])
+
+AS_CASE([$with_libsystemd],
+	[no],[],
+	[auto],[PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd],
+				  [AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Use libsystemd library])],
+				  [:])],
+	[yes],[PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd],
+				 [AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Use libsystemd library])])],
+	[AC_MSG_ERROR([Specifying libsystemd installation path is not supported, adjust PKG_CONFIG_PATH instead])])
+AC_SUBST([LIBSYSTEMD_CFLAGS])
+AC_SUBST([LIBSYSTEMD_LIBS])
+
 #
 # Check if the system supports glibc-compatible backtrace() function.
 #