added signal handler for cleanup
authorKarthik Ramanan <a0393906@ti.com>
Fri, 21 Feb 2014 11:12:58 +0000 (16:42 +0530)
committerKarthik Ramanan <a0393906@ti.com>
Sat, 12 Apr 2014 08:25:39 +0000 (13:55 +0530)
Signed-off-by: Karthik Ramanan <a0393906@ti.com>
kmscube.c

index a37190959e99a51858a574b16e3749e04fc13ee5..bc2e89d19a772f623431b0fd832416db7f90e69e 100644 (file)
--- a/kmscube.c
+++ b/kmscube.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
+#include <signal.h>
 
 #include <xf86drm.h>
 #include <xf86drmMode.h>
@@ -629,6 +630,21 @@ void print_usage()
        printf("\t-c <id> : Display using connector_id [if not specified, use the first connected connector]\n");
 }
 
+int kms_signalhandler(int signum)
+{
+       switch(signum) {
+       case SIGINT:
+       case SIGTERM:
+               printf("Handling signal number = %d\n", signum);
+               cleanup_kmscube();
+               break;
+       default:
+               printf("Unknown signal\n");
+               break;
+       }
+       exit(1);
+}
+
 int main(int argc, char *argv[])
 {
        fd_set fds;
@@ -642,6 +658,9 @@ int main(int argc, char *argv[])
        int ret;
        int opt;
 
+       signal(SIGINT, kms_signalhandler);
+       signal(SIGTERM, kms_signalhandler);
+
        while ((opt = getopt(argc, argv, "ahc:")) != -1) {
                switch(opt) {
                case 'a':