Do the thing™
This commit is contained in:
parent
fef893f60a
commit
f96a7201cf
3 changed files with 13 additions and 2 deletions
|
@ -576,6 +576,11 @@ void Util::Config::activate(){
|
||||||
is_active = true;
|
is_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tthread::mutex * mutabort = 0;
|
||||||
|
void Util::Config::setMutexAborter(void * mutex){
|
||||||
|
mutabort = (tthread::mutex*)mutex;
|
||||||
|
}
|
||||||
|
|
||||||
/// Basic signal handler. Sets is_active to false if it receives
|
/// Basic signal handler. Sets is_active to false if it receives
|
||||||
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
|
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
|
||||||
/// signal, and ignores all other signals.
|
/// signal, and ignores all other signals.
|
||||||
|
@ -584,8 +589,11 @@ void Util::Config::signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
|
||||||
case SIGINT: // these three signals will set is_active to false.
|
case SIGINT: // these three signals will set is_active to false.
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
if (serv_sock_pointer){serv_sock_pointer->close();}
|
if (!mutabort || mutabort->try_lock()){
|
||||||
if (stdin){fclose(stdin);}
|
if (serv_sock_pointer){serv_sock_pointer->close();}
|
||||||
|
if (stdin){fclose(stdin);}
|
||||||
|
if (mutabort){mutabort->unlock();}
|
||||||
|
}
|
||||||
#if DEBUG >= DLVL_DEVEL
|
#if DEBUG >= DLVL_DEVEL
|
||||||
static int ctr = 0;
|
static int ctr = 0;
|
||||||
if (!is_active && ++ctr > 4){BACKTRACE;}
|
if (!is_active && ++ctr > 4){BACKTRACE;}
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace Util{
|
||||||
static void signal_handler(int signum, siginfo_t *sigInfo, void *ignore);
|
static void signal_handler(int signum, siginfo_t *sigInfo, void *ignore);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void setMutexAborter(void * mutex);
|
||||||
// variables
|
// variables
|
||||||
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
|
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
|
||||||
static bool is_restarting; ///< Set to true when restarting, set to false on boot.
|
static bool is_restarting; ///< Set to true when restarting, set to false on boot.
|
||||||
|
|
|
@ -403,6 +403,7 @@ int main_loop(int argc, char **argv){
|
||||||
Controller::updateBandwidthConfig();
|
Controller::updateBandwidthConfig();
|
||||||
createAccount(Controller::conf.getString("account"));
|
createAccount(Controller::conf.getString("account"));
|
||||||
Controller::conf.activate(); // activate early, so threads aren't killed.
|
Controller::conf.activate(); // activate early, so threads aren't killed.
|
||||||
|
Controller::conf.setMutexAborter(&Controller::configMutex);
|
||||||
|
|
||||||
#if !defined(__CYGWIN__) && !defined(_WIN32)
|
#if !defined(__CYGWIN__) && !defined(_WIN32)
|
||||||
{
|
{
|
||||||
|
@ -630,6 +631,7 @@ int main(int argc, char **argv){
|
||||||
Controller::conf = Util::Config(argv[0]);
|
Controller::conf = Util::Config(argv[0]);
|
||||||
Util::Config::binaryType = Util::CONTROLLER;
|
Util::Config::binaryType = Util::CONTROLLER;
|
||||||
Controller::conf.activate();
|
Controller::conf.activate();
|
||||||
|
Controller::conf.setMutexAborter(&Controller::configMutex);
|
||||||
if (getenv("ATHEIST")){return main_loop(argc, argv);}
|
if (getenv("ATHEIST")){return main_loop(argc, argv);}
|
||||||
uint64_t reTimer = 0;
|
uint64_t reTimer = 0;
|
||||||
while (Controller::conf.is_active){
|
while (Controller::conf.is_active){
|
||||||
|
|
Loading…
Add table
Reference in a new issue