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>
This commit is contained in:
Pekka Paalanen 2011-12-13 12:09:09 +02:00
parent 3429a72597
commit 88e60fc2ba
2 changed files with 36 additions and 2 deletions

View File

@ -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 @@ event_mask_update(uint32_t mask, void *data)
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 @@ main(int argc, char **argv)
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;
}

View File

@ -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 @@ create_display(void)
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;
}