1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

(trunk daemon) #3206 "add pidfile support" -- tweak to r10655 suggested by Longinus00: if the pidfile was successfully created, remove it on exit

This commit is contained in:
Charles Kerr 2010-05-18 20:58:12 +00:00
parent 5eb2f5a274
commit 0cc65eb152

View file

@ -309,6 +309,7 @@ main( int argc, char ** argv )
const char * configDir = NULL; const char * configDir = NULL;
dtr_watchdir * watchdir = NULL; dtr_watchdir * watchdir = NULL;
FILE * logfile = NULL; FILE * logfile = NULL;
tr_bool pidfile_created = FALSE;
signal( SIGINT, gotsig ); signal( SIGINT, gotsig );
signal( SIGTERM, gotsig ); signal( SIGTERM, gotsig );
@ -442,11 +443,14 @@ main( int argc, char ** argv )
tr_ninf( NULL, "Using settings from \"%s\"", configDir ); tr_ninf( NULL, "Using settings from \"%s\"", configDir );
tr_sessionSaveSettings( mySession, configDir, &settings ); tr_sessionSaveSettings( mySession, configDir, &settings );
if( pid_filename != NULL ) { if( pid_filename != NULL )
{
FILE * fp = fopen( pid_filename, "w+" ); FILE * fp = fopen( pid_filename, "w+" );
if( fp != NULL ) { if( fp != NULL )
{
fprintf( fp, "%d", (int)getpid() ); fprintf( fp, "%d", (int)getpid() );
fclose( fp ); fclose( fp );
pidfile_created = TRUE;
} }
} }
@ -506,6 +510,8 @@ main( int argc, char ** argv )
printf( " done.\n" ); printf( " done.\n" );
/* cleanup */ /* cleanup */
if( pidfile_created )
remove( pid_filename );
tr_bencFree( &settings ); tr_bencFree( &settings );
return 0; return 0;
} }