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.
This commit is contained in:
Harald Welte 2013-02-11 11:47:56 +01:00
parent ce94d971e1
commit e7e12cc9aa
1 changed files with 21 additions and 1 deletions

View File

@ -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);