]> git.ipfire.org Git - thirdparty/libvirt.git/commit
lib: Avoid double close when passing FDs with virCommandPassFD()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 30 Apr 2019 09:17:22 +0000 (11:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 17 May 2019 14:01:11 +0000 (16:01 +0200)
commit5cdd5d380bab5f6f7207e0ffd0c1322a8281feca
treed5e4ecf18a590d1dde22239565ea14b400a53358
parente5df4edefa6b6b9db2ef620a1f16a901afda0274
lib: Avoid double close when passing FDs with virCommandPassFD()

If an FD is passed into a child using:

  virCommandPassFD(cmd, fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);

then the parent should refrain from touching @fd thereafter. This
is even documented in virCommandPassFD() comment. The reason is
that either at virCommandRun()/virCommandRunAsync() or
virCommandFree() time the @fd will be closed. Closing it earlier,
e.g. right after virCommandPassFD() call might result in
undesired results. Another thread might open a file and receive
the same FD which is then unexpectedly closed by virCommandFree()
or virCommandRun().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
src/util/virpolkit.c
tests/commandtest.c