GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC

The old code was creating a pipe and setting FD_CLOEXEC
non-atomically.

https://bugzilla.gnome.org/show_bug.cgi?id=649225
This commit is contained in:
Colin Walters 2011-05-02 15:42:51 -04:00
parent ed37970a04
commit c078223b38

View File

@ -193,35 +193,19 @@ g_cancellable_class_init (GCancellableClass *klass)
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
static void
set_fd_close_exec (int fd)
{
int flags;
flags = fcntl (fd, F_GETFD, 0);
if (flags != -1 && (flags & FD_CLOEXEC) == 0)
{
flags |= FD_CLOEXEC;
fcntl (fd, F_SETFD, flags);
}
}
static void static void
g_cancellable_open_pipe (GCancellable *cancellable) g_cancellable_open_pipe (GCancellable *cancellable)
{ {
GCancellablePrivate *priv; GCancellablePrivate *priv;
priv = cancellable->priv; priv = cancellable->priv;
if (pipe (priv->cancel_pipe) == 0) if (g_unix_pipe_flags (priv->cancel_pipe, FD_CLOEXEC, NULL))
{ {
/* Make them nonblocking, just to be sure we don't block /* Make them nonblocking, just to be sure we don't block
* on errors and stuff * on errors and stuff
*/ */
g_unix_set_fd_nonblocking (priv->cancel_pipe[0], TRUE, NULL); g_unix_set_fd_nonblocking (priv->cancel_pipe[0], TRUE, NULL);
g_unix_set_fd_nonblocking (priv->cancel_pipe[1], TRUE, NULL); g_unix_set_fd_nonblocking (priv->cancel_pipe[1], TRUE, NULL);
set_fd_close_exec (priv->cancel_pipe[0]);
set_fd_close_exec (priv->cancel_pipe[1]);
if (priv->cancelled) if (priv->cancelled)
{ {