command: avoid potential deadlock on handshake
command: avoid potential deadlock on handshake

There is a theoretical problem of an extreme bug where we can get
into deadlock due to command handshaking.  Thanks to a pair of pipes,
we have a situation where the parent thinks the child reported an
error and is waiting for a message from the child to explain the
error; but at the same time the child thinks it reported success
and is waiting for the parent to acknowledge the success; so both
processes are now blocked.

Thankfully, I don't think this deadlock is possible without at
least one other bug in the code, but I did see exactly that sort
of situation prior to commit da831af - I saw a backtrace where a
double close bug in the parent caused the parent to read from the
wrong fd and assume the child failed, even though the child really
sent success.

This potential deadlock is not quite like commit 858c247 (a deadlock
due to multiple readers on one pipe preventing a write from completing),
although the solution is similar - always close unused pipe fds before
blocking, rather than after.

* src/util/command.c (virCommandHandshakeWait): Close unused fds
sooner.

nertpinx/libvirt,jardasgit/libvirt,iam-TJ/libvirt,andreabolognani/libvirt,dumbbell/libvirt,crobinso/libvirt,trainstack/libvirt,libvirt/libvirt,warewolf/libvirt,andreabolognani/libvirt,eskultety/libvirt,cbosdo/libvirt,trainstack/libvirt,nertpinx/libvirt,cbosdo/libvirt,elmarco/libvirt,wiedi/libvirt,jfehlig/libvirt,olafhering/libvirt,jardasgit/libvirt,siboulet/libvirt-openvz,dumbbell/libvirt,dumbbell/libvirt,trainstack/libvirt,warewolf/libvirt,rmarwaha/libvirt,emaste/libvirt,rlaager/libvirt,bjzhang/libvirt,bjzhang/libvirt,datto/libvirt,siboulet/libvirt-openvz,andreabolognani/libvirt,emaste/libvirt,bjzhang/libvirt,bjzhang/libvirt,crobinso/libvirt,iam-TJ/libvirt,jeckersb/libvirt,nertpinx/libvirt,fabianfreyer/libvirt,fabianfreyer/libvirt,cbosdo/libvirt,rmarwaha/libvirt1,shugaoye/libvirt,olafhering/libvirt,trainstack/libvirt,trainstack/libvirt,rmarwaha/libvirt,eskultety/libvirt,taget/libvirt,libvirt/libvirt,wiedi/libvirt,cbosdo/libvirt,rmarwaha/libvirt,VenkatDatta/libvirt,wiedi/libvirt,bjzhang/libvirt,dumbbell/libvirt,rmarwaha/libvirt1,datto/libvirt,zippy2/libvirt,siboulet/libvirt-openvz,andreabolognani/libvirt,VenkatDatta/libvirt,rmarwaha/libvirt1,zhlcindy/libvirt-1.1.4-maintain,cbosdo/libvirt,eskultety/libvirt,iam-TJ/libvirt,rmarwaha/libvirt1,eskultety/libvirt,fabianfreyer/libvirt,nertpinx/libvirt,siboulet/libvirt-openvz,dumbbell/libvirt,novel/fbsd-libvirt,shugaoye/libvirt,iam-TJ/libvirt,rmarwaha/libvirt1,rlaager/libvirt,zhlcindy/libvirt-1.1.4-maintain,libvirt/libvirt,taget/libvirt,rlaager/libvirt,agx/libvirt,datto/libvirt,jeckersb/libvirt,andreabolognani/libvirt,agx/libvirt,VenkatDatta/libvirt,rlaager/libvirt,jeckersb/libvirt,emaste/libvirt,libvirt/libvirt,shugaoye/libvirt,warewolf/libvirt,iam-TJ/libvirt,trainstack/libvirt,zhlcindy/libvirt-1.1.4-maintain,nertpinx/libvirt,crobinso/libvirt,rlaager/libvirt,novel/fbsd-libvirt,iam-TJ/libvirt,wiedi/libvirt,warewolf/libvirt,wiedi/libvirt,novel/fbsd-libvirt,novel/fbsd-libvirt,elmarco/libvirt,wiedi/libvirt,jeckersb/libvirt,siboulet/libvirt-openvz,novel/fbsd-libvirt,zippy2/libvirt,shugaoye/libvirt,iam-TJ/libvirt,rmarwaha/libvirt1,emaste/libvirt,wiedi/libvirt,shugaoye/libvirt,zippy2/libvirt,jardasgit/libvirt,taget/libvirt,warewolf/libvirt,agx/libvirt,emaste/libvirt,emaste/libvirt,agx/libvirt,warewolf/libvirt,emaste/libvirt,rmarwaha/libvirt,elmarco/libvirt,datto/libvirt,warewolf/libvirt,novel/fbsd-libvirt,jardasgit/libvirt,olafhering/libvirt,elmarco/libvirt,novel/fbsd-libvirt,jfehlig/libvirt,taget/libvirt,novel/fbsd-libvirt,VenkatDatta/libvirt,agx/libvirt,zhlcindy/libvirt-1.1.4-maintain,zhlcindy/libvirt-1.1.4-maintain,jfehlig/libvirt,datto/libvirt,jardasgit/libvirt,crobinso/libvirt,olafhering/libvirt,rmarwaha/libvirt,VenkatDatta/libvirt,novel/fbsd-libvirt,jeckersb/libvirt,fabianfreyer/libvirt,jeckersb/libvirt,fabianfreyer/libvirt,jfehlig/libvirt,jeckersb/libvirt,eskultety/libvirt,taget/libvirt,elmarco/libvirt,zippy2/libvirt,trainstack/libvirt,rmarwaha/libvirt,dumbbell/libvirt