]> xenbits.xensource.com Git - libvirt.git/commit
command: avoid leaking fds across fork
authorEric Blake <eblake@redhat.com>
Tue, 12 Jul 2011 20:56:03 +0000 (14:56 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 21 Jul 2011 16:34:51 +0000 (10:34 -0600)
commit5d804ffae4ca493c70b8fadd697ec2d822876ec4
tree8f4831de0df3d7964a38151091be0efdbca4ed15
parent4289114518c775a1ff2ec012c597bbf02a80ecbb
command: avoid leaking fds across fork

Since libvirt is multi-threaded, we should use FD_CLOEXEC as much
as possible in the parent, and only relax fds to inherited after
forking, to avoid leaking an fd created in one thread to a fork
run in another thread.  This gets us closer to that ideal, by
making virCommand automatically clear FD_CLOEXEC on fds intended
for the child, as well as avoiding a window of time with non-cloexec
pipes created for capturing output.

* src/util/command.c (virExecWithHook): Use CLOEXEC in parent.  In
child, guarantee that all fds to pass to child are inheritable.
(getDevNull): Use CLOEXEC.
(prepareStdFd): New helper function.
(virCommandRun, virCommandRequireHandshake): Use pipe2.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Simplify caller.
src/qemu/qemu_command.c
src/util/command.c