From cccf35c749c0b179b417da03d9f33dfe6801e9af Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 8 Aug 2005 14:01:40 +0000 Subject: [PATCH] allow textual log levels in command line --- servers/slapd/bconfig.c | 24 +++++++++++++++++++++--- servers/slapd/main.c | 16 +++++++++++++++- servers/slapd/proto-slap.h | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 77d9065f01..291004fb62 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1945,6 +1945,26 @@ slap_loglevel_register( slap_mask_t m, struct berval *s ) return rc; } +int +str2loglevel( const char *s, int *l ) +{ + int i; + + if ( loglevel_ops == NULL ) { + loglevel_init(); + } + + i = verb_to_mask( s, loglevel_ops ); + + if ( BER_BVISNULL( &loglevel_ops[ i ].word) ) { + return -1; + } + + *l = loglevel_ops[ i ].mask; + + return 0; +} + static int config_loglevel(ConfigArgs *c) { int i; @@ -1980,14 +2000,12 @@ config_loglevel(ConfigArgs *c) { return( 1 ); } } else { - int j = verb_to_mask(c->argv[i], loglevel_ops); - if(BER_BVISNULL(&loglevel_ops[j].word)) { + if ( str2loglevel( c->argv[i], &level ) ) { sprintf( c->msg, "<%s> unknown level", c->argv[0] ); Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, c->argv[i]); return( 1 ); } - level = loglevel_ops[j].mask; } ldap_syslog |= level; } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index b607bdb912..02dcd5009f 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -386,7 +386,21 @@ int main( int argc, char **argv ) case 'd': /* set debug level and 'do not detach' flag */ no_detach = 1; #ifdef LDAP_DEBUG - slap_debug |= atoi( optarg ); + if ( optarg != NULL && optarg[ 0 ] != '-' && !isdigit( optarg[ 0 ] ) ) + { + int level; + + if ( str2loglevel( optarg, &level ) ) { + fprintf( stderr, + "unrecognized log level " + "\"%s\"\n", optarg ); + goto destroy; + } + + slap_debug |= level; + } else { + slap_debug |= atoi( optarg ); + } #else if ( atoi( optarg ) != 0 ) fputs( "must compile with LDAP_DEBUG for debugging\n", diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 24ab45ac70..5ad9092de7 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -368,6 +368,7 @@ LDAP_SLAPD_F (int) overlay_op_walk LDAP_P(( * bconfig.c */ LDAP_SLAPD_F (int) slap_loglevel_register LDAP_P (( slap_mask_t m, struct berval *s )); +LDAP_SLAPD_F (int) str2loglevel LDAP_P(( const char *s, int *l )); /* * ch_malloc.c -- 2.39.5