diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-03-14 19:30:46 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-03-14 19:30:46 +0000 |
commit | 606732d02e678161ff433040a21d54fc2ea8bb43 (patch) | |
tree | 7549558e51d1dd45a45e71ce219084e368eb845d /daemon/daemon.h | |
parent | 13e7a1b400b7e2a5e9335d25205b09e74c89d858 (diff) | |
download | libguestfs-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/daemon.h')
-rw-r--r-- | daemon/daemon.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/daemon/daemon.h b/daemon/daemon.h index f3e77da5..b7c1fd8e 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -30,6 +30,10 @@ #include "guestfs_protocol.h" +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + /*-- in guestfsd.c --*/ extern int verbose; |