compositor: Add missing SIGCHLD handler 23/28023/1
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 20 Sep 2022 11:34:31 +0000 (14:34 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Fri, 23 Sep 2022 15:15:11 +0000 (18:15 +0300)
We seem to be missing a SIGCHLD signal handlers so this patch
adds one similarity to what weston has.

Bug-AGL: SPEC-4570

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I137af4199c3d543fed940bbe289989095b114b74

src/compositor.c
src/ivi-compositor.h
src/shell.c

index dbc89e2..add78af 100644 (file)
@@ -1608,7 +1608,7 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
        char *cmdline;
        struct wl_display *display = NULL;
        struct wl_event_loop *loop;
-       struct wl_event_source *signals[2] = { 0 };
+       struct wl_event_source *signals[3] = { 0 };
        struct weston_config_section *section;
        /* Command line options */
        char *backend = NULL;
@@ -1709,6 +1709,8 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
                                              display);
        signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
                                              display);
+       signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
+                                             display);
 
        for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
                if (!signals[i])
index ebbcc17..3cca0a0 100644 (file)
@@ -480,5 +480,7 @@ void
 ivi_shell_activate_surface(struct ivi_surface *ivi_surf,
                           struct ivi_shell_seat *ivi_seat,
                           uint32_t flags);
+int
+sigchld_handler(int signal_number, void *data);
 
 #endif
index cb6e592..96f5c63 100644 (file)
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 #include <libweston/libweston.h>
 #include <libweston/config-parser.h>
@@ -928,6 +929,37 @@ struct process_info {
        char *path;
 };
 
+int
+sigchld_handler(int signal_number, void *data)
+{
+       struct weston_process *p;
+       struct ivi_compositor *ivi = data;
+       int status;
+       pid_t pid;
+
+       while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+               wl_list_for_each(p, &ivi->child_process_list, link) {
+                       if (p->pid == pid)
+                               break;
+               }
+
+               if (&p->link == &ivi->child_process_list) {
+                       weston_log("unknown child process exited\n");
+                       continue;
+               }
+
+               wl_list_remove(&p->link);
+               wl_list_init(&p->link);
+               p->cleanup(p, status);
+       }
+
+       if (pid < 0 && errno != ECHILD)
+               weston_log("waitpid error %s\n", strerror(errno));
+
+       return 1;
+}
+
+
 static void
 process_handle_sigchld(struct weston_process *process, int status)
 {