server: add SIGINT to the loop 26/207126/1
authorlsj119 <lsj119@samsung.com>
Mon, 15 Apr 2019 23:49:37 +0000 (08:49 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 30 May 2019 08:32:24 +0000 (17:32 +0900)
Change-Id: I0e2687765a9d6fec1872917bd88e41fa9bd70fa7

src/bin/headless/headless_server.c

index c8602fa..59d7b76 100644 (file)
@@ -1,6 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
 #include <pepper.h>
 #include <headless_server.h>
 
+static int
+handle_sigint(int signal_number, void *data)
+{
+       struct wl_display *display = (struct wl_display *)data;
+       wl_display_terminate(display);
+
+       return 0;
+}
+
+static pepper_bool_t
+init_signal(pepper_compositor_t *compositor)
+{
+    struct wl_display *display;
+    struct wl_event_loop *loop;
+    struct wl_event_source *sigint;
+
+    display = pepper_compositor_get_display(compositor);
+    loop = wl_display_get_event_loop(display);
+       sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
+       if (!sigint)
+               return PEPPER_FALSE;
+
+    return PEPPER_TRUE;
+}
+
 int main(int argc, char *argv[])
 {
        const char *socket_name = NULL;
@@ -18,6 +47,9 @@ int main(int argc, char *argv[])
     /* Init Output */
     pepper_output_led_init(compositor);
 
+    /* Init Signal for SIGINT */
+    init_signal(compositor);
+
        /* run event loop */
        wl_display_run(pepper_compositor_get_display(compositor));