summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-09-20 12:27:00 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-09-20 12:27:00 +0200
commitc6d58023d20e4e7a7c4a52294f3fdf17738f76c9 (patch)
tree205bedb6051db8424ae2e5eac39a9f489de4770f
parent7c9eb7f93e7f8a5c507d5986842b4dbe33f896e8 (diff)
downloadlibuca-c6d58023d20e4e7a7c4a52294f3fdf17738f76c9.tar.gz
libuca-c6d58023d20e4e7a7c4a52294f3fdf17738f76c9.tar.bz2
libuca-c6d58023d20e4e7a7c4a52294f3fdf17738f76c9.tar.xz
libuca-c6d58023d20e4e7a7c4a52294f3fdf17738f76c9.zip
Add: signal handler for SIGINT
With `grab`, libuca wasn't closed down properly when pressing C-c which is the only "normal" way to stop it.
-rw-r--r--test/grab.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/test/grab.c b/test/grab.c
index f7a7548..005365d 100644
--- a/test/grab.c
+++ b/test/grab.c
@@ -1,15 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
#include "uca.h"
#define handle_error(errno) {if ((errno) != UCA_NO_ERROR) printf("error at <%s:%i>\n", \
__FILE__, __LINE__);}
+static struct uca *u = NULL;
+
+void sigint_handler(int signal)
+{
+ printf("Closing down libuca\n");
+ handle_error(uca_cam_stop_recording(u->cameras));
+ uca_destroy(u);
+ exit(signal);
+}
int main(int argc, char *argv[])
{
- struct uca *u = uca_init(NULL);
+ (void) signal(SIGINT, sigint_handler);
+
+ u = uca_init(NULL);
if (u == NULL) {
printf("Couldn't find a camera\n");
return 1;