Skip to content

Commit

Permalink
Merge pull request #200 from P403n1x87/chore/return-signal-code
Browse files Browse the repository at this point in the history
chore: return negated signal number on signal
  • Loading branch information
P403n1x87 authored Sep 10, 2023
2 parents 8f5a1e8 + 7dbb39a commit f3ab6cf
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions src/austin.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ static int interrupt = FALSE;
static void
signal_callback_handler(int signum)
{
if (signum == SIGINT || signum == SIGTERM)
interrupt = SIGTERM;
switch(signum) {
case SIGINT:
case SIGTERM:
interrupt = -signum;
}
} /* signal_callback_handler */

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -213,51 +216,44 @@ do_child_processes(py_proc_t * py_proc) {

// ----------------------------------------------------------------------------
static inline int
handle_error() {
int retval = 0;

handle_error() {
log_d("Last error: %d :: %s", austin_errno, get_last_error());

if (interrupt == SIGTERM) {
retval = SIGTERM;
}
else {
retval = austin_errno;

switch(retval) {
case EPROCISTIMEOUT:
_msg(MTIMEOUT, pargs.attach_pid == 0 ? "run" : "attach to");
break;
#if defined PL_UNIX
case EPROCPERM:
_msg(MPERM);
break;
#endif
case EPROCFORK:
_msg(MFORK);
break;
case EPROCATTACH:
_msg(MATTACH);
break;
case EPROCNPID:
_msg(MNOPROC);
break;
case EPROC:
_msg(MNOPYTHON);
break;
case EPROCNOCHILDREN:
_msg(MNOCHILDREN);
break;
case ENOVERSION:
_msg(MNOVERSION);
break;
case EMEMCOPY:
// Ignore. At this point we expect remote memory reads to fail.
retval = EOK;
break;
default:
_msg(MERROR);
}
int retval = austin_errno;

switch(retval) {
case EPROCISTIMEOUT:
_msg(MTIMEOUT, pargs.attach_pid == 0 ? "run" : "attach to");
break;
#if defined PL_UNIX
case EPROCPERM:
_msg(MPERM);
break;
#endif
case EPROCFORK:
_msg(MFORK);
break;
case EPROCATTACH:
_msg(MATTACH);
break;
case EPROCNPID:
_msg(MNOPROC);
break;
case EPROC:
_msg(MNOPYTHON);
break;
case EPROCNOCHILDREN:
_msg(MNOCHILDREN);
break;
case ENOVERSION:
_msg(MNOVERSION);
break;
case EMEMCOPY:
// Ignore. At this point we expect remote memory reads to fail.
retval = EOK;
break;
default:
_msg(MERROR);
}

return retval;
Expand Down Expand Up @@ -416,6 +412,10 @@ int main(int argc, char ** argv) {

logger_close();

if (interrupt < 0)
// Interrupted by signal
retval = interrupt;

return retval;
} /* main */

Expand Down

0 comments on commit f3ab6cf

Please sign in to comment.