summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch')
-rw-r--r--meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch165
1 files changed, 165 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch b/meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch
new file mode 100644
index 0000000000..34b2ae1e5c
--- /dev/null
+++ b/meta/recipes-connectivity/dhcp/dhcp/0001-Ensure-context-is-running-prior-to-calling-isc_app_c.patch
@@ -0,0 +1,165 @@
1From f369dbb9e67eb5ef336944af63039b6d8f838384 Mon Sep 17 00:00:00 2001
2From: Thomas Markwalder <tmark@isc.org>
3Date: Thu, 12 Sep 2019 10:35:46 -0400
4Subject: [PATCH 1/3] Ensure context is running prior to calling
5 isc_app_ctxsuspend
6
7Add a release note.
8
9includes/omapip/isclib.h
10 Added actx_running flag to global context, dhcp_gbl_ctx
11
12omapip/isclib.c
13 set_ctx_running() - new function used as the ctxonrun callback
14
15 dhcp_context_create() - installs set_ctx_running callback
16
17 dhcp_signal_handler() - modified to use act_running flag to
18 determine is context is running and should be suspended
19
20Upstream-Status: Backport [https://gitlab.isc.org/isc-projects/dhcp.git]
21
22Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
23---
24 RELNOTES | 7 +++++
25 includes/omapip/isclib.h | 3 ++-
26 omapip/isclib.c | 57 +++++++++++++++++++++++++++++++++-------
27 3 files changed, 57 insertions(+), 10 deletions(-)
28
29diff --git a/RELNOTES b/RELNOTES
30index f10305d..1730473 100644
31--- a/RELNOTES
32+++ b/RELNOTES
33@@ -6,6 +6,13 @@
34
35 NEW FEATURES
36
37+- Closed a small window of time between the installation of graceful
38+ shutdown signal handlers and application context startup, during which
39+ the receipt of shutdown signal would cause a REQUIRE() assertion to
40+ occur. Note this issue is only visible when compiling with
41+ ENABLE_GENTLE_SHUTDOWN defined.
42+ [Gitlab #53,!18 git TBD]
43+
44 Please note that that ISC DHCP is now licensed under the Mozilla Public License,
45 MPL 2.0. Please see https://www.mozilla.org/en-US/MPL/2.0/ to read the MPL 2.0
46 license terms.
47diff --git a/includes/omapip/isclib.h b/includes/omapip/isclib.h
48index 6c20584..af6a6fc 100644
49--- a/includes/omapip/isclib.h
50+++ b/includes/omapip/isclib.h
51@@ -94,7 +94,8 @@
52 typedef struct dhcp_context {
53 isc_mem_t *mctx;
54 isc_appctx_t *actx;
55- int actx_started;
56+ int actx_started; // ISC_TRUE if ctxstart has been called
57+ int actx_running; // ISC_TRUE if ctxrun has been called
58 isc_taskmgr_t *taskmgr;
59 isc_task_t *task;
60 isc_socketmgr_t *socketmgr;
61diff --git a/omapip/isclib.c b/omapip/isclib.c
62index ce4b4a1..73e017c 100644
63--- a/omapip/isclib.c
64+++ b/omapip/isclib.c
65@@ -134,6 +134,35 @@ handle_signal(int sig, void (*handler)(int)) {
66 }
67 }
68
69+/* Callback passed to isc_app_ctxonrun
70+ *
71+ * BIND9 context code will invoke this handler once the context has
72+ * entered the running state. We use it to set a global marker so that
73+ * we can tell if the context is running. Several of the isc_app_
74+ * calls REQUIRE that the context is running and we need a way to
75+ * know that.
76+ *
77+ * We also check to see if we received a shutdown signal prior to
78+ * the context entering the run state. If we did, then we can just
79+ * simply shut the context down now. This closes the relatively
80+ * small window between start up and entering run via the call
81+ * to dispatch().
82+ *
83+ */
84+static void
85+set_ctx_running(isc_task_t *task, isc_event_t *event) {
86+ task = task; // unused;
87+ dhcp_gbl_ctx.actx_running = ISC_TRUE;
88+
89+ if (shutdown_signal) {
90+ // We got signaled shutdown before we entered running state.
91+ // Now that we've reached running state, shut'er down.
92+ isc_app_ctxsuspend(dhcp_gbl_ctx.actx);
93+ }
94+
95+ isc_event_free(&event);
96+}
97+
98 isc_result_t
99 dhcp_context_create(int flags,
100 struct in_addr *local4,
101@@ -141,6 +170,9 @@ dhcp_context_create(int flags,
102 isc_result_t result;
103
104 if ((flags & DHCP_CONTEXT_PRE_DB) != 0) {
105+ dhcp_gbl_ctx.actx_started = ISC_FALSE;
106+ dhcp_gbl_ctx.actx_running = ISC_FALSE;
107+
108 /*
109 * Set up the error messages, this isn't the right place
110 * for this call but it is convienent for now.
111@@ -204,15 +236,24 @@ dhcp_context_create(int flags,
112 if (result != ISC_R_SUCCESS)
113 goto cleanup;
114
115- result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task);
116+ result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0,
117+ &dhcp_gbl_ctx.task);
118 if (result != ISC_R_SUCCESS)
119 goto cleanup;
120
121 result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
122 if (result != ISC_R_SUCCESS)
123- return (result);
124+ goto cleanup;
125+
126 dhcp_gbl_ctx.actx_started = ISC_TRUE;
127
128+ // Install the onrun callback.
129+ result = isc_app_ctxonrun(dhcp_gbl_ctx.actx, dhcp_gbl_ctx.mctx,
130+ dhcp_gbl_ctx.task, set_ctx_running,
131+ dhcp_gbl_ctx.actx);
132+ if (result != ISC_R_SUCCESS)
133+ goto cleanup;
134+
135 /* Not all OSs support suppressing SIGPIPE through socket
136 * options, so set the sigal action to be ignore. This allows
137 * broken connections to fail gracefully with EPIPE on writes */
138@@ -335,19 +376,17 @@ isclib_make_dst_key(char *inname,
139 * @param signal signal code that we received
140 */
141 void dhcp_signal_handler(int signal) {
142- isc_appctx_t *ctx = dhcp_gbl_ctx.actx;
143- int prev = shutdown_signal;
144-
145- if (prev != 0) {
146+ if (shutdown_signal != 0) {
147 /* Already in shutdown. */
148 return;
149 }
150+
151 /* Possible race but does it matter? */
152 shutdown_signal = signal;
153
154- /* Use reload (aka suspend) for easier dispatch() reenter. */
155- if (ctx && ctx->methods && ctx->methods->ctxsuspend) {
156- (void) isc_app_ctxsuspend(ctx);
157+ /* If the application context is running tell it to shut down */
158+ if (dhcp_gbl_ctx.actx_running == ISC_TRUE) {
159+ (void) isc_app_ctxsuspend(dhcp_gbl_ctx.actx);
160 }
161 }
162
163--
1642.23.0
165