]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
ITS#4780 plug leak
[openldap] / servers / slapd / main.c
index 8b1ee9c9c6300cd01aef7a657f6ef554e21be8e5..877c04250311b9e4eca49a25040bb5ee9e360e23 100644 (file)
@@ -98,8 +98,9 @@ const char Versionstr[] =
        OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
 #endif
 
-#define CHECK_NONE     0x00
-#define CHECK_CONFIG   0x01
+#define        CHECK_NONE      0x00
+#define        CHECK_CONFIG    0x01
+#define        CHECK_LOGLEVEL  0x02
 static int check = CHECK_NONE;
 static int version = 0;
 
@@ -369,6 +370,7 @@ int main( int argc, char **argv )
        size_t  l;
 
        int slapd_pid_file_unlink = 0, slapd_args_file_unlink = 0;
+       int firstopt = 1;
 
 #ifdef CSRIMALLOC
        FILE *leakfile;
@@ -502,8 +504,8 @@ int main( int argc, char **argv )
                        int     level = 0;
 
                        if ( strcmp( optarg, "?" ) == 0 ) {
-                               rc = loglevel_print( stdout );
-                               goto destroy;
+                               check |= CHECK_LOGLEVEL;
+                               break;
                        }
 
                        no_detach = 1;
@@ -563,8 +565,8 @@ int main( int argc, char **argv )
 
                case 's':       /* set syslog level */
                        if ( strcmp( optarg, "?" ) == 0 ) {
-                               rc = loglevel_print( stdout );
-                               goto destroy;
+                               check |= CHECK_LOGLEVEL;
+                               break;
                        }
 
                        if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) {
@@ -623,6 +625,12 @@ int main( int argc, char **argv )
                        break;
 
                case 'T':
+                       if ( firstopt == 0 ) {
+                               fprintf( stderr, "warning: \"-T %s\" "
+                                       "should be the first option.\n",
+                                       optarg );
+                       }
+
                        /* try full option string first */
                        for ( i = 0; tools[i].name; i++ ) {
                                if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
@@ -653,6 +661,10 @@ unhandled_option:;
                        SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
                        goto stop;
                }
+
+               if ( firstopt ) {
+                       firstopt = 0;
+               }
        }
 
        ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
@@ -754,6 +766,11 @@ unhandled_option:;
                syslog_unknowns = NULL;
                if ( rc )
                        goto destroy;
+       }       
+
+       if ( check & CHECK_LOGLEVEL ) {
+               rc = 0;
+               goto destroy;
        }
 
        if ( check & CHECK_CONFIG ) {
@@ -924,6 +941,9 @@ shutdown:
        rc |= slap_shutdown( NULL );
 
 destroy:
+       if ( check & CHECK_LOGLEVEL ) {
+               (void)loglevel_print( stdout );
+       }
        /* remember an error during destroy */
        rc |= slap_destroy();