]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virfile: Introduce virCloseRange()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 22 Aug 2023 06:49:10 +0000 (08:49 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Aug 2023 10:41:07 +0000 (12:41 +0200)
commitd69237caa328268c1ec00aa422e9b88abc5a9c5d
tree760a934e07dac8df4399201b964b1729ca91a4ab
parent6a0b6455376ed57b6e3206989af5181cf1a36a84
virfile: Introduce virCloseRange()

Linux gained new close_range() syscall (in v5.9) that allows
closing a range of FDs in a single syscall. Ideally, we would use
it to close FDs when spawning a process (e.g. via virCommand
module).

Glibc has close_range() wrapper over the syscall, which falls
back to iterative closing of all FDs inside the range if running
under older kernel. We don't wane that as in that case we might
just close opened FDs (see Linux version of
virCommandMassClose()). And musl doesn't have close_range() at
all. Therefore, call syscall directly.

Now, mass close of FDs happens in a fork()-ed off child. While it
could detect whether the kernel does support close_range(), it
has no way of passing this info back to the parent and thus each
child would need to query it again and again.

Since this can't change while we are running we can cache the
information - hence virCloseRangeInit().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h