Skip to content

Commit

Permalink
core: added --no-atexit cli parameter
Browse files Browse the repository at this point in the history
- skip atexit callbacks execution from external libraries which may access
destroyed shm memory causing crash on shutdown

(cherry picked from commit 9f12d31)
  • Loading branch information
miconda committed Feb 12, 2021
1 parent be0e0fc commit 91ae115
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main.c
Expand Up @@ -208,7 +208,9 @@ Options:\n\
#ifdef USE_TCP
" -N Number of tcp child processes (default: equal to `-n')\n"
#endif
" -O nr Script optimization level (debugging option)\n\
" --no-atexit Skip atexit callbacks execution from external libraries\n\
which may access destroyed shm memory causing crash on shutdown\n\
-O nr Script optimization level (debugging option)\n\
-P file Create a pid file\n"
#ifdef USE_SCTP
" -Q Number of sctp child processes (default: equal to `-n')\n"
Expand Down Expand Up @@ -533,6 +535,7 @@ char *sr_memmng_shm = NULL;

static int *_sr_instance_started = NULL;

int ksr_no_atexit = 0;
/**
* return 1 if all child processes were forked
* - note: they might still be in init phase (i.e., child init)
Expand Down Expand Up @@ -735,7 +738,11 @@ void handle_sigs(void)
LM_NOTICE("Thank you for flying " NAME "!!!\n");
/* shutdown/kill all the children */
shutdown_children(SIGTERM, 1);
exit(0);
if(ksr_no_atexit==1) {
_exit(0);
} else {
exit(0);
}
break;

case SIGUSR1:
Expand Down Expand Up @@ -805,9 +812,17 @@ void handle_sigs(void)
/* exit */
shutdown_children(SIGTERM, 1);
if (WIFSIGNALED(chld_status)) {
exit(1);
if(ksr_no_atexit==1) {
_exit(1);
} else {
exit(1);
}
} else {
exit(0);
if(ksr_no_atexit==1) {
_exit(0);
} else {
exit(0);
}
}
break;

Expand Down Expand Up @@ -1933,6 +1948,7 @@ int main(int argc, char** argv)
{"modparam", required_argument, 0, KARGOPTVAL + 6},
{"log-engine", required_argument, 0, KARGOPTVAL + 7},
{"debug", required_argument, 0, KARGOPTVAL + 8},
{"no-atexit", no_argument, 0, KARGOPTVAL + 10},
{0, 0, 0, 0 }
};

Expand Down Expand Up @@ -2002,6 +2018,9 @@ int main(int argc, char** argv)
goto error;
}
break;
case KARGOPTVAL+10:
ksr_no_atexit = 1;
break;

default:
if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
Expand Down Expand Up @@ -2164,6 +2183,7 @@ int main(int argc, char** argv)
case KARGOPTVAL+6:
case KARGOPTVAL+7:
case KARGOPTVAL+8:
case KARGOPTVAL+10:
break;

/* long options */
Expand Down

0 comments on commit 91ae115

Please sign in to comment.