From 0ce088277293ac4b209be0f1b1c1f3dd3c5ee103 Mon Sep 17 00:00:00 2001 From: Arvind Samptur Date: Mon, 23 Sep 2002 06:45:10 +0000 Subject: [PATCH] when the child fails we need to reap it to avoid a zombie. This would 2002-09-23 Arvind Samptur * glib/gspawn.c (fork_exec_with_pipes) : when the child fails we need to reap it to avoid a zombie. This would happen in case of g_spawn_sync. Fixes #92658 --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-12 | 5 +++++ ChangeLog.pre-2-2 | 5 +++++ ChangeLog.pre-2-4 | 5 +++++ ChangeLog.pre-2-6 | 5 +++++ ChangeLog.pre-2-8 | 5 +++++ glib/gspawn.c | 22 +++++++++++++++++++++- 8 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 32165bd..0095086 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 32165bd..0095086 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +2002-09-23 Arvind Samptur + * glib/gspawn.c (fork_exec_with_pipes) : when the child fails + we need to reap it to avoid a zombie. This would + happen in case of g_spawn_sync. Fixes #92658 + 2002-09-20 Matthias Clasen * glib/gscanner.c (g_scanner_msg_handler): Don't print diff --git a/glib/gspawn.c b/glib/gspawn.c index d8ed1d9..3df45f4 100644 --- a/glib/gspawn.c +++ b/glib/gspawn.c @@ -961,7 +961,7 @@ fork_exec_with_pipes (gboolean intermediate_child, gint *standard_error, GError **error) { - gint pid; + gint pid = -1; gint stdin_pipe[2] = { -1, -1 }; gint stdout_pipe[2] = { -1, -1 }; gint stderr_pipe[2] = { -1, -1 }; @@ -1219,6 +1219,26 @@ fork_exec_with_pipes (gboolean intermediate_child, } cleanup_and_fail: + + /* There was an error from the Child, reap the child to avoid it being + a zombie. + */ + + if (pid > 0) + { + wait_failed: + if (waitpid (pid, NULL, 0) < 0) + { + if (errno == EINTR) + goto wait_failed; + else if (errno == ECHILD) + ; /* do nothing, child already reaped */ + else + g_warning ("waitpid() should not fail in " + "'fork_exec_with_pipes'"); + } + } + close_and_invalidate (&child_err_report_pipe[0]); close_and_invalidate (&child_err_report_pipe[1]); close_and_invalidate (&child_pid_report_pipe[0]); -- 2.7.4