summaryrefslogtreecommitdiffstats
path: root/daemon/wc.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-03-14 19:30:46 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-03-14 19:30:46 +0000
commit606732d02e678161ff433040a21d54fc2ea8bb43 (patch)
tree7549558e51d1dd45a45e71ce219084e368eb845d /daemon/wc.c
parent13e7a1b400b7e2a5e9335d25205b09e74c89d858 (diff)
downloadlibguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.tar.gz
libguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.tar.xz
libguestfs-606732d02e678161ff433040a21d54fc2ea8bb43.zip
Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.
The presumption is that all file descriptors should be created with the close-on-exec flag set. The only exception are file descriptors that we want passed through to exec'd subprocesses (mainly pipes and stdin/stdout/stderr). For open calls, we pass O_CLOEXEC as an extra flag, eg: fd = open ("foo", O_RDONLY|O_CLOEXEC); This is a Linux-ism, but using a macro we can easily make it portable. For sockets, similarly: sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...); For accepted sockets, we use the Linux accept4 system call which allows flags to be supplied, but we use the Gnulib 'accept4' module to make this portable. For dup, dup2, we use the Linux dup3 system call, and the Gnulib modules 'dup3' and 'cloexec'.
Diffstat (limited to 'daemon/wc.c')
-rw-r--r--daemon/wc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/daemon/wc.c b/daemon/wc.c
index 5d35559c..f2753469 100644
--- a/daemon/wc.c
+++ b/daemon/wc.c
@@ -35,7 +35,7 @@ wc (const char *flag, const char *path)
int fd, flags, r;
CHROOT_IN;
- fd = open (path, O_RDONLY);
+ fd = open (path, O_RDONLY|O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {