test_output: Catch SIGINT and SIGTERM
authorDavid Herrmann <dh.herrmann@googlemail.com>
Fri, 2 Dec 2011 14:10:07 +0000 (15:10 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Fri, 2 Dec 2011 14:10:07 +0000 (15:10 +0100)
Correctly handle SIGINT and SIGTERM. This will also reset the crtc so it won't
stay black if the application is killed.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
tests/test_output.c

index 7653f55..92b836e 100644 (file)
 #define GL_GLEXT_PROTOTYPES
 
 #include <inttypes.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <GL/gl.h>
 #include <GL/glext.h>
 #include "output.h"
 
+static void sig_term(int sig)
+{
+}
+
 static int set_outputs(struct kmscon_compositor *comp, int num, char **list)
 {
        struct kmscon_output *iter;
@@ -159,6 +165,12 @@ int main(int argc, char **argv)
 {
        struct kmscon_compositor *comp;
        int ret;
+       struct sigaction sig;
+
+       memset(&sig, 0, sizeof(sig));
+       sig.sa_handler = sig_term;
+       sigaction(SIGTERM, &sig, NULL);
+       sigaction(SIGINT, &sig, NULL);
 
        printf("Creating compositor...\n");
        ret = kmscon_compositor_new(&comp);