andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From 5b5f57e8f008a342d82c7aa2d6a6574df7a3f14e Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Thu, 6 Jun 2013 15:30:41 -0400
dc8c34
Subject: [PATCH] Ticket 47385 - DS not shutting down when disk monitoring threshold is reached
dc8c34
dc8c34
Bug Description:  If verbose logging is enabled, it fails to correctly
dc8c34
                  identify that the logging was disabled, and it gets
dc8c34
                  stuck in an endless loop - never shutting the server down.
dc8c34
dc8c34
                  Also, whe the server does shutdown due to a disk full, the
dc8c34
                  pid file is not removed.
dc8c34
dc8c34
Fix Description:  Check for the two possible error log levels that indicate
dc8c34
                  verbose logging is disabled.  There were also logic errors
dc8c34
                  when determining if it was ok to disable access/audit logging,
dc8c34
                  and if to delete rotated logs.
dc8c34
dc8c34
                  Also removed the "nsslapd-disk-monitoring-preserve-logging"
dc8c34
                  setting, as it really didn't served a purpose because it was
dc8c34
                  basically the same as "nsslapd-disk-monitoring-logging-critical".
dc8c34
dc8c34
                  Lastly, if the server is being shutdown from a "disk full"
dc8c34
                  condition, then we need to manually remove the pidfile.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47385
dc8c34
dc8c34
Reviewed by: Noriko(Thanks!)
dc8c34
---
dc8c34
 ldap/servers/slapd/daemon.c     |   31 ++++++++++++++++++++-----------
dc8c34
 ldap/servers/slapd/libglobs.c   |   28 ----------------------------
dc8c34
 ldap/servers/slapd/proto-slap.h |    2 --
dc8c34
 ldap/servers/slapd/slap.h       |    2 --
dc8c34
 4 files changed, 20 insertions(+), 43 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
dc8c34
index b611f5c..5cc643a 100644
dc8c34
--- a/ldap/servers/slapd/daemon.c
dc8c34
+++ b/ldap/servers/slapd/daemon.c
dc8c34
@@ -711,7 +711,6 @@ disk_monitoring_thread(void *nothing)
dc8c34
     time_t now = 0;
dc8c34
     int deleted_rotated_logs = 0;
dc8c34
     int logging_critical = 0;
dc8c34
-    int preserve_logging = 0;
dc8c34
     int passed_threshold = 0;
dc8c34
     int verbose_logging = 0;
dc8c34
     int using_accesslog = 0;
dc8c34
@@ -741,7 +740,6 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  Get the config settings, as they could have changed
dc8c34
          */
dc8c34
         logging_critical = config_get_disk_logging_critical();
dc8c34
-        preserve_logging = config_get_disk_preserve_logging();
dc8c34
         grace_period = 60 * config_get_disk_grace_period(); /* convert it to seconds */
dc8c34
         verbose_logging = config_get_errorlog_level();
dc8c34
         threshold = config_get_disk_threshold();
dc8c34
@@ -798,18 +796,21 @@ disk_monitoring_thread(void *nothing)
dc8c34
         }
dc8c34
         /*
dc8c34
          *  If we are low, see if we are using verbose error logging, and turn it off
dc8c34
+         *  if logging is not critical
dc8c34
          */
dc8c34
-        if(verbose_logging){
dc8c34
+        if(verbose_logging != 0 && verbose_logging != LDAP_DEBUG_ANY){
dc8c34
             LDAPDebug(LDAP_DEBUG_ANY, "Disk space is low on disk (%s), remaining space: %d Kb, "
dc8c34
-                "setting error loglevel to zero.\n", dirstr, (disk_space / 1024), 0);
dc8c34
-            config_set_errorlog_level(CONFIG_LOGLEVEL_ATTRIBUTE, 0, errorbuf, CONFIG_APPLY);
dc8c34
+                "temporarily setting error loglevel to zero.\n", dirstr,
dc8c34
+                (disk_space / 1024), 0);
dc8c34
+            /* Setting the log level back to zero, actually sets the value to LDAP_DEBUG_ANY */
dc8c34
+            config_set_errorlog_level(CONFIG_LOGLEVEL_ATTRIBUTE, "0", errorbuf, CONFIG_APPLY);
dc8c34
             continue;
dc8c34
         }
dc8c34
         /*
dc8c34
          *  If we are low, there's no verbose logging, logs are not critical, then disable the
dc8c34
          *  access/audit logs, log another error, and continue.
dc8c34
          */
dc8c34
-        if(!logs_disabled && (!preserve_logging || !logging_critical)){
dc8c34
+        if(!logs_disabled && !logging_critical){
dc8c34
             if(disk_space < previous_mark){
dc8c34
                 LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %d Kb, "
dc8c34
                     "disabling access and audit logging.\n", dirstr, (disk_space / 1024), 0);
dc8c34
@@ -823,7 +824,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  If we are low, we turned off verbose logging, logs are not critical, and we disabled
dc8c34
          *  access/audit logging, then delete the rotated logs, log another error, and continue.
dc8c34
          */
dc8c34
-        if(!deleted_rotated_logs && (!preserve_logging || !logging_critical)){
dc8c34
+        if(!deleted_rotated_logs && !logging_critical){
dc8c34
             if(disk_space < previous_mark){
dc8c34
                 LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %d Kb, "
dc8c34
                     "deleting rotated logs.\n", dirstr, (disk_space / 1024), 0);
dc8c34
@@ -872,10 +873,10 @@ disk_monitoring_thread(void *nothing)
dc8c34
                      */
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY, "Available disk space is now acceptable (%d bytes).  Aborting"
dc8c34
                                               " shutdown, and restoring the log settings.\n",disk_space,0,0);
dc8c34
-                    if(!preserve_logging && using_accesslog){
dc8c34
+                    if(logs_disabled && using_accesslog){
dc8c34
                         config_set_accesslog_enabled(LOGGING_ON);
dc8c34
                     }
dc8c34
-                    if(!preserve_logging && using_auditlog){
dc8c34
+                    if(logs_disabled && using_auditlog){
dc8c34
                         config_set_auditlog_enabled(LOGGING_ON);
dc8c34
                     }
dc8c34
                     deleted_rotated_logs = 0;
dc8c34
@@ -892,7 +893,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
                      */
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY, "Disk space is critically low on disk (%s), remaining space: %d Kb."
dc8c34
                         "  Signaling slapd for shutdown...\n", dirstr, (disk_space / 1024), 0);
dc8c34
-                    g_set_shutdown( SLAPI_SHUTDOWN_EXIT );
dc8c34
+                    g_set_shutdown( SLAPI_SHUTDOWN_DISKFULL );
dc8c34
                     return;
dc8c34
                 }
dc8c34
                 time(&now;;
dc8c34
@@ -909,7 +910,8 @@ disk_monitoring_thread(void *nothing)
dc8c34
              */
dc8c34
             LDAPDebug(LDAP_DEBUG_ANY, "Disk space is still too low (%d Kb).  Signaling slapd for shutdown...\n",
dc8c34
                 (disk_space / 1024), 0, 0);
dc8c34
-            g_set_shutdown( SLAPI_SHUTDOWN_EXIT );
dc8c34
+            g_set_shutdown( SLAPI_SHUTDOWN_DISKFULL );
dc8c34
+
dc8c34
             return;
dc8c34
         }
dc8c34
     }
dc8c34
@@ -1379,6 +1381,13 @@ void slapd_daemon( daemon_ports_t *ports )
dc8c34
 
dc8c34
 #ifdef _WIN32
dc8c34
 	WSACleanup();
dc8c34
+#else
dc8c34
+	if ( g_get_shutdown() == SLAPI_SHUTDOWN_DISKFULL ){
dc8c34
+		/* This is a server-induced shutdown, we need to manually remove the pid file */
dc8c34
+		if( unlink(get_pid_file()) ){
dc8c34
+			LDAPDebug( LDAP_DEBUG_ANY, "Failed to remove pid file %s\n", get_pid_file(), 0, 0 );
dc8c34
+		}
dc8c34
+	}
dc8c34
 #endif
dc8c34
 }
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
dc8c34
index 3226ede..02e9df1 100644
dc8c34
--- a/ldap/servers/slapd/libglobs.c
dc8c34
+++ b/ldap/servers/slapd/libglobs.c
dc8c34
@@ -687,10 +687,6 @@ static struct config_get_and_set {
dc8c34
 		NULL, 0,
dc8c34
 		(void**)&global_slapdFrontendConfig.disk_logging_critical,
dc8c34
 		CONFIG_ON_OFF, (ConfigGetFunc)config_get_disk_logging_critical},
dc8c34
-	{CONFIG_DISK_PRESERVE_LOGGING, config_set_disk_preserve_logging,
dc8c34
-		NULL, 0,
dc8c34
-		(void**)&global_slapdFrontendConfig.disk_preserve_logging,
dc8c34
-		CONFIG_ON_OFF, (ConfigGetFunc)config_get_disk_preserve_logging},
dc8c34
 #ifdef MEMPOOL_EXPERIMENTAL
dc8c34
 	,{CONFIG_MEMPOOL_SWITCH_ATTRIBUTE, config_set_mempool_switch,
dc8c34
 		NULL, 0,
dc8c34
@@ -1090,7 +1086,6 @@ FrontendConfig_init () {
dc8c34
   cfg->disk_monitoring = LDAP_OFF;
dc8c34
   cfg->disk_threshold = 2097152;  /* 2 mb */
dc8c34
   cfg->disk_grace_period = 60; /* 1 hour */
dc8c34
-  cfg->disk_preserve_logging = LDAP_OFF;
dc8c34
   cfg->disk_logging_critical = LDAP_OFF;
dc8c34
 
dc8c34
 #ifdef MEMPOOL_EXPERIMENTAL
dc8c34
@@ -1259,17 +1254,6 @@ config_set_disk_threshold( const char *attrname, char *value, char *errorbuf, in
dc8c34
 }
dc8c34
 
dc8c34
 int
dc8c34
-config_set_disk_preserve_logging( const char *attrname, char *value, char *errorbuf, int apply )
dc8c34
-{
dc8c34
-    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
-    int retVal = LDAP_SUCCESS;
dc8c34
-
dc8c34
-    retVal = config_set_onoff ( attrname, value, &(slapdFrontendConfig->disk_preserve_logging),
dc8c34
-                                errorbuf, apply);
dc8c34
-    return retVal;
dc8c34
-}
dc8c34
-
dc8c34
-int
dc8c34
 config_set_disk_logging_critical( const char *attrname, char *value, char *errorbuf, int apply )
dc8c34
 {
dc8c34
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
@@ -3742,18 +3726,6 @@ config_get_disk_monitoring(){
dc8c34
 }
dc8c34
 
dc8c34
 int
dc8c34
-config_get_disk_preserve_logging(){
dc8c34
-    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
-    int retVal;
dc8c34
-
dc8c34
-    CFG_LOCK_READ(slapdFrontendConfig);
dc8c34
-    retVal = slapdFrontendConfig->disk_preserve_logging;
dc8c34
-    CFG_UNLOCK_READ(slapdFrontendConfig);
dc8c34
-
dc8c34
-    return retVal;
dc8c34
-}
dc8c34
-
dc8c34
-int
dc8c34
 config_get_disk_logging_critical(){
dc8c34
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
     int retVal;
dc8c34
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
dc8c34
index 5112471..17b1e99 100644
dc8c34
--- a/ldap/servers/slapd/proto-slap.h
dc8c34
+++ b/ldap/servers/slapd/proto-slap.h
dc8c34
@@ -388,7 +388,6 @@ int config_set_default_naming_context( const char *attrname, char *value, char *
dc8c34
 int config_set_disk_monitoring( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
 int config_set_disk_threshold( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
 int config_set_disk_grace_period( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
-int config_set_disk_preserve_logging( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
 int config_set_disk_logging_critical( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
 int config_set_auditlog_unhashed_pw(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
 
dc8c34
@@ -544,7 +543,6 @@ int config_get_accesslog_logging_enabled();
dc8c34
 int config_get_disk_monitoring();
dc8c34
 long config_get_disk_threshold();
dc8c34
 int config_get_disk_grace_period();
dc8c34
-int config_get_disk_preserve_logging();
dc8c34
 int config_get_disk_logging_critical();
dc8c34
 
dc8c34
 int is_abspath(const char *);
dc8c34
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
dc8c34
index eea025a..e0b261d 100644
dc8c34
--- a/ldap/servers/slapd/slap.h
dc8c34
+++ b/ldap/servers/slapd/slap.h
dc8c34
@@ -2001,7 +2001,6 @@ typedef struct _slapdEntryPoints {
dc8c34
 #define CONFIG_DISK_MONITORING "nsslapd-disk-monitoring"
dc8c34
 #define CONFIG_DISK_THRESHOLD "nsslapd-disk-monitoring-threshold"
dc8c34
 #define CONFIG_DISK_GRACE_PERIOD "nsslapd-disk-monitoring-grace-period"
dc8c34
-#define CONFIG_DISK_PRESERVE_LOGGING "nsslapd-disk-monitoring-preserve-logging"
dc8c34
 #define CONFIG_DISK_LOGGING_CRITICAL "nsslapd-disk-monitoring-logging-critical"
dc8c34
 
dc8c34
 #ifdef MEMPOOL_EXPERIMENTAL
dc8c34
@@ -2236,7 +2235,6 @@ typedef struct _slapdFrontendConfig {
dc8c34
   int disk_monitoring;
dc8c34
   int disk_threshold;
dc8c34
   int disk_grace_period;
dc8c34
-  int disk_preserve_logging;
dc8c34
   int disk_logging_critical;
dc8c34
 } slapdFrontendConfig_t;
dc8c34
 
dc8c34
-- 
dc8c34
1.7.1
dc8c34