mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: close all unused fds in sigwinch listener
The PTY main file descriptor had to be introduced as a parameter to start_sigwinch_listener, so that it could be closed in the child. Really the SIGWINCH listener process should not have any file descriptors open, except for the ones it needs to function, so let's make it more robust by having it close all other file descriptors. For recent kernels, we can do this very conveniently with close_range(2), but for older kernels, we have to fall back to closing open file descriptors one at a time. Signed-off-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
committed by
Rob Bradford
parent
67ad3ff1ba
commit
505f4dfa53
@@ -1869,7 +1869,7 @@ impl DeviceManager {
|
||||
self.modify_mode(f.as_raw_fd(), |t| unsafe { cfmakeraw(t) })
|
||||
}
|
||||
|
||||
fn listen_for_sigwinch_on_tty(&mut self, pty_main: File, pty_sub: File) -> std::io::Result<()> {
|
||||
fn listen_for_sigwinch_on_tty(&mut self, pty_sub: File) -> std::io::Result<()> {
|
||||
let seccomp_filter = get_seccomp_filter(
|
||||
&self.seccomp_action,
|
||||
Thread::PtyForeground,
|
||||
@@ -1877,7 +1877,7 @@ impl DeviceManager {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
match start_sigwinch_listener(seccomp_filter, pty_main, pty_sub) {
|
||||
match start_sigwinch_listener(seccomp_filter, pty_sub) {
|
||||
Ok(pipe) => {
|
||||
self.console_resize_pipe = Some(Arc::new(pipe));
|
||||
}
|
||||
@@ -1917,8 +1917,7 @@ impl DeviceManager {
|
||||
self.config.lock().unwrap().console.file = Some(path.clone());
|
||||
let file = main.try_clone().unwrap();
|
||||
assert!(resize_pipe.is_none());
|
||||
self.listen_for_sigwinch_on_tty(main.try_clone().unwrap(), sub)
|
||||
.unwrap();
|
||||
self.listen_for_sigwinch_on_tty(sub).unwrap();
|
||||
self.console_pty = Some(Arc::new(Mutex::new(PtyPair { main, path })));
|
||||
Endpoint::PtyPair(file.try_clone().unwrap(), file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user