aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index fd91d4b..dfe46dd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <getopt.h>
+#include <sys/signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -482,9 +483,26 @@ run(struct gapk_state *gs)
return frames > 0 ? 0 : rv;
}
+
+static struct gapk_state _gs, *gs = &_gs;
+
+static void signal_handler(int signal)
+{
+ switch (signal) {
+ case SIGINT:
+ fprintf(stderr, "catching sigint, closing files\n");
+ files_close(gs);
+ pq_destroy(gs->pq);
+ exit(0);
+ break;
+ default:
+ break;
+ }
+}
+
+
int main(int argc, char *argv[])
{
- struct gapk_state _gs, *gs = &_gs;
int rv;
/* Clear state */
@@ -528,6 +546,8 @@ int main(int argc, char *argv[])
if (rv)
goto error;
+ signal(SIGINT, &signal_handler);
+
/* Run the processing queue */
rv = run(gs);