From 76661aa0cb822acdcd34a88fe449eb42e4588d42 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 17 Apr 2024 14:00:02 -0500 Subject: [PATCH] Don't use atexit anymore It turns out we only run the cleanup code in a few of the exit paths, so let's do it explicitly. --- main.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index 219043b..8fdd196 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,6 @@ void on_call_retract(const char *chat_id, void *dummy) { (void)dummy; snikket_release(chat_id); puts("Hung up..."); - chat = NULL; // So we don't call hangup again if (!exiting) exit(0); } @@ -41,7 +40,11 @@ void on_call_retract(const char *chat_id, void *dummy) { void sigint_handler(int sig) { (void)sig; puts("Hang up..."); - exit(0); + exiting = true; + snikket_chat_hangup(chat); + sleep(3); // Give time for hangup to send, etc + + _exit(0); } // Audio track got some from the other side, so let's play it @@ -176,21 +179,6 @@ void on_password_needed(void *client, void *password) { snikket_release(client); } -void at_exit(void) { - exiting = true; - - // If it was us, send the hangup signal - if (chat) { - snikket_chat_hangup(chat); - sleep(3); // Give time for hangup to send, etc - } - - // We could release stuff here, but we're gonna exit anyway - - // Stop the SDK, no waiting - snikket_stop(false); -} - int main(int argc, const char **argv) { const char *err; @@ -208,9 +196,6 @@ int main(int argc, const char **argv) { return 1; } - // Set cleanup hook - atexit(&at_exit); - // And make a persistence layer void *persistence = snikket_persistence_dummy_new(); @@ -255,5 +240,6 @@ int main(int argc, const char **argv) { if (dtmf) snikket_jingle_dtmf_sender_insert_dtmf(dtmf, tone); } + sigint_handler(SIGINT); return 0; } -- 2.45.2