• E
    qemu: fix restoring a compressed save image · d51023d4
    Eric Blake 提交于
    Latent bug introduced in commit 2d6a5819 (Aug 2009), but not exposed
    until commit 1859939a (Jan 2011).  Basically, when virExec creates a
    pipe, it always marks libvirt's side as cloexec.  If libvirt then
    wants to hand that pipe to another child process, things work great if
    the fd is dup2()'d onto stdin or stdout (as with stdin: or exec:
    migration), but if the pipe is instead used as-is (such as with fd:
    migration) then qemu sees EBADF because the fd was closed at exec().
    
    This is a minimal fix for the problem at hand; it is slightly racy,
    but no more racy than the rest of libvirt fd handling, including the
    case of uncompressed save images.  A more invasive fix, but ultimately
    safer at avoiding leaking unintended fds, would be to _always and
    atomically_ open all fds as cloexec in libvirt (thanks to primitives
    like open(O_CLOEXEC), pipe2(), accept4(), ...), then teach virExec to
    clear that bit for all fds explicitly marked to be handed to the child
    only after forking.
    
    * src/qemu/qemu_command.c (qemuBuildCommandLine): Clear cloexec
    flag.
    * tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Tweak test.
    d51023d4
qemuxml2argvtest.c 19.2 KB