From 571e53b7cadbcc3119c65dccbddc220b99735c85 Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Thu, 16 Aug 2007 21:17:02 +0000 Subject: [PATCH] Properly protect pidfile creation and deletion with the lockfile. --- daemon/daemon.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index 884cf4cf0..633688921 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -85,14 +85,16 @@ main( int argc, char ** argv ) errsyslog( 1 ); } - if( NULL != pidfile && 0 > savepid( pidfile ) ) - exit( 1 ); atexit( exitcleanup ); sockfd = trylocksock( sockpath ); if( 0 > sockfd ) { exit( 1 ); } + if( NULL != pidfile && 0 > savepid( pidfile ) ) + { + exit( 1 ); + } evbase = event_init(); setupsigs( evbase ); @@ -299,15 +301,15 @@ exitcleanup( void ) unlink( gl_sockpath ); close( gl_sockfd ); } + if( 0 != gl_pidfile[0] ) + { + unlink( gl_pidfile ); + } if( 0 <= gl_lockfd ) { unlink( gl_lockpath ); close( gl_lockfd ); } - if( 0 != gl_pidfile[0] ) - { - unlink( gl_pidfile ); - } } void