andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 93776bac227d4408fa5103dc1d0144e3b54bfb7a Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Thu, 8 Oct 2015 10:30:07 -0700
Subject: [PATCH 361/363] Ticket #48304 - ns-slapd - LOGINFO:Unable to remove
 file

Description: In the log rotation, if a log file to be deleted does
not exist, the "Unable to remove file" is logged in the error log,
which is not necessary.

This patch updates the logging code to suppress the unnecessary log
messages as well as replace with more detailed ones.

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

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

(cherry picked from commit e2abffcc5cf6e63136fc0bcb5b0e12830cca22a5)
(cherry picked from commit 6c71c0d96d2287bcae88942ce6d5a0f7df5bee84)
(cherry picked from commit 8081a91a7a1714396a377871d1f676f000d7a4d5)
(cherry picked from commit 217ea08b60eedb2da254517d47991ab0d42e578a)
---
 ldap/servers/slapd/log.c | 109 +++++++++++++++++++++++++++++------------------
 1 file changed, 67 insertions(+), 42 deletions(-)

diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index 3a31260..4db8946 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -2466,15 +2466,25 @@ log__delete_access_logfile()
                 loginfo.log_access_fdes = NULL;
 		PR_snprintf (buffer, sizeof(buffer), "%s", loginfo.log_access_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
-			LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s\n", loginfo.log_access_file,0,0);
+			PRErrorCode prerr = PR_GetError();
+			if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_access_file);
+			} else {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s error %d (%s)\n",
+				                loginfo.log_access_file, prerr, slapd_pr_strerror(prerr));
+			}
 		}
 
 		/* Delete the rotation file also. */
 		PR_snprintf (buffer, sizeof(buffer), "%s.rotationinfo", loginfo.log_access_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
-			LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s.rotationinfo\n", loginfo.log_access_file,0,0);
+			PRErrorCode prerr = PR_GetError();
+			if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_access_file);
+			} else {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s.rotationinfo error %d (%s)\n",
+				                loginfo.log_access_file, prerr, slapd_pr_strerror(prerr));
+			}
 		}
 		return 0;
 	}
@@ -2576,15 +2586,15 @@ delete_logfile:
 	log_convert_time (delete_logp->l_ctime, tbuf, 1 /*short */);
 	PR_snprintf (buffer, sizeof(buffer), "%s.%s", loginfo.log_access_file, tbuf);
 	if (PR_Delete(buffer) != PR_SUCCESS) {
-		LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s.%s\n",
-				   loginfo.log_access_file,tbuf,0);
-
+		PRErrorCode prerr = PR_GetError();
+		if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+			slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_access_file);
+		} else {
+			slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s.%s error %d (%s)\n",
+			                loginfo.log_access_file, tbuf, prerr, slapd_pr_strerror(prerr));
+		}
 	} else {
-		LDAPDebug(LDAP_DEBUG_TRACE, 
-			   "LOGINFO:Removed file:%s.%s because of (%s)\n",
-					loginfo.log_access_file, tbuf,
-					logstr);
+		slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Removed file:%s.%s because of (%s)\n", loginfo.log_access_file, tbuf, logstr);
 	}
 	slapi_ch_free((void**)&delete_logp);
 	loginfo.log_numof_access_logs--;
@@ -3246,7 +3256,6 @@ log__delete_error_logfile(int locked)
 	char               buffer[BUFSIZ];
 	char               tbuf[TBUFSIZE];
 
-
 	/* If we have only one log, then  will delete this one */
 	if (loginfo.log_error_maxnumlogs == 1) {
 		LOG_CLOSE(loginfo.log_error_fdes);
@@ -3254,10 +3263,14 @@ log__delete_error_logfile(int locked)
 		PR_snprintf (buffer, sizeof(buffer), "%s", loginfo.log_error_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
 			if (!locked) {
-				/* if locked, we should not call LDAPDebug, 
-				   which tries to get a lock internally. */
-				LDAPDebug(LDAP_DEBUG_TRACE, 
-					"LOGINFO:Unable to remove file:%s\n", loginfo.log_error_file,0,0);
+				/* If locked, we should not call LDAPDebug, which tries to get a lock internally. */
+				PRErrorCode prerr = PR_GetError();
+				if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+					slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_error_file);
+				} else {
+					slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s error %d (%s)\n",
+					                loginfo.log_error_file, prerr, slapd_pr_strerror(prerr));
+				}
 			}
 		}
 
@@ -3265,11 +3278,14 @@ log__delete_error_logfile(int locked)
 		PR_snprintf (buffer, sizeof(buffer), "%s.rotationinfo", loginfo.log_error_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
 			if (!locked) {
-				/* if locked, we should not call LDAPDebug, 
-				   which tries to get a lock internally. */
-				LDAPDebug(LDAP_DEBUG_TRACE, 
-					"LOGINFO:Unable to remove file:%s.rotationinfo\n", 
-					loginfo.log_error_file,0,0);
+				/* If locked, we should not call LDAPDebug, which tries to get a lock internally. */
+				PRErrorCode prerr = PR_GetError();
+				if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+					slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_error_file);
+				} else {
+					slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s.rotationinfo error %d (%s)\n",
+					                loginfo.log_error_file, prerr, slapd_pr_strerror(prerr));
+				}
 			}
 		}
 		return 0;
@@ -3381,10 +3397,11 @@ delete_logfile:
 	PR_snprintf (buffer, sizeof(buffer), "%s.%s", loginfo.log_error_file, tbuf);
 	if (PR_Delete(buffer) != PR_SUCCESS) {
 		PRErrorCode prerr = PR_GetError();
-		PR_snprintf(buffer, sizeof(buffer),
-				"LOGINFO:Unable to remove file:%s.%s error %d (%s)\n",
-				loginfo.log_error_file, tbuf, prerr, slapd_pr_strerror(prerr));
-		log__error_emergency(buffer, 0, locked);
+		if (PR_FILE_NOT_FOUND_ERROR != prerr) {
+			PR_snprintf(buffer, sizeof(buffer), "LOGINFO:Unable to remove file:%s.%s error %d (%s)\n",
+			            loginfo.log_error_file, tbuf, prerr, slapd_pr_strerror(prerr));
+			log__error_emergency(buffer, 0, locked);
+		}
 	}
 	slapi_ch_free((void**)&delete_logp);
 	loginfo.log_numof_error_logs--;
@@ -3424,15 +3441,25 @@ log__delete_audit_logfile()
                 loginfo.log_audit_fdes = NULL;
 		PR_snprintf(buffer, sizeof(buffer), "%s", loginfo.log_audit_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
-			LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s\n", loginfo.log_audit_file,0,0);
+			PRErrorCode prerr = PR_GetError();
+			if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_audit_file);
+			} else {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s error %d (%s)\n",
+				                loginfo.log_audit_file, prerr, slapd_pr_strerror(prerr));
+			}
 		}
 
 		/* Delete the rotation file also. */
 		PR_snprintf(buffer, sizeof(buffer), "%s.rotationinfo", loginfo.log_audit_file);
 		if (PR_Delete(buffer) != PR_SUCCESS) {
-			LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s.rotationinfo\n", loginfo.log_audit_file,0,0);
+			PRErrorCode prerr = PR_GetError();
+			if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_audit_file);
+			} else {
+				slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s.rotatoininfo error %d (%s)\n",
+				                loginfo.log_audit_file, prerr, slapd_pr_strerror(prerr));
+			}
 		}
 		return 0;
 	}
@@ -3533,15 +3560,15 @@ delete_logfile:
 	log_convert_time (delete_logp->l_ctime, tbuf, 1 /*short */);
 	PR_snprintf(buffer, sizeof(buffer), "%s.%s", loginfo.log_audit_file, tbuf );
 	if (PR_Delete(buffer) != PR_SUCCESS) {
-		LDAPDebug(LDAP_DEBUG_TRACE, 
-				"LOGINFO:Unable to remove file:%s.%s\n",
-				   loginfo.log_audit_file, tbuf,0);
-
+		PRErrorCode prerr = PR_GetError();
+		if (PR_FILE_NOT_FOUND_ERROR == prerr) {
+			slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "File %s already removed\n", loginfo.log_audit_file);
+		} else {
+			slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Unable to remove file:%s.%s error %d (%s)\n",
+			                loginfo.log_audit_file, tbuf, prerr, slapd_pr_strerror(prerr));
+		}
 	} else {
-		LDAPDebug(LDAP_DEBUG_TRACE, 
-			   "LOGINFO:Removed file:%s.%s because of (%s)\n",
-					loginfo.log_audit_file, tbuf,
-					logstr);
+		slapi_log_error(SLAPI_LOG_TRACE, "LOGINFO", "Removed file:%s.%s because of (%s)\n", loginfo.log_audit_file, tbuf, logstr);
 	}
 	slapi_ch_free((void**)&delete_logp);
 	loginfo.log_numof_audit_logs--;
@@ -3823,10 +3850,8 @@ log__open_errorlogfile(int logfile_state, int locked)
 				   Even if PR_Rename fails with the error, we continue logging.
 				 */
 				if (PR_FILE_EXISTS_ERROR != prerr) {
-					PR_snprintf(buffer, sizeof(buffer),
-						"Failed to rename errors log file, " 
-						SLAPI_COMPONENT_NAME_NSPR " error %d (%s). Exiting...", 
-						prerr, slapd_pr_strerror(prerr));
+					PR_snprintf(buffer, sizeof(buffer), "Failed to rename errors log file, " 
+						SLAPI_COMPONENT_NAME_NSPR " error %d (%s). Exiting...\n", prerr, slapd_pr_strerror(prerr));
 					log__error_emergency(buffer, 1, 1);
 					slapi_ch_free((void **)&log);
 					if (!locked) LOG_ERROR_UNLOCK_WRITE();
-- 
2.4.3