Send and receive candidate process ID 83/278683/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 25 Jul 2022 05:36:00 +0000 (14:36 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 25 Jul 2022 05:51:42 +0000 (14:51 +0900)
The hydra loader sends a launched candidate process ID to
launchpad-process-pool. When disposing the candidate process,
launchpad-process-pool checks whether the candidate process is running
or not to send SIGKILL signal. In the provious implementation, there is
a problem that the candidate process was not terminated while it's
executing.

Change-Id: I88fe989f80007d9c5b6f4bb381c5ad2d863be4e8
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/src/launchpad.c
src/lib/launchpad-hydra/src/launchpad_hydra.c

index 79bc21967f1e472aabd4424618a70cc7a6cef3a9..85e3c7a76008339ba44d707ffb6daaf71efdfd7c 100644 (file)
@@ -1451,6 +1451,8 @@ static bool __handle_hydra_client_event(int fd, io_condition_e cond,
                void *data)
 {
        candidate_process_context_t *cpc = data;
+       int recv_pid = -1;
+       int ret;
 
        if (cpc == NULL)
                return false;
@@ -1464,6 +1466,18 @@ static bool __handle_hydra_client_event(int fd, io_condition_e cond,
                return false;
        }
 
+       if (cond & IO_IN) {
+               ret = recv(cpc->hydra_fd, &recv_pid, sizeof(recv_pid),
+                               MSG_WAITALL);
+               if (ret == -1) {
+                       _E("recv() is failed. errno(%d)", errno);
+               } else {
+                       _W("candidate process: %d", recv_pid);
+                       if (recv_pid > 1)
+                               cpc->pid = recv_pid;
+               }
+       }
+
        return true;
 }
 
index aa737fd3aa5cb9a8fa2646f63211e403ffba3473..ba385dbd04d1847bd2eb4e7079801e39262f1c4d 100644 (file)
@@ -202,6 +202,10 @@ retry_recv:
 
        __context.candidate_pid = __fork_process(__run_loader, NULL);
        _D("[__HYDRA__] candidate process(%d)", __context.candidate_pid);
+       len = send(fd, &__context.candidate_pid,
+                       sizeof(__context.candidate_pid), MSG_NOSIGNAL);
+       if (len == -1)
+               _E("[__HYDRA__] send() is failed. errno(%d)", errno);
 
        return 0;
 err:
@@ -437,6 +441,10 @@ API int launchpad_hydra_main(int argc, char **argv,
 
        __context.candidate_pid = __fork_process(__run_loader, NULL);
        _D("[__HYDRA__] candidate process(%d)", __context.candidate_pid);
+       if (send(__context.client_fd, &__context.candidate_pid,
+                               sizeof(__context.candidate_pid),
+                               MSG_NOSIGNAL) == -1)
+               _E("[__HYDRA__] send() is failed. errno(%d)", errno);
 
        __run_loop();