|
|
|
@ -53,6 +53,13 @@ namespace llarp
|
|
|
|
|
const char *key, const char *val)
|
|
|
|
|
{
|
|
|
|
|
Context *ctx = static_cast< Context * >(itr->user);
|
|
|
|
|
if(!strcmp(section, "system"))
|
|
|
|
|
{
|
|
|
|
|
if(!strcmp(key, "pidfile"))
|
|
|
|
|
{
|
|
|
|
|
ctx->SetPIDFile(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!strcmp(section, "router"))
|
|
|
|
|
{
|
|
|
|
|
if(!strcmp(key, "worker-threads") && !ctx->singleThreaded)
|
|
|
|
@ -81,6 +88,12 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Context::SetPIDFile(const std::string & fname)
|
|
|
|
|
{
|
|
|
|
|
pidfile = fname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
Context::LoadDatabase()
|
|
|
|
|
{
|
|
|
|
@ -174,9 +187,12 @@ namespace llarp
|
|
|
|
|
llarp::LogError("cannot run non configured context");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if(!WritePIDFile())
|
|
|
|
|
return 1;
|
|
|
|
|
// run
|
|
|
|
|
if(!router->Run(nodedb))
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
// run net io thread
|
|
|
|
|
llarp::LogInfo("running mainloop");
|
|
|
|
|
llarp_ev_loop_run_single_process(mainloop, worker, logic);
|
|
|
|
@ -184,6 +200,34 @@ namespace llarp
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Context::WritePIDFile() const
|
|
|
|
|
{
|
|
|
|
|
if(pidfile.size())
|
|
|
|
|
{
|
|
|
|
|
std::ofstream f(pidfile);
|
|
|
|
|
f << std::to_string(getpid());
|
|
|
|
|
return f.good();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Context::RemovePIDFile() const
|
|
|
|
|
{
|
|
|
|
|
if(pidfile.size())
|
|
|
|
|
{
|
|
|
|
|
fs::path f = pidfile;
|
|
|
|
|
std::error_code ex;
|
|
|
|
|
if(fs::exists(f, ex))
|
|
|
|
|
{
|
|
|
|
|
if(!ex)
|
|
|
|
|
fs::remove(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Context::HandleSignal(int sig)
|
|
|
|
|
{
|
|
|
|
@ -277,6 +321,7 @@ namespace llarp
|
|
|
|
|
delete logic;
|
|
|
|
|
logic = nullptr;
|
|
|
|
|
}
|
|
|
|
|
RemovePIDFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|