odph_linux_process_wait_n():
This patch helps catch child abnormal termination by breaking out
of the wait()-loop on error.

Examine what caused a forked child process to terminate. Do not wait()
for other children if the termination status indicates error in the
child, return -1 instead. Children that are not waited for will be
terminated by the SIGTERM signal once the parent exits (requested by
the prctl(PR_SET_PDEATHSIG, SIGTERM) call after child fork) even if the
parent does not perform any explicit clean-up actions.

Signed-off-by: Carl Wallen <[email protected]>
---
 helper/linux.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/helper/linux.c b/helper/linux.c
index 3d5da18..6e70206 100644
--- a/helper/linux.c
+++ b/helper/linux.c
@@ -224,7 +224,21 @@ int odph_linux_process_wait_n(odph_linux_process_t 
*proc_tbl, int num)
                }
 
                if (j == num) {
-                       ODPH_ERR("Bad pid\n");
+                       ODPH_ERR("Bad pid:%d\n", (int)pid);
+                       return -1;
+               }
+
+               /* Examine the child process' termination status */
+               if (WIFEXITED(status) && WEXITSTATUS(status) != EXIT_SUCCESS) {
+                       ODPH_ERR("Child exit status:%d (pid:%d)\n",
+                                WEXITSTATUS(status), (int)pid);
+                       return -1;
+               }
+               if (WIFSIGNALED(status)) {
+                       int signo = WTERMSIG(status);
+
+                       ODPH_ERR("Child term signo:%d - %s (pid:%d)\n",
+                                signo, strsignal(signo), (int)pid);
                        return -1;
                }
        }
-- 
2.1.4

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to