diff options
author | Karthik Ramanan | 2014-02-21 05:12:58 -0600 |
---|---|---|
committer | Karthik Ramanan | 2014-04-12 03:25:39 -0500 |
commit | 70d2b36450e25614440babebaff445f653299203 (patch) | |
tree | 63194d9fe1f05b3c5ac08b41960dc01ad023d3ea | |
parent | 5f3254cffba51c83d66a93790b01a178021bcd34 (diff) | |
download | kmscube-70d2b36450e25614440babebaff445f653299203.tar.gz kmscube-70d2b36450e25614440babebaff445f653299203.tar.xz kmscube-70d2b36450e25614440babebaff445f653299203.zip |
added signal handler for cleanup
Signed-off-by: Karthik Ramanan <a0393906@ti.com>
-rw-r--r-- | kmscube.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -33,6 +33,7 @@ | |||
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | #include <errno.h> | 35 | #include <errno.h> |
36 | #include <signal.h> | ||
36 | 37 | ||
37 | #include <xf86drm.h> | 38 | #include <xf86drm.h> |
38 | #include <xf86drmMode.h> | 39 | #include <xf86drmMode.h> |
@@ -629,6 +630,21 @@ void print_usage() | |||
629 | printf("\t-c <id> : Display using connector_id [if not specified, use the first connected connector]\n"); | 630 | printf("\t-c <id> : Display using connector_id [if not specified, use the first connected connector]\n"); |
630 | } | 631 | } |
631 | 632 | ||
633 | int kms_signalhandler(int signum) | ||
634 | { | ||
635 | switch(signum) { | ||
636 | case SIGINT: | ||
637 | case SIGTERM: | ||
638 | printf("Handling signal number = %d\n", signum); | ||
639 | cleanup_kmscube(); | ||
640 | break; | ||
641 | default: | ||
642 | printf("Unknown signal\n"); | ||
643 | break; | ||
644 | } | ||
645 | exit(1); | ||
646 | } | ||
647 | |||
632 | int main(int argc, char *argv[]) | 648 | int main(int argc, char *argv[]) |
633 | { | 649 | { |
634 | fd_set fds; | 650 | fd_set fds; |
@@ -642,6 +658,9 @@ int main(int argc, char *argv[]) | |||
642 | int ret; | 658 | int ret; |
643 | int opt; | 659 | int opt; |
644 | 660 | ||
661 | signal(SIGINT, kms_signalhandler); | ||
662 | signal(SIGTERM, kms_signalhandler); | ||
663 | |||
645 | while ((opt = getopt(argc, argv, "ahc:")) != -1) { | 664 | while ((opt = getopt(argc, argv, "ahc:")) != -1) { |
646 | switch(opt) { | 665 | switch(opt) { |
647 | case 'a': | 666 | case 'a': |