summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2023-08-17 23:05:22 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2023-08-17 23:05:22 +0000
commit0c63639723cd60492d2688bad82e734c03428663 (patch)
tree3ff35dc8a86b6216ad1de7fd6be36d30e012401f
parent95baa8dcc5a08ff04188de0a7902aa0fcec2699e (diff)
parent89b55fa9bca41e0b6ca6f4703a201af94e97279e (diff)
downloadglib-0c63639723cd60492d2688bad82e734c03428663.tar.gz
Merge branch 'th/gchildwatch-fail-message' into 'main'
[th/gchildwatch-fail-message] gmain: improve g_warning() for failure in g_child_watch_dispatch() See merge request GNOME/glib!3542
-rw-r--r--glib/gmain.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index e4378177d..8400e9726 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -5922,17 +5922,20 @@ g_child_watch_dispatch (GSource *source,
}
else
{
- g_debug (G_STRLOC ": pidfd signaled but pid %d didn't exit",
+ g_debug (G_STRLOC ": pidfd signaled but pid %" G_PID_FORMAT " didn't exit",
child_watch_source->pid);
return TRUE;
}
}
else
{
- /* Unknown error. We got signaled that the process might be exited,
- * but now we failed to reap it? Assume the process is gone and proceed. */
- g_warning (G_STRLOC ": pidfd signaled ready but failed for pid %d",
- child_watch_source->pid);
+ int errsv = errno;
+
+ g_warning (G_STRLOC ": waitid(pid:%" G_PID_FORMAT ", pidfd=%d) failed: %s (%d). %s",
+ child_watch_source->pid, child_watch_source->poll.fd, g_strerror (errsv), errsv,
+ "See documentation of g_child_watch_source_new() for possible causes.");
+
+ /* Assume the process is gone and proceed. */
child_exited = TRUE;
}
}
@@ -5951,6 +5954,9 @@ g_child_watch_dispatch (GSource *source,
pid = waitpid (child_watch_source->pid, &wstatus, WNOHANG);
+ if (G_UNLIKELY (pid < 0 && errno == EINTR))
+ goto waitpid_again;
+
if (pid == 0)
{
/* Not exited yet. Wait longer. */
@@ -5959,13 +5965,15 @@ g_child_watch_dispatch (GSource *source,
if (pid > 0)
wait_status = wstatus;
- else if (errno == ECHILD)
- g_warning ("GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). See the documentation of g_child_watch_source_new() for possible causes.");
- else if (errno == EINTR)
- goto waitpid_again;
else
{
- /* Unexpected error. Whatever happened, we are done waiting for this child. */
+ int errsv = errno;
+
+ g_warning (G_STRLOC ": waitpid(pid:%" G_PID_FORMAT ") failed: %s (%d). %s",
+ child_watch_source->pid, g_strerror (errsv), errsv,
+ "See documentation of g_child_watch_source_new() for possible causes.");
+
+ /* Assume the process is gone and proceed. */
}
}
}