[glib] Make cancellable pipe fds close-on-exec
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] Make cancellable pipe fds close-on-exec
- Date: Fri, 15 May 2009 04:43:48 -0400 (EDT)
commit a48fc532519b849498c8b75dde578caf0c270b23
Author: Alexander Larsson <alexl redhat com>
Date: Fri May 15 10:42:28 2009 +0200
Make cancellable pipe fds close-on-exec
GCancellable is purely an in-process thing, so ensure that no cancellable
fds accidentally leak to child processes.
---
gio/gcancellable.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 39f8778..589b83a 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -189,6 +189,20 @@ set_fd_nonblocking (int fd)
}
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
g_cancellable_open_pipe (GCancellable *cancellable)
{
if (pipe (cancellable->cancel_pipe) == 0)
@@ -198,6 +212,8 @@ g_cancellable_open_pipe (GCancellable *cancellable)
*/
set_fd_nonblocking (cancellable->cancel_pipe[0]);
set_fd_nonblocking (cancellable->cancel_pipe[1]);
+ set_fd_close_exec (cancellable->cancel_pipe[0]);
+ set_fd_close_exec (cancellable->cancel_pipe[1]);
}
else
g_warning ("Failed to create pipe for GCancellable. Out of file descriptors?");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]