amoralej / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 years ago
Clone
Blob Blame History Raw
From 6b5c8ba040fa482c1817c044716bb994f173d373 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Wed, 27 Jul 2016 11:23:17 -0700
Subject: [PATCH 19/29] Ticket #48939 - nsslapd-workingdir is empty when
 ns-slapd is started by systemd

Description: Thanks to tbordaz@redhat.com for suggesting to reset the
working dir in the error cases.  I've added more error checks and
resetting the nsslapd-workingdir values.

https://fedorahosted.org/389/ticket/48939

Reviewed by mreynolds@redhat.com (Thank you, Mark!!)

(cherry picked from commit 70d06dab96468e0c6712482186f22de8e2c33e17)
---
 ldap/servers/slapd/detach.c | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/ldap/servers/slapd/detach.c b/ldap/servers/slapd/detach.c
index cd13a99..2f5667f 100644
--- a/ldap/servers/slapd/detach.c
+++ b/ldap/servers/slapd/detach.c
@@ -59,14 +59,41 @@ set_workingdir()
 		errorlog = config_get_errorlog();
 		if (NULL == errorlog) {
 			rc = chdir("/");
+			if (0 == rc) {
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+				}
+			} else {
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
+			}
 		} else {
 			ptr = strrchr(errorlog, '/');
 			if (ptr) {
 				*ptr = '\0';
 			}
 			rc = chdir(errorlog);
-			if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, errorlog, errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
-				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+			if (0 == rc) {
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, errorlog, errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+					rc = chdir("/");
+					if (0 == rc) {
+						if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
+							LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+						}
+					} else {
+						LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
+					}
+				}
+			} else {
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", errorlog);
+				rc = chdir("/");
+				if (0 == rc) {
+					if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
+						LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+					}
+				} else {
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
+				}
 			}
 			slapi_ch_free_string(&errorlog);
 		}
@@ -75,8 +102,18 @@ set_workingdir()
 		if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, workingdir, errorbuf, 0) == LDAP_OPERATIONS_ERROR) {
 			LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
 			rc = chdir("/");
+			if (0 == rc) {
+				if (config_set_workingdir(CONFIG_WORKINGDIR_ATTRIBUTE, "/", errorbuf, 1) == LDAP_OPERATIONS_ERROR) {
+					LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: set workingdir failed with \"%s\"\n", errorbuf);
+				}
+			} else {
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", "/");
+			}
 		} else {
 			rc = chdir(workingdir);
+			if (rc) {
+				LDAPDebug1Arg(LDAP_DEBUG_ANY, "detach: failed to chdir to %s\n", workingdir);
+			}
 		}
 		slapi_ch_free_string(&workingdir);
 	}
@@ -115,7 +152,7 @@ detach( int slapd_exemode, int importexport_encrypt,
 		}
 
 		if (set_workingdir()) {
-			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: chdir to workingdir failed.\n");
+			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: set_workingdir failed.\n");
 		}
 
 		if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) {
@@ -142,7 +179,7 @@ detach( int slapd_exemode, int importexport_encrypt,
 			return 1;
 		}
 		if (set_workingdir()) {
-			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: chdir to workingdir failed.\n");
+			LDAPDebug0Args(LDAP_DEBUG_ANY, "detach: set_workingdir failed.\n");
 		}
 	}
 
-- 
2.4.11