[test] catch ^C correctly and clean up

This commit is contained in:
Milo Turner 2020-02-19 19:55:49 -05:00
parent 47c0560b13
commit e09947b953
2 changed files with 28 additions and 6 deletions

View File

@ -22,9 +22,11 @@ struct ax_ctxt* ax_new(void)
void ax_free(struct ax_ctxt* ax)
{
if (ax != NULL) {
ax__ctxt_cleanup(ax);
rgn_cleanup(ax->init_rgn);
}
}
const char* ax_get_error(struct ax_ctxt* ax)
{

View File

@ -1,12 +1,30 @@
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include "../src/ax.h"
#include "../src/ctxt.h"
#include "../src/backend.h"
struct ax_ctxt* ax = NULL;
static void cleanup()
{
ax_free(ax);
ax = NULL;
}
static void sigint_handler(int signum)
{
printf("\nCaught interrupt.\n");
cleanup();
exit(0);
}
int main(void)
{
struct ax_ctxt* ax = ax_new();
signal(SIGINT, sigint_handler);
ax = ax_new();
ax_set_logger(ax, 0, false);
int rv = 0;
@ -22,13 +40,15 @@ int main(void)
ax_log(ax, "Got here\n");
while (!ax__backend_is_shutdown(ax->bac)) {
ax__backend_wait_for_event(ax->bac);
ax__backend_step(ax->bac);
}
//cleanup:
if (rv != 0) {
printf("error: %s\n", ax_get_error(ax));
}
ax_free(ax);
cleanup();
return rv;
}