Do the thing™

This commit is contained in:
Thulinma 2024-05-30 12:56:59 +02:00
parent fef893f60a
commit f96a7201cf
3 changed files with 13 additions and 2 deletions

View file

@ -576,6 +576,11 @@ void Util::Config::activate(){
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
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
/// 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 SIGHUP:
case SIGTERM:
if (serv_sock_pointer){serv_sock_pointer->close();}
if (stdin){fclose(stdin);}
if (!mutabort || mutabort->try_lock()){
if (serv_sock_pointer){serv_sock_pointer->close();}
if (stdin){fclose(stdin);}
if (mutabort){mutabort->unlock();}
}
#if DEBUG >= DLVL_DEVEL
static int ctr = 0;
if (!is_active && ++ctr > 4){BACKTRACE;}

View file

@ -36,6 +36,7 @@ namespace Util{
static void signal_handler(int signum, siginfo_t *sigInfo, void *ignore);
public:
static void setMutexAborter(void * mutex);
// variables
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.