From: Kurt Zeilenga Date: Fri, 10 Oct 2003 02:15:21 +0000 (+0000) Subject: fix pid/arg file handling X-Git-Tag: OPENLDAP_REL_ENG_2_1_23~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d05a375d4262533e8f6f3115bf76ea5b589567f;p=thirdparty%2Fopenldap.git fix pid/arg file handling --- diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index c12f9e9022..2315ad5c79 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -178,42 +178,43 @@ int main( int argc, char **argv ) } - if ( slurpd_pid_file != NULL ) { - FILE *fp = fopen( slurpd_pid_file, "w" ); + /* + * Detach from the controlling terminal + * unless the -d flag is given or in one-shot mode. + */ +#ifndef HAVE_WINSOCK + if ( ! (sglob->no_detach || sglob->one_shot_mode) ) { + lutil_detach( 0, 0 ); + } +#endif + + if ( slurpd_pid_file != NULL ) { + FILE *fp = fopen( slurpd_pid_file, "w" ); - if( fp != NULL ) { - fprintf( fp, "%d\n", (int) getpid() ); - fclose( fp ); + if( fp != NULL ) { + fprintf( fp, "%d\n", (int) getpid() ); + fclose( fp ); - } else { + } else { free(slurpd_pid_file); slurpd_pid_file = NULL; + } } - } - if ( slurpd_args_file != NULL ) { - FILE *fp = fopen( slurpd_args_file, "w" ); - - if( fp != NULL ) { - for ( i = 0; i < argc; i++ ) { - fprintf( fp, "%s ", argv[i] ); + if ( slurpd_args_file != NULL ) { + FILE *fp = fopen( slurpd_args_file, "w" ); + + if( fp != NULL ) { + for ( i = 0; i < argc; i++ ) { + fprintf( fp, "%s ", argv[i] ); + } + fprintf( fp, "\n" ); + fclose( fp ); + } else { + free(slurpd_args_file); + slurpd_args_file = NULL; } - fprintf( fp, "\n" ); - fclose( fp ); - } else { - free(slurpd_args_file); - slurpd_args_file = NULL; } - } - - /* - * Detach from the controlling terminal - * unless the -d flag is given or in one-shot mode. - */ -#ifndef HAVE_WINSOCK - if ( ! (sglob->no_detach || sglob->one_shot_mode) ) - lutil_detach( 0, 0 ); -#endif if ( (rc = lutil_pair( sglob->wake_sds )) < 0 ) { SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );