From 0ef7742328fb37a369ee95cea6aecdedfd86b8c0 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 2 Feb 2006 08:30:56 +0000 Subject: [PATCH] Reparse unknown debug flags after config is read to allow use of dynamically registered debug levels --- servers/slapd/bconfig.c | 2 +- servers/slapd/main.c | 57 +++++++++++++++++++++++++++++--------- servers/slapd/proto-slap.h | 4 ++- servers/slapd/slapcommon.c | 11 +++++++- 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 3d3771b838..a5cf6730cf 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2171,7 +2171,7 @@ slap_loglevel_get( struct berval *s, int *l ) rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore ); if ( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n", + Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n", i, s->bv_val, 0 ); } else { diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 38348533d4..46d24ba1db 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -222,13 +222,31 @@ parse_syslog_level( const char *arg, int *levelp ) } int -parse_debug_level( const char *arg, int *levelp ) +parse_debug_unknowns( char **unknowns, int *levelp ) +{ + int i, level, rc = 0; + + for ( i = 0; unknowns[ i ] != NULL; i++ ) { + level = 0; + if ( str2loglevel( unknowns[ i ], &level )) { + fprintf( stderr, + "unrecognized log level \"%s\"\n", unknowns[ i ] ); + rc = 1; + } else { + *levelp |= level; + } + } + return rc; +} + +int +parse_debug_level( const char *arg, int *levelp, char ***unknowns ) { int level; if ( arg != NULL && arg[ 0 ] != '-' && !isdigit( arg[ 0 ] ) ) { - int i, goterr = 0; + int i; char **levels; levels = ldap_str2charray( arg, "," ); @@ -237,12 +255,11 @@ parse_debug_level( const char *arg, int *levelp ) level = 0; if ( str2loglevel( levels[ i ], &level ) ) { + /* remember this for later */ + ldap_charray_add( unknowns, levels[ i ] ); fprintf( stderr, - "unrecognized log level " - "\"%s\"\n", levels[ i ] ); - goterr = 1; - /* but keep parsing... */ - + "unrecognized log level \"%s\" (deferred)\n", + levels[ i ] ); } else { *levelp |= level; } @@ -250,10 +267,6 @@ parse_debug_level( const char *arg, int *levelp ) ldap_charray_free( levels ); - if ( goterr ) { - return 1; - } - } else { if ( lutil_atoix( &level, arg, 0 ) != 0 ) { fprintf( stderr, @@ -349,6 +362,9 @@ int main( int argc, char **argv ) struct sync_cookie *scp = NULL; struct sync_cookie *scp_entry = NULL; + char **debug_unknowns = NULL; + char **syslog_unknowns = NULL; + char *serverNamePrefix = ""; size_t l; @@ -486,7 +502,7 @@ int main( int argc, char **argv ) int level = 0; no_detach = 1; - if ( parse_debug_level( optarg, &level ) ) { + if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) { goto destroy; } #ifdef LDAP_DEBUG @@ -541,7 +557,7 @@ int main( int argc, char **argv ) } case 's': /* set syslog level */ - if ( parse_debug_level( optarg, &ldap_syslog ) ) { + if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) { goto destroy; } break; @@ -707,6 +723,21 @@ unhandled_option:; goto destroy; } + if ( debug_unknowns ) { + rc = parse_debug_unknowns( debug_unknowns, &slap_debug ); + ldap_charray_free( debug_unknowns ); + debug_unknowns = NULL; + if ( rc ) + goto destroy; + } + if ( syslog_unknowns ) { + rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog ); + ldap_charray_free( syslog_unknowns ); + syslog_unknowns = NULL; + if ( rc ) + goto destroy; + } + if ( check & CHECK_CONFIG ) { fprintf( stderr, "config check succeeded\n" ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5859ecad3e..5bdba47717 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1004,7 +1004,9 @@ LDAP_SLAPD_F (int) lock_fclose LDAP_P(( FILE *fp, FILE *lfp )); * main.c */ LDAP_SLAPD_F (int) -parse_debug_level LDAP_P(( const char *arg, int *levelp )); +parse_debug_level LDAP_P(( const char *arg, int *levelp, char ***unknowns )); +LDAP_SLAPD_F (int) +parse_debug_unknowns LDAP_P(( char **unknowns, int *levelp )); /* * matchedValues.c diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 9f99363dc8..59e1e01cf3 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -189,6 +189,7 @@ slap_tool_init( char *filterstr = NULL; char *subtree = NULL; char *ldiffile = NULL; + char **debug_unknowns = NULL; int rc, i, dbnum; int mode = SLAP_TOOL_MODE; int truncatemode = 0; @@ -267,7 +268,7 @@ slap_tool_init( case 'd': { /* turn on debugging */ int level = 0; - if ( parse_debug_level( optarg, &level ) ) { + if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) { usage( tool, progname ); } #ifdef LDAP_DEBUG @@ -454,6 +455,14 @@ slap_tool_init( exit( EXIT_FAILURE ); } + if ( debug_unknowns ) { + rc = parse_debug_unknowns( debug_unknowns, &slap_debug ); + ldap_charray_free( debug_unknowns ); + debug_unknowns = NULL; + if ( rc ) + exit( EXIT_FAILURE ); + } + at_oc_cache = 1; switch ( tool ) { -- 2.39.5