mirror of
https://github.com/anope/anope.git
synced 2026-06-28 09:46:38 +02:00
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
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user