diff --git a/src/main.c b/src/main.c index 6e6635956..8141f8de6 100644 --- a/src/main.c +++ b/src/main.c @@ -771,6 +771,8 @@ int main(int argc, char *argv[]) { signal(SIGUSR2, SIG_IGN); #endif /* _WIN32 */ + olsr_shutdown_registered = true; + /* Starting scheduler */ olsr_scheduler(); diff --git a/src/olsr.c b/src/olsr.c index 216996228..986044c1b 100644 --- a/src/olsr.c +++ b/src/olsr.c @@ -81,6 +81,8 @@ bool changes_neighborhood; bool changes_hna; bool changes_force; +bool olsr_shutdown_registered = false; + /*COLLECT startup sleeps caused by warnings*/ #ifdef OLSR_COLLECT_STARTUP_SLEEP @@ -576,7 +578,13 @@ olsr_exit(const char *msg, int val) olsr_cnf->exit_value = val; } - raise(SIGTERM); + /* Only take the orderly shutdown path once olsr_shutdown() is + * installed. Before that, SIGTERM still has its default disposition + * and raise() would kill us outright, so the exit() below would never + * run and the process would report 143 instead of val. */ + if (olsr_shutdown_registered) { + raise(SIGTERM); + } /* in case the signal handler was not setup yet */ exit(val); diff --git a/src/olsr.h b/src/olsr.h index 505231691..755228432 100644 --- a/src/olsr.h +++ b/src/olsr.h @@ -54,6 +54,8 @@ extern bool changes_neighborhood; extern bool changes_hna; extern bool changes_force; +extern bool olsr_shutdown_registered; + extern union olsr_ip_addr all_zero; void get_argc_argv(int *argc, char **argv[]);