From 01e990632a1fe3918cf78a8633576b13fc4da50a Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Fri, 7 Feb 2014 15:07:45 -0800 Subject: [PATCH] Ticket #47693 - Environment variables are not passed when DS is started via service Description: Environment variables (except TERM and LANG) are ignored if a program is started via service. If it is started with systemctl, it takes this COMMAND and the values are correctly passed to the server. systemctl set-environment SLAPD_MXFAST=0 MALLOC_TRIM_THRESHOLD_=4096 To control them explicitly and to provide the same instructions to the service and systemctl, it'd be good to have some variables (SLAPD_MXFAST, MALLOC_TRIM_THRESHOLD_ and MALLOC_MMAP_THRESHOLD_ in this patch) configurable. --- ldap/servers/slapd/libglobs.c | 181 ++++++++++++++++++++++++++++++++++++++++ ldap/servers/slapd/proto-slap.h | 11 +++ ldap/servers/slapd/slap.h | 12 +++ 3 files changed, 204 insertions(+) diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c index bea8b2c..d3f451e 100644 --- a/ldap/servers/slapd/libglobs.c +++ b/ldap/servers/slapd/libglobs.c @@ -81,6 +81,9 @@ #endif /* USE_SYSCONF */ #include "slap.h" #include "plhash.h" +#if defined(LINUX) +#include +#endif #define REMOVE_CHANGELOG_CMD "remove" @@ -266,6 +269,11 @@ slapi_onoff_t init_plugin_logging; slapi_int_t init_connection_buffer; slapi_int_t init_listen_backlog_size; slapi_onoff_t init_ignore_time_skew; +#if defined (LINUX) +slapi_int_t init_malloc_mxfast; +slapi_int_t init_malloc_trim_threshold; +slapi_int_t init_malloc_mmap_threshold; +#endif #ifdef MEMPOOL_EXPERIMENTAL slapi_onoff_t init_mempool_switch; #endif @@ -1073,6 +1081,23 @@ static struct config_get_and_set { NULL, 0, (void**)&global_slapdFrontendConfig.listen_backlog_size, CONFIG_INT, (ConfigGetFunc)config_get_listen_backlog_size, &init_listen_backlog_size}, +#if defined(LINUX) + {CONFIG_MALLOC_MXFAST, config_set_malloc_mxfast, + NULL, 0, + (void**)&global_slapdFrontendConfig.malloc_mxfast, + CONFIG_INT, (ConfigGetFunc)config_get_malloc_mxfast, + &init_malloc_mxfast}, + {CONFIG_MALLOC_TRIM_THRESHOLD, config_set_malloc_trim_threshold, + NULL, 0, + (void**)&global_slapdFrontendConfig.malloc_trim_threshold, + CONFIG_INT, (ConfigGetFunc)config_get_malloc_trim_threshold, + &init_malloc_trim_threshold}, + {CONFIG_MALLOC_MMAP_THRESHOLD, config_set_malloc_mmap_threshold, + NULL, 0, + (void**)&global_slapdFrontendConfig.malloc_mmap_threshold, + CONFIG_INT, (ConfigGetFunc)config_get_malloc_mmap_threshold, + &init_malloc_mmap_threshold}, +#endif {CONFIG_IGNORE_TIME_SKEW, config_set_ignore_time_skew, NULL, 0, (void**)&global_slapdFrontendConfig.ignore_time_skew, @@ -1520,6 +1545,12 @@ FrontendConfig_init () { init_plugin_logging = cfg->plugin_logging = LDAP_OFF; init_listen_backlog_size = cfg->listen_backlog_size = DAEMON_LISTEN_SIZE; init_ignore_time_skew = cfg->ignore_time_skew = LDAP_OFF; +#if defined(LINUX) + init_malloc_mxfast = cfg->malloc_mxfast = DEFAULT_MALLOC_UNSET; + init_malloc_trim_threshold = cfg->malloc_trim_threshold = DEFAULT_MALLOC_UNSET; + init_malloc_mmap_threshold = cfg->malloc_mmap_threshold = DEFAULT_MALLOC_UNSET; +#endif + #ifdef MEMPOOL_EXPERIMENTAL init_mempool_switch = cfg->mempool_switch = LDAP_ON; cfg->mempool_maxfreelist = 1024; @@ -7555,6 +7586,156 @@ config_set_auditlog_enabled(int value){ CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig); } +#if defined(LINUX) +int +config_set_malloc_mxfast(const char *attrname, char *value, char *errorbuf, int apply) +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int max = 80 * (sizeof(size_t) / 4); + int mxfast; + char *endp = NULL; + + if (config_value_is_null(attrname, value, errorbuf, 0)) { + return LDAP_OPERATIONS_ERROR; + } + errno = 0; + mxfast = strtol(value, &endp, 10); + + if ((*endp != '\0') || (errno == ERANGE)) { + PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, + "limit \"%s\" is invalid, password grace limit must range from 0 to %lld", + value , (long long int)LONG_MAX ); + return LDAP_OPERATIONS_ERROR; + } + CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig); + slapdFrontendConfig->malloc_mxfast = mxfast; + CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig); + + if ((mxfast >= 0) && (mxfast <= max)) { + mallopt(M_MXFAST, mxfast); +slapi_log_error(SLAPI_LOG_FATAL, "config", + "NYA: %s: set %d\n", + CONFIG_MALLOC_MXFAST, mxfast); + } else if (DEFAULT_MALLOC_UNSET != mxfast) { + slapi_log_error(SLAPI_LOG_FATAL, "config", + "%s: Invalid value %d will be ignored\n", + CONFIG_MALLOC_MXFAST, mxfast); + } + return LDAP_SUCCESS; +} + +int +config_get_malloc_mxfast() +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int retVal; + + retVal = slapdFrontendConfig->malloc_mxfast; + return retVal; +} + +int +config_set_malloc_trim_threshold(const char *attrname, char *value, char *errorbuf, int apply) +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int trim_threashold; + char *endp = NULL; + + if (config_value_is_null(attrname, value, errorbuf, 0)) { + return LDAP_OPERATIONS_ERROR; + } + errno = 0; + trim_threashold = strtol(value, &endp, 10); + + if ((*endp != '\0') || (errno == ERANGE)) { + PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, + "limit \"%s\" is invalid, password grace limit must range from 0 to %lld", + value , (long long int)LONG_MAX ); + return LDAP_OPERATIONS_ERROR; + } + + CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig); + slapdFrontendConfig->malloc_trim_threshold = trim_threashold; + CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig); + + if (trim_threashold >= -1) { + mallopt(M_TRIM_THRESHOLD, trim_threashold); +slapi_log_error(SLAPI_LOG_FATAL, "config", + "NYA: %s: set %d\n", + CONFIG_MALLOC_TRIM_THRESHOLD, trim_threashold); + } else if (DEFAULT_MALLOC_UNSET != trim_threashold) { + slapi_log_error(SLAPI_LOG_FATAL, "config", + "%s: Invalid value %d will be ignored\n", + CONFIG_MALLOC_TRIM_THRESHOLD, trim_threashold); + } + return LDAP_SUCCESS; +} + +int +config_get_malloc_trim_threshold() +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int retVal; + + retVal = slapdFrontendConfig->malloc_trim_threshold; + return retVal; +} + +int +config_set_malloc_mmap_threshold(const char *attrname, char *value, char *errorbuf, int apply) +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int max; + int mmap_threshold; + char *endp = NULL; + + if (config_value_is_null(attrname, value, errorbuf, 0)) { + return LDAP_OPERATIONS_ERROR; + } + errno = 0; + mmap_threshold = strtol(value, &endp, 10); + + if ((*endp != '\0') || (errno == ERANGE)) { + PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, + "limit \"%s\" is invalid, password grace limit must range from 0 to %lld", + value , (long long int)LONG_MAX ); + return LDAP_OPERATIONS_ERROR; + } + + CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig); + slapdFrontendConfig->malloc_mmap_threshold = mmap_threshold; + CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig); + + if (sizeof(char *) == 8) { + max = 33554432; /* 4*1024*1024*sizeof(long) on 64-bit systems */ + } else { + max = 524288; /* 512*1024 on 32-bit systems */ + } + + if ((mmap_threshold >= 0) && (mmap_threshold <= max)) { + mallopt(M_MMAP_THRESHOLD, mmap_threshold); +slapi_log_error(SLAPI_LOG_FATAL, "config", + "NYA: %s: set %d\n", + CONFIG_MALLOC_MMAP_THRESHOLD, mmap_threshold); + } else if (DEFAULT_MALLOC_UNSET != mmap_threshold) { + slapi_log_error(SLAPI_LOG_FATAL, "config", + "%s: Invalid value %d will be ignored\n", + CONFIG_MALLOC_MMAP_THRESHOLD, mmap_threshold); + } + return LDAP_SUCCESS; +} + +int +config_get_malloc_mmap_threshold() +{ + slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig(); + int retVal; + + retVal = slapdFrontendConfig->malloc_mmap_threshold; + return retVal; +} +#endif + char * slapi_err2string(int result) { diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h index 9f77146..3aa2170 100644 --- a/ldap/servers/slapd/proto-slap.h +++ b/ldap/servers/slapd/proto-slap.h @@ -401,6 +401,11 @@ int config_set_return_orig_type_switch(const char *attrname, char *value, char * int config_set_sasl_maxbufsize(const char *attrname, char *value, char *errorbuf, int apply ); int config_set_listen_backlog_size(const char *attrname, char *value, char *errorbuf, int apply); int config_set_ignore_time_skew(const char *attrname, char *value, char *errorbuf, int apply); +#if defined(LINUX) +int config_set_malloc_mxfast(const char *attrname, char *value, char *errorbuf, int apply); +int config_set_malloc_trim_threshold(const char *attrname, char *value, char *errorbuf, int apply); +int config_set_malloc_mmap_threshold(const char *attrname, char *value, char *errorbuf, int apply); +#endif #if !defined(_WIN32) && !defined(AIX) int config_set_maxdescriptors( const char *attrname, char *value, char *errorbuf, int apply ); @@ -582,6 +587,12 @@ PLHashNumber hashNocaseString(const void *key); PRIntn hashNocaseCompare(const void *v1, const void *v2); int config_get_ignore_time_skew(); +#if defined(LINUX) +int config_get_malloc_mxfast(); +int config_get_malloc_trim_threshold(); +int config_get_malloc_mmap_threshold(); +#endif + int is_abspath(const char *); char* rel2abspath( char * ); char* rel2abspath_ext( char *, char * ); diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h index 068748b..e7ee893 100644 --- a/ldap/servers/slapd/slap.h +++ b/ldap/servers/slapd/slap.h @@ -2138,6 +2138,13 @@ typedef struct _slapdEntryPoints { #define CONFIG_PLUGIN_LOGGING "nsslapd-plugin-logging" #define CONFIG_LISTEN_BACKLOG_SIZE "nsslapd-listen-backlog-size" +/* getenv alternative */ +#define CONFIG_MALLOC_MXFAST "nsslapd-malloc-mxfast" +#define CONFIG_MALLOC_TRIM_THRESHOLD "nsslapd-malloc-trim-threshold" +#define CONFIG_MALLOC_MMAP_THRESHOLD "nsslapd-malloc-mmap-threshold" + +#define DEFAULT_MALLOC_UNSET (-10) + /* * Define the backlog number for use in listen() call. * We use the same definition as in ldapserver/include/base/systems.h @@ -2392,6 +2399,11 @@ typedef struct _slapdFrontendConfig { slapi_onoff_t connection_nocanon; /* if "on" sets LDAP_OPT_X_SASL_NOCANON */ slapi_onoff_t plugin_logging; /* log all internal plugin operations */ slapi_onoff_t ignore_time_skew; +#if defined(LINUX) + int malloc_mxfast; /* mallopt M_MXFAST */ + int malloc_trim_threshold; /* mallopt M_TRIM_THRESHOLD */ + int malloc_mmap_threshold; /* mallopt M_MMAP_THRESHOLD */ +#endif } slapdFrontendConfig_t; /* possible values for slapdFrontendConfig_t.schemareplace */ -- 1.8.1.4