After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 649225 - GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-05-02 19:43 UTC by Colin Walters
Modified: 2011-05-03 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC (1.69 KB, patch)
2011-05-02 19:43 UTC, Colin Walters
accepted-commit_now Details | Review
g_unix_set_fd_nonblocking: New API to control file descriptor blocking state (5.44 KB, patch)
2011-05-03 13:55 UTC, Colin Walters
committed Details | Review
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC (1.50 KB, patch)
2011-05-03 13:55 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2011-05-02 19:43:37 UTC
The old code was creating a pipe and setting FD_CLOEXEC
non-atomically.
Comment 1 Colin Walters 2011-05-02 19:43:39 UTC
Created attachment 187078 [details] [review]
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC
Comment 2 Dan Winship 2011-05-02 20:45:54 UTC
Comment on attachment 187078 [details] [review]
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC

yay assuming you tested against something

>+#include "glib.h"
>+#ifdef G_OS_UNIX
>+#include "glib-unix.h"

"No comment" :-)
Comment 3 Matthias Clasen 2011-05-03 02:34:22 UTC
Review of attachment 187078 [details] [review]:

::: gio/gcancellable.c
@@ +222,3 @@
        */
       set_fd_nonblocking (priv->cancel_pipe[0]);
       set_fd_nonblocking (priv->cancel_pipe[1]);

According to pipe2(2), you can pass O_NONBLOCK to pipe2(). Should g_unix_pipe_flags not support that ?
Comment 4 Matthias Clasen 2011-05-03 02:34:22 UTC
Review of attachment 187078 [details] [review]:

::: gio/gcancellable.c
@@ +222,3 @@
        */
       set_fd_nonblocking (priv->cancel_pipe[0]);
       set_fd_nonblocking (priv->cancel_pipe[1]);

According to pipe2(2), you can pass O_NONBLOCK to pipe2(). Should g_unix_pipe_flags not support that ?
Comment 5 Colin Walters 2011-05-03 12:47:27 UTC
(In reply to comment #4)
> Review of attachment 187078 [details] [review]:
> 
> ::: gio/gcancellable.c
> @@ +222,3 @@
>         */
>        set_fd_nonblocking (priv->cancel_pipe[0]);
>        set_fd_nonblocking (priv->cancel_pipe[1]);
> 
> According to pipe2(2), you can pass O_NONBLOCK to pipe2(). Should
> g_unix_pipe_flags not support that ?

We could, but the reason I didn't originally do this is:

* There are no race conditions related to it; the FD_CLOEXEC is the important one
* There are far fewer users of O_NONBLOCK with pipes
* I was a little worried about possible value collisions between the flags.  On Linux/glibc with fcntl(), setting close-on-exec and nonblock are two different operations; F_SETFD versus F_SETFL.  In theory O_NONBLOCK could have the same value as FD_CLOEXEC, though I admit in practice that's unlikely.
Comment 6 Matthias Clasen 2011-05-03 13:47:23 UTC
I guess if you were to add O_NONBLOCK, you'd have to use O_CLOEXEC instead of FD_CLOEXEC to avoid possible clashes...
Comment 7 Matthias Clasen 2011-05-03 13:48:00 UTC
oh, but you are right, the F_SETFD vs F_SETFL basically renders the point moot, I hadn't noticed that
Comment 8 Colin Walters 2011-05-03 13:55:02 UTC
Created attachment 187125 [details] [review]
g_unix_set_fd_nonblocking: New API to control file descriptor blocking state

And use it in relevant places in GLib.
Comment 9 Colin Walters 2011-05-03 13:55:09 UTC
Created attachment 187126 [details] [review]
GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC

The old code was creating a pipe and setting FD_CLOEXEC
non-atomically.
Comment 10 Colin Walters 2011-05-03 13:56:19 UTC
This new API is more general and better - we can e.g. set only one end of the pipe nonblocking, as was used in gmain.c, and we also abstract unsetting the flag.
Comment 11 Matthias Clasen 2011-05-03 14:06:05 UTC
Review of attachment 187125 [details] [review]:

Looks like a nice cleanup
Comment 12 Matthias Clasen 2011-05-03 14:11:17 UTC
Review of attachment 187126 [details] [review]:

Looks good then, too
Comment 13 Colin Walters 2011-05-03 14:15:07 UTC
Attachment 187125 [details] pushed as ed37970 - g_unix_set_fd_nonblocking: New API to control file descriptor blocking state
Attachment 187126 [details] pushed as c078223 - GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC