0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-16 01:26:58 +01:00

construct: Simplify various behavior based on runlevel.

This commit is contained in:
Jason Volk 2018-05-15 15:11:08 -07:00
parent 97f38507e0
commit b2b5d6abce
2 changed files with 19 additions and 23 deletions

View file

@ -105,7 +105,7 @@ try
ircd::runlevel == ircd::runlevel::HALT; ircd::runlevel == ircd::runlevel::HALT;
}); });
if(ircd::runlevel == ircd::runlevel::HALT) if(ircd::runlevel != ircd::runlevel::RUN)
return; return;
const unwind atexit([] const unwind atexit([]

View file

@ -232,10 +232,10 @@ enable_coredumps()
} }
#endif #endif
static bool handle_quit(); static void handle_quit();
static bool handle_interruption(); static void handle_interruption();
static bool handle_hangup(); static void handle_hangup();
static bool handle(const int &signum); static void handle(const int &signum);
void void
sigfd_handler(const boost::system::error_code &ec, sigfd_handler(const boost::system::error_code &ec,
@ -258,13 +258,20 @@ noexcept
throw std::runtime_error(ec.message()); throw std::runtime_error(ec.message());
} }
if(!handle(signum)) handle(signum);
return;
sigs.async_wait(sigfd_handler); switch(ircd::runlevel)
{
case ircd::runlevel::QUIT:
case ircd::runlevel::FAULT:
return;
default:
sigs.async_wait(sigfd_handler);
}
} }
bool void
handle(const int &signum) handle(const int &signum)
{ {
switch(signum) switch(signum)
@ -273,17 +280,15 @@ handle(const int &signum)
case SIGHUP: return handle_hangup(); case SIGHUP: return handle_hangup();
case SIGQUIT: return handle_quit(); case SIGQUIT: return handle_quit();
case SIGTERM: return handle_quit(); case SIGTERM: return handle_quit();
default: return true;
} }
} }
bool void
handle_quit() handle_quit()
try try
{ {
console_cancel(); console_cancel();
ircd::quit(); ircd::quit();
return false;
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
@ -291,16 +296,13 @@ catch(const std::exception &e)
{ {
"SIGQUIT handler: %s", e.what() "SIGQUIT handler: %s", e.what()
}; };
return true;
} }
bool void
handle_hangup() handle_hangup()
try try
{ {
console_hangup(); console_hangup();
return true;
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
@ -308,11 +310,9 @@ catch(const std::exception &e)
{ {
"SIGHUP handler: %s", e.what() "SIGHUP handler: %s", e.what()
}; };
return true;
} }
bool void
handle_interruption() handle_interruption()
try try
{ {
@ -320,8 +320,6 @@ try
console_cancel(); console_cancel();
else else
console_spawn(); console_spawn();
return true;
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
@ -329,6 +327,4 @@ catch(const std::exception &e)
{ {
"SIGINT handler: %s", e.what() "SIGINT handler: %s", e.what()
}; };
return true;
} }