Skip to content

Commit

Permalink
HPCC-32072 Thor worker cleaner shutdown 2
Browse files Browse the repository at this point in the history
Signed-off-by: M Kelly <[email protected]>
  • Loading branch information
mckellyln committed Jul 29, 2024
1 parent 9371db4 commit 22f532e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
26 changes: 26 additions & 0 deletions system/jlib/jexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <sys/wait.h>
#include <sys/types.h>
#include <stddef.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#ifdef __linux__
#include <execinfo.h> // comment out if not present
Expand Down Expand Up @@ -1663,6 +1665,30 @@ void jlib_decl disableSEHtoExceptionMapping()
#endif
}

void jlib_decl raiseSignalInFuture(int signo, unsigned timeoutSec)
{
#ifndef _WIN32
int ret;
timer_t timerId;
struct sigevent sigev;
struct itimerspec itSpec;

sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = signo;
sigev.sigev_value.sival_ptr = &timerId;
sigev.sigev_notify_function = nullptr;
sigev.sigev_notify_attributes = NULL;

itSpec.it_value.tv_sec = timeoutSec;
itSpec.it_value.tv_nsec = 0;
itSpec.it_interval.tv_sec = 0;
itSpec.it_interval.tv_nsec = 0;

ret = timer_create(CLOCK_MONOTONIC, &sigev, &timerId);
if (!ret)
timer_settime(timerId, 0, &itSpec, 0);
#endif
}

StringBuffer & formatSystemError(StringBuffer & out, unsigned errcode)
{
Expand Down
1 change: 1 addition & 0 deletions system/jlib/jexcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void jlib_decl disableSEHtoExceptionMapping();

void jlib_decl *setSEHtoExceptionHandler(IExceptionHandler *handler); // sets handler and return old value

void jlib_decl raiseSignalInFuture(int signo, unsigned timeoutSec);

void jlib_decl setTerminateOnSEHInSystemDLLs(bool set=true);
void jlib_decl setTerminateOnSEH(bool set=true);
Expand Down
27 changes: 1 addition & 26 deletions thorlcr/slave/thslavemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,31 +283,6 @@ bool UnregisterSelf(IException *e)
return false;
}

void signalInFuture(int signo, unsigned timeoutSec)
{
#ifndef _WIN32
int ret;
timer_t timerId;
struct sigevent sigev;
struct itimerspec itSpec;

sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = signo;
sigev.sigev_value.sival_ptr = &timerId;
sigev.sigev_notify_function = nullptr;
sigev.sigev_notify_attributes = NULL;

itSpec.it_value.tv_sec = timeoutSec;
itSpec.it_value.tv_nsec = 0;
itSpec.it_interval.tv_sec = 0;
itSpec.it_interval.tv_nsec = 0;

ret = timer_create(CLOCK_MONOTONIC, &sigev, &timerId);
if (!ret)
timer_settime(timerId, 0, &itSpec, 0);
#endif
}

bool ControlHandler(ahType type)
{
static bool recvdSig = false;
Expand All @@ -319,7 +294,7 @@ bool ControlHandler(ahType type)
_exit(128+SIGTERM);
}
recvdSig = true;
signalInFuture(SIGTERM, 20);
raiseSignalInFuture(SIGTERM, 20);

if (ahInterrupt == type)
LOG(MCdebugProgress, "CTRL-C detected");
Expand Down

0 comments on commit 22f532e

Please sign in to comment.