mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
Reparse unknown debug flags after config is read to allow use
of dynamically registered debug levels
This commit is contained in:
parent
57c25cbd68
commit
0ef7742328
@ -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 {
|
||||
|
@ -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" );
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user