]> git.sur5r.net Git - openldap/commitdiff
ITS#2318: unlink pid file (and args file)
authorKurt Zeilenga <kurt@openldap.org>
Wed, 19 Feb 2003 20:47:57 +0000 (20:47 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 19 Feb 2003 20:47:57 +0000 (20:47 +0000)
servers/slapd/main.c

index 10ab52ae2c9117e27d9d7afdffe0079647580952..d9e19b4f97e82d0cfde61d252f3c1b3a6a3fd719 100644 (file)
@@ -524,31 +524,38 @@ int main( int argc, char **argv )
                goto shutdown;
        }
 
-       {
-               FILE *fp;
-
 #ifdef NEW_LOGGING
-               LDAP_LOG( SLAPD, INFO, "main: slapd starting.\n", 0, 0, 0 );
+       LDAP_LOG( SLAPD, INFO, "main: slapd starting.\n", 0, 0, 0 );
 #else
-               Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
+       Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
 #endif
 
 
-               if (( slapd_pid_file != NULL ) &&
-                       (( fp = fopen( slapd_pid_file, "w" )) != NULL ))
-               {
+       if ( slapd_pid_file != NULL ) {
+               FILE *fp = fopen( slapd_pid_file, "w" );
+
+               if( fp != NULL ) {
                        fprintf( fp, "%d\n", (int) getpid() );
                        fclose( fp );
+
+               } else {
+                       free(slapd_pid_file);
+                       slapd_pid_file = NULL;
                }
+       }
 
-               if (( slapd_args_file != NULL ) &&
-                       (( fp = fopen( slapd_args_file, "w" )) != NULL ))
-               {
+       if ( slapd_args_file != NULL ) {
+               FILE *fp = fopen( slapd_args_file, "w" );
+
+               if( fp != NULL ) {
                        for ( i = 0; i < g_argc; i++ ) {
                                fprintf( fp, "%s ", g_argv[i] );
                        }
                        fprintf( fp, "\n" );
                        fclose( fp );
+               } else {
+                       free(slapd_args_file);
+                       slapd_args_file = NULL;
                }
        }
 
@@ -607,6 +614,13 @@ stop:
        ldap_pvt_tls_destroy();
 #endif
 
+       if ( slapd_pid_file != NULL ) {
+               unlink( slapd_pid_file );
+       }
+       if ( slapd_args_file != NULL ) {
+               unlink( slapd_args_file );
+       }
+
        config_destroy();
 
 #ifdef CSRIMALLOC