~singpolyma/ccd

76661aa0cb822acdcd34a88fe449eb42e4588d42 — Stephen Paul Weber 4 months ago ea19096
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.
1 files changed, 6 insertions(+), 20 deletions(-)

M main.c
M main.c => main.c +6 -20
@@ 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;
}