mirror of
https://github.com/anope/anope.git
synced 2026-06-29 17:16:38 +02:00
Only allow one instance of Anope at once.
This commit is contained in:
@@ -235,6 +235,18 @@ static void write_pidfile()
|
||||
if (Anope::NoPID || pidfile.empty())
|
||||
return;
|
||||
|
||||
#ifndef _WIN32
|
||||
std::ifstream oldstream(pidfile.str());
|
||||
if (oldstream.is_open())
|
||||
{
|
||||
pid_t oldpid = 0;
|
||||
oldstream >> oldpid;
|
||||
if (oldpid && kill(oldpid, 0) == 0)
|
||||
throw CoreException("Anope is already running with process id " + Anope::ToString(oldpid));
|
||||
}
|
||||
oldstream.close();
|
||||
#endif
|
||||
|
||||
std::ofstream stream(pidfile.str());
|
||||
if (!stream.is_open())
|
||||
throw CoreException("Can not write to PID file " + pidfile);
|
||||
|
||||
Reference in New Issue
Block a user