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:
+18
-1
@@ -26,6 +26,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wayland-egl.h>
|
#include <wayland-egl.h>
|
||||||
@@ -307,9 +308,18 @@ event_mask_update(uint32_t mask, void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int running = 1;
|
||||||
|
|
||||||
|
static void
|
||||||
|
signal_int(int signum)
|
||||||
|
{
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
struct sigaction sigint;
|
||||||
struct display display = { 0 };
|
struct display display = { 0 };
|
||||||
struct window window = { 0 };
|
struct window window = { 0 };
|
||||||
|
|
||||||
@@ -333,10 +343,17 @@ main(int argc, char **argv)
|
|||||||
create_surface(&window);
|
create_surface(&window);
|
||||||
init_gl(&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);
|
redraw(&window, NULL, 0);
|
||||||
|
|
||||||
while (true)
|
while (running)
|
||||||
wl_display_iterate(display.display, display.mask);
|
wl_display_iterate(display.display, display.mask);
|
||||||
|
|
||||||
|
fprintf(stderr, "simple-egl exiting\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-1
@@ -28,6 +28,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wayland-egl.h>
|
#include <wayland-egl.h>
|
||||||
@@ -208,19 +209,35 @@ create_display(void)
|
|||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int running = 1;
|
||||||
|
|
||||||
|
static void
|
||||||
|
signal_int(int signum)
|
||||||
|
{
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
struct sigaction sigint;
|
||||||
struct display *display;
|
struct display *display;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
|
|
||||||
display = create_display();
|
display = create_display();
|
||||||
window = create_window(display, 250, 250);
|
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);
|
redraw(window, NULL, 0);
|
||||||
|
|
||||||
while (true)
|
while (running)
|
||||||
wl_display_iterate(display->display, display->mask);
|
wl_display_iterate(display->display, display->mask);
|
||||||
|
|
||||||
|
fprintf(stderr, "simple-shm exiting\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user