summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-05-16 15:15:30 +0100
committerSadie Powell <sadie@witchery.services>2025-05-16 15:15:30 +0100
commit8722daa6e790241f1f7adab316a5ae908f28ce93 (patch)
treeee2c8fecf89e5b3993acfb39c7c027b75f04fe3d /src
parenta0e98acea8fee1cf6d7ac510c920d45612273ac0 (diff)
Only allow one instance of Anope at once.
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp12
1 files changed, 12 insertions, 0 deletions
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);