simple clients: add signal handler for clean exit

Add signal handler for SIGINT to simple-egl and simple-shm, so they can
be exited voluntarily, without killing them. Later we can add clean-up
code and destructors, and check with valgrind for leaks and errors.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index 13c33bd..f6b6cf4 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -26,6 +26,7 @@
 #include <stdbool.h>
 #include <math.h>
 #include <assert.h>
+#include <signal.h>
 
 #include <wayland-client.h>
 #include <wayland-egl.h>
@@ -307,9 +308,18 @@
 	return 0;
 }
 
+static int running = 1;
+
+static void
+signal_int(int signum)
+{
+	running = 0;
+}
+
 int
 main(int argc, char **argv)
 {
+	struct sigaction sigint;
 	struct display display = { 0 };
 	struct window  window  = { 0 };
 
@@ -333,10 +343,17 @@
 	create_surface(&window);
 	init_gl(&window);
 
+	sigint.sa_handler = signal_int;
+	sigemptyset(&sigint.sa_mask);
+	sigint.sa_flags = SA_RESETHAND;
+	sigaction(SIGINT, &sigint, NULL);
+
 	redraw(&window, NULL, 0);
 
-	while (true)
+	while (running)
 		wl_display_iterate(display.display, display.mask);
 
+	fprintf(stderr, "simple-egl exiting\n");
+
 	return 0;
 }