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-shm.c b/clients/simple-shm.c
index 8a760ae..19dab94 100644
--- a/clients/simple-shm.c
+++ b/clients/simple-shm.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <signal.h>
 
 #include <wayland-client.h>
 #include <wayland-egl.h>
@@ -208,19 +209,35 @@
 	return display;
 }
 
+static int running = 1;
+
+static void
+signal_int(int signum)
+{
+	running = 0;
+}
+
 int
 main(int argc, char **argv)
 {
+	struct sigaction sigint;
 	struct display *display;
 	struct window *window;
 
 	display = create_display();
 	window = create_window(display, 250, 250);
 
+	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-shm exiting\n");
+
 	return 0;
 }