diff mbox

[2/3] helper: linux: examine the cause for child process termination

Message ID 1446210967-23576-3-git-send-email-carl.wallen@nokia.com
State Accepted
Commit 8bc76ef7d5f9caf691ac23e584aa618cb39e0f7f
Headers show

Commit Message

Wallen, Carl (Nokia - FI/Espoo) Oct. 30, 2015, 1:16 p.m. UTC
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 <carl.wallen@nokia.com>
---
 helper/linux.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox

Patch

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;
 		}
 	}