Use unique_ptr for InspIRCd::Config.

This commit is contained in:
Sadie Powell 2024-09-19 13:08:26 +01:00
parent 4c9e3aeb8b
commit 2ab1281c4d
4 changed files with 16 additions and 22 deletions

View File

@ -279,7 +279,7 @@ private:
/** Ensures that connect classes are well formed.
* @param current The current server config that is about to be replaced.
*/
void CrossCheckConnectBlocks(ServerConfig* current);
void CrossCheckConnectBlocks(const std::unique_ptr<ServerConfig>& current);
/** Ensures that oper accounts, oper types, and oper classes are well formed. */
void CrossCheckOperBlocks();
@ -511,7 +511,7 @@ public:
ServerConfig();
/** Apply configuration changes from the old configuration. */
void Apply(ServerConfig* old, const std::string& useruid);
void Apply(const std::unique_ptr<ServerConfig>& old, const std::string& useruid);
/** Get a list of configuration tags by name.
* @param tag The name of the tags to get.
@ -563,7 +563,7 @@ class CoreExport ConfigReaderThread final
{
private:
/** The new server configuration. */
ServerConfig* Config = new ServerConfig();
std::unique_ptr<ServerConfig> Config;
/** Whether the config has been read yet. */
std::atomic_bool done = { false };
@ -579,15 +579,11 @@ public:
const std::string UUID;
ConfigReaderThread(const std::string& uuid)
: UUID(uuid)
: Config(std::make_unique<ServerConfig>())
, UUID(uuid)
{
}
~ConfigReaderThread() override
{
delete Config;
}
/** Whether the configuration has been read yet. */
bool IsDone() { return done.load(); }
};

View File

@ -222,7 +222,7 @@ public:
UserManager Users;
/** The server configuration. */
ServerConfig* Config = nullptr;
std::unique_ptr<ServerConfig> Config;
/* If non-nullptr then the thread that is reading the server configuration on rehash. */
ConfigReaderThread* ConfigThread = nullptr;

View File

@ -195,7 +195,7 @@ void ServerConfig::CrossCheckOperBlocks()
}
}
void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
void ServerConfig::CrossCheckConnectBlocks(const std::unique_ptr<ServerConfig>& current)
{
typedef std::map<std::pair<std::string, ConnectClass::Type>, std::shared_ptr<ConnectClass>> ClassMap;
ClassMap oldBlocksByMask;
@ -422,7 +422,7 @@ void ServerConfig::Read()
}
}
void ServerConfig::Apply(ServerConfig* old, const std::string& useruid)
void ServerConfig::Apply(const std::unique_ptr<ServerConfig>& old, const std::string& useruid)
{
valid = true;
if (old)
@ -687,12 +687,12 @@ void ConfigReaderThread::OnStart()
void ConfigReaderThread::OnStop()
{
ServerConfig* old = ServerInstance->Config;
ServerInstance->Logs.Normal("CONFIG", "Switching to new configuration...");
ServerInstance->Config = this->Config;
Config->Apply(old, UUID);
if (Config->valid)
std::swap(ServerInstance->Config, this->Config);
ServerInstance->Config->Apply(this->Config, UUID);
if (ServerInstance->Config->valid)
{
/*
* Apply the changed configuration from the rehash.
@ -736,17 +736,15 @@ void ConfigReaderThread::OnStop()
user->WriteNotice("Cannot open log files: " + ex.GetReason());
}
if (Config->RawLog && !old->RawLog)
if (!Config->RawLog && ServerInstance->Config->RawLog)
{
for (auto* luser : ServerInstance->Users.GetLocalUsers())
Log::NotifyRawIO(luser, MessageType::PRIVMSG);
}
Config = old;
}
else
{
// whoops, abort!
ServerInstance->Config = old;
std::swap(ServerInstance->Config, this->Config);
}
}

View File

@ -405,7 +405,7 @@ void InspIRCd::Cleanup()
}
stdalgo::delete_zero(this->FakeClient);
stdalgo::delete_zero(this->XLines);
stdalgo::delete_zero(this->Config);
this->Config.reset(nullptr);
SocketEngine::Deinit();
Logs.CloseLogs();
}
@ -442,7 +442,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
IncreaseCoreDumpSize();
SocketEngine::Init();
this->Config = new ServerConfig;
this->Config = std::make_unique<ServerConfig>();
dynamic_reference_base::reset_all();
this->XLines = new XLineManager;