From 8722daa6e790241f1f7adab316a5ae908f28ce93 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 16 May 2025 15:15:30 +0100 Subject: [PATCH] Only allow one instance of Anope at once. --- src/init.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 75e6a2419..89a946a98 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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);