mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-12 20:36:15 +01:00
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);
This commit is contained in:
parent
cecbb25eeb
commit
d5d6ef8f1b
23
glib/gmain.c
23
glib/gmain.c
@ -374,11 +374,11 @@ struct _GChildWatchSource
|
|||||||
{
|
{
|
||||||
GSource source;
|
GSource source;
|
||||||
GPid pid;
|
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;
|
GPollFD poll;
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
gboolean child_maybe_exited; /* (atomic) */
|
gboolean child_maybe_exited; /* (atomic) */
|
||||||
gboolean using_pidfd;
|
|
||||||
#endif /* G_OS_WIN32 */
|
#endif /* G_OS_WIN32 */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -5514,7 +5514,10 @@ g_child_watch_prepare (GSource *source,
|
|||||||
|
|
||||||
child_watch_source = (GChildWatchSource *) 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 */
|
#endif /* G_OS_WIN32 */
|
||||||
}
|
}
|
||||||
@ -5531,7 +5534,7 @@ g_child_watch_check (GSource *source)
|
|||||||
child_exited = child_watch_source->poll.revents & G_IO_IN;
|
child_exited = child_watch_source->poll.revents & G_IO_IN;
|
||||||
#else /* G_OS_WIN32 */
|
#else /* G_OS_WIN32 */
|
||||||
#ifdef HAVE_PIDFD
|
#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;
|
child_exited = child_watch_source->poll.revents & G_IO_IN;
|
||||||
return child_exited;
|
return child_exited;
|
||||||
@ -5549,10 +5552,9 @@ g_child_watch_finalize (GSource *source)
|
|||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
GChildWatchSource *child_watch_source = (GChildWatchSource *) source;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5900,7 +5902,7 @@ g_child_watch_dispatch (GSource *source,
|
|||||||
wait_status = -1;
|
wait_status = -1;
|
||||||
|
|
||||||
#ifdef HAVE_PIDFD
|
#ifdef HAVE_PIDFD
|
||||||
if (child_watch_source->using_pidfd)
|
if (child_watch_source->poll.fd >= 0)
|
||||||
{
|
{
|
||||||
siginfo_t child_info = {
|
siginfo_t child_info = {
|
||||||
0,
|
0,
|
||||||
@ -6085,17 +6087,15 @@ g_child_watch_source_new (GPid pid)
|
|||||||
* better than SIGCHLD.
|
* better than SIGCHLD.
|
||||||
*/
|
*/
|
||||||
child_watch_source->poll.fd = (int) syscall (SYS_pidfd_open, pid, 0);
|
child_watch_source->poll.fd = (int) syscall (SYS_pidfd_open, pid, 0);
|
||||||
errsv = errno;
|
|
||||||
|
|
||||||
if (child_watch_source->poll.fd >= 0)
|
if (child_watch_source->poll.fd >= 0)
|
||||||
{
|
{
|
||||||
child_watch_source->using_pidfd = TRUE;
|
|
||||||
child_watch_source->poll.events = G_IO_IN;
|
child_watch_source->poll.events = G_IO_IN;
|
||||||
g_source_add_poll (source, &child_watch_source->poll);
|
g_source_add_poll (source, &child_watch_source->poll);
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errsv = errno;
|
||||||
g_debug ("pidfd_open(%" G_PID_FORMAT ") failed with error: %s",
|
g_debug ("pidfd_open(%" G_PID_FORMAT ") failed with error: %s",
|
||||||
pid, g_strerror (errsv));
|
pid, g_strerror (errsv));
|
||||||
/* Fall through; likely the kernel isn’t new enough to support pidfd_open() */
|
/* Fall through; likely the kernel isn’t new enough to support pidfd_open() */
|
||||||
@ -6104,6 +6104,7 @@ g_child_watch_source_new (GPid pid)
|
|||||||
/* We can do that without atomic, as the source is not yet added in
|
/* We can do that without atomic, as the source is not yet added in
|
||||||
* unix_child_watches (which we do next under a lock). */
|
* unix_child_watches (which we do next under a lock). */
|
||||||
child_watch_source->child_maybe_exited = TRUE;
|
child_watch_source->child_maybe_exited = TRUE;
|
||||||
|
child_watch_source->poll.fd = -1;
|
||||||
|
|
||||||
G_LOCK (unix_signal_lock);
|
G_LOCK (unix_signal_lock);
|
||||||
ref_unix_signal_handler_unlocked (SIGCHLD);
|
ref_unix_signal_handler_unlocked (SIGCHLD);
|
||||||
|
Loading…
Reference in New Issue
Block a user