From 41c56410ee389f8b2d330d89b5439d1d3366a7d8 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 2 Dec 2011 14:35:33 +0100 Subject: [PATCH] test_console: React on SIGINT Correctly terminate the application on SIGINT so the CRTC gets reset. Signed-off-by: David Herrmann --- tests/test_console.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test_console.c b/tests/test_console.c index 43d18eb..eb70463 100644 --- a/tests/test_console.c +++ b/tests/test_console.c @@ -45,8 +45,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -54,6 +56,13 @@ #include "console.h" #include "output.h" +static volatile sig_atomic_t terminate; + +static void sig_term(int sig) +{ + terminate = 1; +} + static int map_outputs(struct kmscon_compositor *comp, struct kmscon_console *con) { @@ -82,7 +91,6 @@ static int map_outputs(struct kmscon_compositor *comp, iter, ret); continue; } - sleep(1); } return 0; @@ -134,12 +142,14 @@ static int run_console(struct kmscon_compositor *comp) goto err_unref; } - while (1) { + while (!terminate) { kmscon_console_draw(con); map_outputs(comp, con); usleep(10000); } + printf("Terminating due to user request\n"); + err_unref: kmscon_console_unref(con); return ret; @@ -149,9 +159,15 @@ int main(int argc, char **argv) { struct kmscon_compositor *comp; int ret; + struct sigaction sig; setlocale(LC_ALL, ""); + memset(&sig, 0, sizeof(sig)); + sig.sa_handler = sig_term; + sigaction(SIGTERM, &sig, NULL); + sigaction(SIGINT, &sig, NULL); + ret = kmscon_compositor_new(&comp); if (ret) { printf("Cannot create compositor: %d\n", ret); -- 2.7.4