diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-28 19:53:02 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-05-17 13:09:54 +0200 |
commit | 8b3211b70b544d0f2048ef59e1d8070e9ab38f79 (patch) | |
tree | 5c86897b3f88dd61b1a180b2351ca133a601b1dd | |
parent | b84e558d9febe9326fa4c479eed3238d0dbbf150 (diff) | |
download | glib-8b3211b70b544d0f2048ef59e1d8070e9ab38f79.tar.gz |
gmain: drop redundant using_pidfd field from GChildWatchSource
It's redundant, which leads to impossible code like:
if (child_watch_source->using_pidfd)
{
if (child_watch_source->poll.fd >= 0)
close (child_watch_source->poll.fd);
-rw-r--r-- | glib/gmain.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/glib/gmain.c b/glib/gmain.c index 6ba6fa02e..524a1bad9 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -374,11 +374,11 @@ struct _GChildWatchSource { GSource source; GPid pid; - /* @poll is always used on Windows, and used on Unix iff @using_pidfd is set: */ + /* @poll is always used on Windows. + * On Unix, poll.fd will be negative if PIDFD is unavailable. */ GPollFD poll; #ifndef G_OS_WIN32 gboolean child_maybe_exited; - gboolean using_pidfd; #endif /* G_OS_WIN32 */ }; @@ -5514,7 +5514,10 @@ g_child_watch_prepare (GSource *source, child_watch_source = (GChildWatchSource *) source; - return !child_watch_source->using_pidfd && g_atomic_int_get (&child_watch_source->child_maybe_exited); + if (child_watch_source->poll.fd >= 0) + return FALSE; + + return g_atomic_int_get (&child_watch_source->child_maybe_exited); } #endif /* G_OS_WIN32 */ } @@ -5531,7 +5534,7 @@ g_child_watch_check (GSource *source) child_exited = child_watch_source->poll.revents & G_IO_IN; #else /* G_OS_WIN32 */ #ifdef HAVE_PIDFD - if (child_watch_source->using_pidfd) + if (child_watch_source->poll.fd >= 0) { child_exited = child_watch_source->poll.revents & G_IO_IN; return child_exited; @@ -5549,10 +5552,9 @@ g_child_watch_finalize (GSource *source) #ifndef G_OS_WIN32 GChildWatchSource *child_watch_source = (GChildWatchSource *) source; - if (child_watch_source->using_pidfd) + if (child_watch_source->poll.fd >= 0) { - if (child_watch_source->poll.fd >= 0) - close (child_watch_source->poll.fd); + close (child_watch_source->poll.fd); return; } @@ -5900,7 +5902,7 @@ g_child_watch_dispatch (GSource *source, wait_status = -1; #ifdef HAVE_PIDFD - if (child_watch_source->using_pidfd) + if (child_watch_source->poll.fd >= 0) { siginfo_t child_info = { 0, @@ -6085,17 +6087,15 @@ g_child_watch_source_new (GPid pid) * better than SIGCHLD. */ child_watch_source->poll.fd = (int) syscall (SYS_pidfd_open, pid, 0); - errsv = errno; if (child_watch_source->poll.fd >= 0) { - child_watch_source->using_pidfd = TRUE; child_watch_source->poll.events = G_IO_IN; g_source_add_poll (source, &child_watch_source->poll); - return source; } + errsv = errno; g_debug ("pidfd_open(%" G_PID_FORMAT ") failed with error: %s", pid, g_strerror (errsv)); /* Fall through; likely the kernel isn’t new enough to support pidfd_open() */ |