command: avoid double close
command: avoid double close

Previously, the parent process opened 'null' to /dev/null, then
the child process closes 'null' as well as 'childout'.  But if
childout was set to be null, then this is a double close.  At
least the double close was confined to the child process after a
fork, and therefore there is no risk of another thread opening
an fd of the same value to be bitten by the double close, but it
is always better to avoid double-close to begin with.

Additionally, if all three fds were specified, then opening
'null' was wasted.

This patch fixes things to lazily open null on the first use,
then guarantees it gets closed exactly once.

* src/util/command.c (getDevNull): New helper function.
(virExecWithHook): Use it to avoid spurious opens and double close.

rmarwaha/libvirt1,fabianfreyer/libvirt,fabianfreyer/libvirt,wiedi/libvirt,rlaager/libvirt,novel/fbsd-libvirt,wiedi/libvirt,taget/libvirt,novel/fbsd-libvirt,cbosdo/libvirt,iam-TJ/libvirt,VenkatDatta/libvirt,soulxu/libvirt-xuhj,elmarco/libvirt,rmarwaha/libvirt1,novel/fbsd-libvirt,warewolf/libvirt,jfehlig/libvirt,emaste/libvirt,bjzhang/libvirt,agx/libvirt,datto/libvirt,libvirt/libvirt,warewolf/libvirt,VenkatDatta/libvirt,foomango/libvirt,rlaager/libvirt,usc-isi/libvirt,bjzhang/libvirt,zhlcindy/libvirt-1.1.4-maintain,siboulet/libvirt-openvz,jardasgit/libvirt,warewolf/libvirt,dumbbell/libvirt,emaste/libvirt,novel/fbsd-libvirt,zippy2/libvirt,emaste/libvirt,zippy2/libvirt,iam-TJ/libvirt,usc-isi/libvirt,zippy2/libvirt,rmarwaha/libvirt1,foomango/libvirt,nertpinx/libvirt,andreabolognani/libvirt,rmarwaha/libvirt,emaste/libvirt,zippy2/libvirt,usc-isi/libvirt,rlaager/libvirt,taget/libvirt,VenkatDatta/libvirt,trainstack/libvirt,trainstack/libvirt,jeckersb/libvirt,libvirt/libvirt,olafhering/libvirt,rlaager/libvirt,eskultety/libvirt,bjzhang/libvirt,dumbbell/libvirt,foomango/libvirt,warewolf/libvirt,eskultety/libvirt,nertpinx/libvirt,leilihh/libvirt,danwent/libvirt-ovs,novel/fbsd-libvirt,bjzhang/libvirt,shugaoye/libvirt,emaste/libvirt,fabianfreyer/libvirt,jeckersb/libvirt,jfehlig/libvirt,zhlcindy/libvirt-1.1.4-maintain,zhlcindy/libvirt-1.1.4-maintain,rmarwaha/libvirt1,andreabolognani/libvirt,eskultety/libvirt,iam-TJ/libvirt,kantai/libvirt-vfork,wiedi/libvirt,iam-TJ/libvirt,jardasgit/libvirt,agx/libvirt,cbosdo/libvirt,leilihh/libvirt,fabianfreyer/libvirt,olafhering/libvirt,dumbbell/libvirt,danwent/libvirt-ovs,elmarco/libvirt,agx/libvirt,rlaager/libvirt,soulxu/libvirt-xuhj,rmarwaha/libvirt,novel/fbsd-libvirt,cbosdo/libvirt,wiedi/libvirt,datto/libvirt,VenkatDatta/libvirt,leilihh/libvirt,foomango/libvirt,zhlcindy/libvirt-1.1.4-maintain,crobinso/libvirt,siboulet/libvirt-openvz,nertpinx/libvirt,trainstack/libvirt,warewolf/libvirt,datto/libvirt,soulxu/libvirt-xuhj,leilihh/libvirt,kantai/libvirt-vfork,novel/fbsd-libvirt,iam-TJ/libvirt,agx/libvirt,jeckersb/libvirt,jfehlig/libvirt,andreabolognani/libvirt,shugaoye/libvirt,taget/libvirt,usc-isi/libvirt,nertpinx/libvirt,trainstack/libvirt,crobinso/libvirt,bjzhang/libvirt,jardasgit/libvirt,usc-isi/libvirt,wiedi/libvirt,soulxu/libvirt-xuhj,fabianfreyer/libvirt,rmarwaha/libvirt,siboulet/libvirt-openvz,trainstack/libvirt,novel/fbsd-libvirt,leilihh/libvirt,elmarco/libvirt,jeckersb/libvirt,taget/libvirt,crobinso/libvirt,rmarwaha/libvirt,warewolf/libvirt,cbosdo/libvirt,wiedi/libvirt,zhlcindy/libvirt-1.1.4-maintain,andreabolognani/libvirt,datto/libvirt,libvirt/libvirt,shugaoye/libvirt,jeckersb/libvirt,danwent/libvirt-ovs,elmarco/libvirt,eskultety/libvirt,olafhering/libvirt,foomango/libvirt,danwent/libvirt-ovs,andreabolognani/libvirt,crobinso/libvirt,siboulet/libvirt-openvz,novel/fbsd-libvirt,kantai/libvirt-vfork,rmarwaha/libvirt1,leilihh/libvirt,trainstack/libvirt,olafhering/libvirt,libvirt/libvirt,danwent/libvirt-ovs,trainstack/libvirt,warewolf/libvirt,dumbbell/libvirt,kantai/libvirt-vfork,eskultety/libvirt,siboulet/libvirt-openvz,rmarwaha/libvirt,VenkatDatta/libvirt,cbosdo/libvirt,jardasgit/libvirt,kantai/libvirt-vfork,dumbbell/libvirt,jeckersb/libvirt,dumbbell/libvirt,iam-TJ/libvirt,rmarwaha/libvirt,shugaoye/libvirt,iam-TJ/libvirt,elmarco/libvirt,datto/libvirt,nertpinx/libvirt,emaste/libvirt,jardasgit/libvirt,jfehlig/libvirt,jeckersb/libvirt,emaste/libvirt,agx/libvirt,shugaoye/libvirt,rmarwaha/libvirt1,soulxu/libvirt-xuhj,wiedi/libvirt,taget/libvirt