Blame SOURCES/0019-Ticket-48939-nsslapd-workingdir-is-empty-when-ns-sla.patch

7c7f29
From 6b5c8ba040fa482c1817c044716bb994f173d373 Mon Sep 17 00:00:00 2001
7c7f29
From: Noriko Hosoi <nhosoi@redhat.com>
7c7f29
Date: Wed, 27 Jul 2016 11:23:17 -0700
7c7f29
Subject: [PATCH 19/29] Ticket #48939 - nsslapd-workingdir is empty when
7c7f29
 ns-slapd is started by systemd
7c7f29
7c7f29
Description: Thanks to tbordaz@redhat.com for suggesting to reset the
7c7f29
working dir in the error cases.  I've added more error checks and
7c7f29
resetting the nsslapd-workingdir values.
7c7f29
7c7f29
https://fedorahosted.org/389/ticket/48939
7c7f29
7c7f29
Reviewed by mreynolds@redhat.com (Thank you, Mark!!)
7c7f29
7c7f29
(cherry picked from commit 70d06dab96468e0c6712482186f22de8e2c33e17)
7c7f29
---
7c7f29
 ldap/servers/slapd/detach.c | 45 +++++++++++++++++++++++++++++++++++++++++----
7c7f29
 1 file changed, 41 insertions(+), 4 deletions(-)
7c7f29
7c7f29
diff --git a/ldap/servers/slapd/detach.c b/ldap/servers/slapd/detach.c
7c7f29
index cd13a99..2f5667f 100644
7c7f29
--- a/ldap/servers/slapd/detach.c
7c7f29
+++ b/ldap/servers/slapd/detach.c
7c7f29
@@ -59,14 +59,41 @@ set_workingdir()
7c7f29
 		errorlog = config_get_errorlog();
7c7f29
 		if (NULL == errorlog) {
7c7f29
 			rc = chdir("/");
7c7f29
+			if (0 == rc) {
7c7f29
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+				}
7c7f29
+			} else {
7c7f29
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
7c7f29
+			}
7c7f29
 		} else {
7c7f29
 			ptr = strrchr(errorlog, '/');
7c7f29
 			if (ptr) {
7c7f29
 				*ptr = '\0';
7c7f29
 			}
7c7f29
 			rc = chdir(errorlog);
7c7f29
-			if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, errorlog, errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
-				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+			if (0 == rc) {
7c7f29
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, errorlog, errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+					rc = chdir("/");
7c7f29
+					if (0 == rc) {
7c7f29
+						if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
+							LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+						}
7c7f29
+					} else {
7c7f29
+						LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
7c7f29
+					}
7c7f29
+				}
7c7f29
+			} else {
7c7f29
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", errorlog);
7c7f29
+				rc = chdir("/");
7c7f29
+				if (0 == rc) {
7c7f29
+					if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
+						LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+					}
7c7f29
+				} else {
7c7f29
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
7c7f29
+				}
7c7f29
 			}
7c7f29
 			slapi_ch_free_string(&errorlog);
7c7f29
 		}
7c7f29
@@ -75,8 +102,18 @@ set_workingdir()
7c7f29
 		if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, workingdir, errorbuf, 0) == LDAP_OPERATIONS_ERROR) {
7c7f29
 			LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
 			rc = chdir("/");
7c7f29
+			if (0 == rc) {
7c7f29
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
7c7f29
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
7c7f29
+				}
7c7f29
+			} else {
7c7f29
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
7c7f29
+			}
7c7f29
 		} else {
7c7f29
 			rc = chdir(workingdir);
7c7f29
+			if (rc) {
7c7f29
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", workingdir);
7c7f29
+			}
7c7f29
 		}
7c7f29
 		slapi_ch_free_string(&workingdir);
7c7f29
 	}
7c7f29
@@ -115,7 +152,7 @@ detach( int slapd_exemode, int importexport_encrypt,
7c7f29
 		}
7c7f29
 
7c7f29
 		if (set_workingdir()) {
7c7f29
-			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: chdir to workingdir failed.\n");
7c7f29
+			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: set_workingdir failed.\n");
7c7f29
 		}
7c7f29
 
7c7f29
 		if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) {
7c7f29
@@ -142,7 +179,7 @@ detach( int slapd_exemode, int importexport_encrypt,
7c7f29
 			return 1;
7c7f29
 		}
7c7f29
 		if (set_workingdir()) {
7c7f29
-			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: chdir to workingdir failed.\n");
7c7f29
+			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: set_workingdir failed.\n");
7c7f29
 		}
7c7f29
 	}
7c7f29
 
7c7f29
-- 
7c7f29
2.4.11
7c7f29