summaryrefslogtreecommitdiff
path: root/modules/database/db_flatfile.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-12-26 16:08:56 -0500
committerAdam <Adam@anope.org>2013-12-26 16:08:56 -0500
commit9bf9cfcf5e122f9f46ad096b9f979a95c10d2d4b (patch)
tree2436ffe46858057f79a704b7ddd355d2f01255bc /modules/database/db_flatfile.cpp
parent0c9750a22b51b64e3b020d12fccdd53da65df93c (diff)
If using db_flatfile:fork, don't allow multiple saves to happen at one time on shutdown/restart wait for any pending saves to finish
Diffstat (limited to 'modules/database/db_flatfile.cpp')
-rw-r--r--modules/database/db_flatfile.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index 9c40c88f4..ae5e35647 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -10,6 +10,10 @@
#include "module.h"
+#ifndef _WIN32
+#include <sys/wait.h>
+#endif
+
class SaveData : public Serialize::Data
{
public:
@@ -106,6 +110,8 @@ class DBFlatFile : public Module, public Pipe
std::map<Anope::string, std::list<Anope::string> > backups;
bool loaded;
+ int child_pid;
+
void BackupDatabase()
{
tm *tm = localtime(&Anope::CurTime);
@@ -161,11 +167,31 @@ class DBFlatFile : public Module, public Pipe
}
public:
- DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), last_day(0), loaded(false)
+ DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), last_day(0), loaded(false), child_pid(-1)
{
}
+#ifndef _WIN32
+ void OnRestart() anope_override
+ {
+ OnShutdown();
+ }
+
+ void OnShutdown() anope_override
+ {
+ if (child_pid > -1)
+ {
+ Log(this) << "Waiting for child to exit...";
+
+ int status;
+ waitpid(child_pid, &status, 0);
+
+ Log(this) << "Done";
+ }
+ }
+#endif
+
void OnNotify() anope_override
{
char buf[512];
@@ -174,6 +200,8 @@ class DBFlatFile : public Module, public Pipe
return;
buf[i] = 0;
+ child_pid = -1;
+
if (!*buf)
{
Log(this) << "Finished saving databases";
@@ -238,15 +266,24 @@ class DBFlatFile : public Module, public Pipe
void OnSaveDatabase() anope_override
{
+ if (child_pid > -1)
+ {
+ Log(this) << "Database save is already in progress!";
+ return;
+ }
+
BackupDatabase();
int i = -1;
#ifndef _WIN32
- if (Config->GetModule(this)->Get<bool>("fork"))
+ if (!Anope::Quitting && Config->GetModule(this)->Get<bool>("fork"))
{
i = fork();
if (i > 0)
+ {
+ child_pid = i;
return;
+ }
else if (i < 0)
Log(this) << "Unable to fork for database save";
}