mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +01:00
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.
This commit is contained in:
parent
95baa8dcc5
commit
89b55fa9bc
28
glib/gmain.c
28
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. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user