summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-02-11 11:47:56 +0100
committerHarald Welte <laforge@gnumonks.org>2013-02-11 11:47:56 +0100
commite7e12cc9aac2484f06cb85b38f51444d95695745 (patch)
treece456154b0fab93d7a99d6e34dce9678f008e29d /src/main.c
parentce94d971e1223626c96ad32373ea4ff034233b50 (diff)
gapk: make sure the output file is closed/flushed on ctrl+c
This is useful particularly in case you are reading from RTP and writing to a file, and don't want truncated codec frames in your file.
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);