diff options
author | Thomas Haller <thaller@redhat.com> | 2023-08-17 17:52:32 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-08-17 19:12:23 +0200 |
commit | 89b55fa9bca41e0b6ca6f4703a201af94e97279e (patch) | |
tree | 3ff35dc8a86b6216ad1de7fd6be36d30e012401f | |
parent | 95baa8dcc5a08ff04188de0a7902aa0fcec2699e (diff) | |
download | glib-89b55fa9bca41e0b6ca6f4703a201af94e97279e.tar.gz |
gmain: improve g_warning() for failure in g_child_watch_dispatch()
Print the PID, the errno and the pidfd in case of an unexpected failure
in g_child_watch_dispatch().
This is always(?) caused by a bug in the user application. Also hint to
g_child_watch_source_new() documentation for possible causes.
Also use G_PID_FORMAT for printing GPid values.
-rw-r--r-- | glib/gmain.c | 28 |
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. */ } } } |