Improve instance detection

Fix -i option
This commit is contained in:
2020-06-15 16:36:24 +02:00
parent 27404a4aa7
commit c72f90e5eb
4 changed files with 33 additions and 9 deletions

View File

@ -116,7 +116,17 @@ bool createPidFile(const std::string& fileName)
if(std::filesystem::exists(fileName))
{
std::cerr<<fileName<<" pid file exsists, only one instance may run at once\n";
return false;
std::string sigstopedName = Process(getpid()).getName();
if(Process::byName(sigstopedName).size() > 1) return false;
else
{
std::cerr<<"Only one "
<<sigstopedName
<<" process exists, either sigstoped died or you have severl diferently named binarys\n";
std::filesystem::remove(fileName);
return createPidFile(fileName);
}
}
else
{
@ -150,7 +160,7 @@ int main(int argc, char* argv[])
std::string confDir = getConfdir();
if(confDir.size() == 0) return 1;
if(!createPidFile(confDir+"pidfile")) return 1;
if(!createPidFile(confDir+"pidfile"));
std::vector<std::string> applicationNames = getApplicationlist(confDir+"blacklist");
@ -185,6 +195,7 @@ int main(int argc, char* argv[])
signal(SIGINT, sigTerm);
signal(SIGTERM, sigTerm);
signal(SIGHUP, sigTerm);
signal(SIGUSR1, sigUser1);
while(!stop)