1
0
Эх сурвалжийг харах

Ticket #48939 - nsslapd-workingdir is empty when ns-slapd is started by systemd

Description: Thanks to [email protected] 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 [email protected] (Thank you, Mark!!)
Noriko Hosoi 9 жил өмнө
parent
commit
70d06dab96

+ 41 - 4
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");
 		}
 	}