Blame SOURCES/slapi-nis-priming-0003-nis-add-backend-shutdown-support-to-stop-priming-thr.patch

6b9042
From 63212ccae673e46334b874688741bf96d996fd36 Mon Sep 17 00:00:00 2001
6b9042
From: Thierry Bordaz <tbordaz@redhat.com>
6b9042
Date: Tue, 26 Apr 2016 13:17:03 +0300
6b9042
Subject: [PATCH 3/4] nis: add backend shutdown support to stop priming thread
6b9042
6b9042
Resolves: rhbz#1327197
6b9042
---
6b9042
 src/back-nis.c |  6 ++++++
6b9042
 src/plug-nis.c | 34 +++++++++++++++++++++++++++-------
6b9042
 2 files changed, 33 insertions(+), 7 deletions(-)
6b9042
6b9042
diff --git a/src/back-nis.c b/src/back-nis.c
6b9042
index b9379c0..7fb191d 100644
6b9042
--- a/src/back-nis.c
6b9042
+++ b/src/back-nis.c
6b9042
@@ -1021,6 +1021,12 @@ backend_startup(Slapi_PBlock *pb, struct plugin_state *state)
6b9042
 	backend_shr_startup(state, pb, NIS_MAP_CONFIGURATION_FILTER);
6b9042
 }
6b9042
 
6b9042
+void
6b9042
+backend_shutdown(struct plugin_state *state)
6b9042
+{
6b9042
+    backend_shr_shutdown(state);
6b9042
+}
6b9042
+
6b9042
 /* Set up our post-op callbacks. */
6b9042
 #ifdef SLAPI_NIS_SUPPORT_BE_TXNS
6b9042
 int
6b9042
diff --git a/src/plug-nis.c b/src/plug-nis.c
6b9042
index a1bdf89..ee90c37 100644
6b9042
--- a/src/plug-nis.c
6b9042
+++ b/src/plug-nis.c
6b9042
@@ -81,14 +81,31 @@ plugin_startup(Slapi_PBlock *pb)
6b9042
 	struct plugin_state *state;
6b9042
 	const char *pname;
6b9042
 	int i, protocol;
6b9042
+	Slapi_DN *pluginsdn = NULL;
6b9042
+
6b9042
 	slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
6b9042
-	slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
6b9042
-	slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
6b9042
-			"configuration entry is %s%s%s\n",
6b9042
-			state->plugin_base ? "\"" : "",
6b9042
-			state->plugin_base ? state->plugin_base : "NULL",
6b9042
-			state->plugin_base ? "\"" : "");
6b9042
+	slapi_pblock_get(pb, SLAPI_TARGET_SDN, &pluginsdn);
6b9042
+	/* plugin base need to be duplicated because it will be destroyed
6b9042
+	 * when pblock is destroyed but we need to use it in a separate thread */
6b9042
+	if (NULL == pluginsdn || 0 == slapi_sdn_get_ndn_len(pluginsdn)) {
6b9042
+        slapi_log_error(SLAPI_LOG_FATAL, state->plugin_desc->spd_id,
6b9042
+                        "nis plugin_startup: unable to retrieve plugin DN\n");
6b9042
+		return -1;
6b9042
+
6b9042
+    } else {
6b9042
+        state->plugin_base = slapi_ch_strdup(slapi_sdn_get_dn(pluginsdn));
6b9042
+		slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
6b9042
+				"configuration entry is %s%s%s\n",
6b9042
+				state->plugin_base ? "\"" : "",
6b9042
+				state->plugin_base ? state->plugin_base : "NULL",
6b9042
+				state->plugin_base ? "\"" : "");
6b9042
+    }
6b9042
+
6b9042
 	/* Populate the maps and data. */
6b9042
+        if (state->priming_mutex == NULL) {
6b9042
+            state->priming_mutex = wrap_new_mutex();
6b9042
+	    state->start_priming_thread = 1;
6b9042
+        }
6b9042
 	backend_startup(pb, state);
6b9042
 	/* Start a new listening thread to handle incoming traffic. */
6b9042
 	state->tid = wrap_start_thread(&dispatch_thread, state);
6b9042
@@ -177,6 +194,7 @@ plugin_shutdown(Slapi_PBlock *pb)
6b9042
 	struct plugin_state *state;
6b9042
 	int i, protocol;
6b9042
 	slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
6b9042
+        backend_shutdown(state);
6b9042
 	for (i = 0; i < state->n_listeners; i++) {
6b9042
 		if (state->pmap_client_socket != -1) {
6b9042
 			switch (state->listener[i].type) {
6b9042
@@ -217,7 +235,9 @@ plugin_shutdown(Slapi_PBlock *pb)
6b9042
 #ifdef HAVE_TCPD_H
6b9042
 	free(state->request_info);
6b9042
 #endif
6b9042
-	state->plugin_base = NULL;
6b9042
+        if (state->plugin_base != NULL) {
6b9042
+		slapi_ch_free((void **)&state->plugin_base);
6b9042
+	}
6b9042
 	slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
6b9042
 			"plugin shutdown completed\n");
6b9042
 	return 0;
6b9042
-- 
6b9042
2.7.4
6b9042