1
0
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:
Sadie Powell
2025-05-16 15:15:30 +01:00
parent a0e98acea8
commit 8722daa6e7
+12
View File
@@ -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);