]> git.ipfire.org Git - thirdparty/libvirt.git/commit
vircommand.c: write child pidfile before process tuning in virExec()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 1 Oct 2020 13:34:24 +0000 (10:34 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 2 Oct 2020 17:32:57 +0000 (14:32 -0300)
commit0bb796bda31103ebf54eefc11c471586c87b95fd
tree1967b648fe4fc850dbf1662bfac4a2a97cf92c96
parentfdb6a5d79eb35a814d72c002ff451aa788b03851
vircommand.c: write child pidfile before process tuning in virExec()

When VIR_EXEC_DAEMON is true and cmd->pidfile exists, the parent
will expect the pidfile to be written before exiting, sitting
tight in a saferead() call waiting.

The child then does process tuning (via virProcessSet* functions)
before writing the pidfile. Problem is that these tunings can
fail, and trigger a 'fork_error' jump, before cmd->pidfile is
written. The result is that the process was aborted in the
child, but the parent is still hang in the saferead() call.

This behavior can be reproduced by trying to create and execute
a QEMU guest in user mode (e.g. using qemu:///session as non-root).
virProcessSetMaxMemLock() will fail if the spawned libvirtd user
process does not have CAP_SYS_RESOURCE capability. setrlimit() will
fail, and a 'fork_error' jump is triggered before cmd->pidfile
is written. The parent will hung in saferead() indefinitely. From
the user perspective, 'virsh start <guest>' will hang up
indefinitely. CTRL+C can be used to retrieve the terminal, but
any subsequent 'virsh' call will also hang because the previous
libvirtd user process is still there.

We can fix this by moving all virProcessSet*() tuning functions
to be executed after cmd->pidfile is taken care of. In the case
mentioned above, this would be the result of 'virsh start'
after this patch:

error: Failed to start domain vm1
error: internal error: Process exited prior to exec: libvirt:  error :
cannot limit locked memory to 79691776: Operation not permitted

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1882093

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/util/vircommand.c