diff options
author | Harald Welte <laforge@gnumonks.org> | 2013-02-11 11:47:56 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2013-02-11 11:47:56 +0100 |
commit | e7e12cc9aac2484f06cb85b38f51444d95695745 (patch) | |
tree | ce456154b0fab93d7a99d6e34dce9678f008e29d | |
parent | ce94d971e1223626c96ad32373ea4ff034233b50 (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.
-rw-r--r-- | src/main.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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); |