Skip to content
Permalink
Browse files

Closes #198, erroneous unlinking of not-owned pid-file

  • Loading branch information
klirichek committed Feb 8, 2018
1 parent 5fcf016 commit 48d7e8001d2a66466ca64577f27ddc5421a67251
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/searchd.cpp
@@ -186,6 +186,7 @@ static CSphVector<Listener_t> g_dListeners;
static int g_iQueryLogFile = -1;
static CSphString g_sQueryLogFile;
static CSphString g_sPidFile;
static bool g_bPidIsMine = false; // if PID is not mine, don't unlink it on fail
static int g_iPidFD = -1;

static int g_iMaxCachedDocs = 0; // in bytes
@@ -1585,12 +1586,14 @@ void Shutdown ()

ClosePersistentSockets();

// remove pid
if ( !g_sPidFile.IsEmpty() )
{
// close pid
if ( g_iPidFD!=-1 )
::close ( g_iPidFD );
g_iPidFD = -1;

// remove pid file, if we owned it
if ( g_bPidIsMine && !g_sPidFile.IsEmpty() )
::unlink ( g_sPidFile.cstr() );
}

sphInfo ( "shutdown complete" );

if ( bOptPIDFile && !sphLockEx ( g_iPidFD, false ) )
sphFatal ( "failed to lock pid file '%s': %s (searchd already running?)", g_sPidFile.scstr(), strerror(errno) );

g_bPidIsMine = true;

// Actions on resurrection
if ( bWatched && !bVisualLoad && CheckConfigChanges() )
{

0 comments on commit 48d7e80

Please sign in to comment.
You can’t perform that action at this time.