mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-10-23 23:34:16 +03:00
vircommand: Introduce virCommandMassCloseRange()
This is brand new way of closing FDs before exec(). We need to close all FDs except those we want to explicitly pass to avoid leaking FDs into the child. Historically, we've done this by either iterating over all opened FDs and closing them one by one (or preserving them), or by iterating over an FD interval [2 ... N] and closing them one by one followed by calling closefrom(N + 1). This is a lot of syscalls. That's why Linux kernel developers introduced new close_from syscall. It closes all FDs within given range, in a single syscall. Since we keep list of FDs we want to preserve and pass to the child process, we can use this syscall to close all FDs in between. We don't even need to care about opened FDs. Of course, we have to check whether the syscall is available and fall back to the old implementation if it isn't. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
@@ -1247,6 +1247,8 @@ mymain(void)
|
||||
setpgid(0, 0);
|
||||
ignore_value(setsid());
|
||||
|
||||
virCloseRangeInit();
|
||||
|
||||
/* Our test expects particular fd values; to get that, we must not
|
||||
* leak fds that we inherited from a lazy parent. At the same
|
||||
* time, virInitialize may open some fds (perhaps via third-party
|
||||
|
||||
Reference in New Issue
Block a user