cloud-hypervisor/vmm/src
Alyssa Ross 330b5ea3be vmm: notify virtio-console of pty resizes
When a pty is resized (using the TIOCSWINSZ ioctl -- see ioctl_tty(2)),
the kernel will send a SIGWINCH signal to the pty's foreground process
group to notify it of the resize.  This is the only way to be notified
by the kernel of a pty resize.

We can't just make the cloud-hypervisor process's process group the
foreground process group though, because a process can only set the
foreground process group of its controlling terminal, and
cloud-hypervisor's controlling terminal will often be the terminal the
user is running it in.  To work around this, we fork a subprocess in a
new process group, and set its process group to be the foreground
process group of the pty.  The subprocess additionally must be running
in a new session so that it can have a different controlling
terminal.  This subprocess writes a byte to a pipe every time the pty
is resized, and the virtio-console device can listen for this in its
epoll loop.

Alternatives I considered were to have the subprocess just send
SIGWINCH to its parent, and to use an eventfd instead of a pipe.
I decided against the signal approach because re-purposing a signal
that has a very specific meaning (even if this use was only slightly
different to its normal meaning) felt unclean, and because it would
have required using pidfds to avoid race conditions if
cloud-hypervisor had terminated, which added complexity.  I decided
against using an eventfd because using a pipe instead allows the child
to be notified (via poll(2)) when nothing is reading from the pipe any
more, meaning it can be reliably notified of parent death and
terminate itself immediately.

I used clone3(2) instead of fork(2) because without
CLONE_CLEAR_SIGHAND the subprocess would inherit signal-hook's signal
handlers, and there's no other straightforward way to restore all signal
handlers to their defaults in the child process.  The only way to do
it would be to iterate through all possible signals, or maintain a
global list of monitored signals ourselves (vmm:vm::HANDLED_SIGNALS is
insufficient because it doesn't take into account e.g. the SIGSYS
signal handler that catches seccomp violations).

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2021-09-14 15:43:25 +01:00
..
api vmm: Shutdown VMM if API thread panics 2021-09-10 10:52:08 -07:00
acpi.rs vmm: Move NUMA node data structures to arch 2021-08-12 10:49:02 +02:00
clone3.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00
config.rs vmm: Remove concept of "input_enabled" 2021-09-08 11:26:48 -07:00
cpu.rs vmm: cpu: Increase robustness of CpuManager control device 2021-09-10 10:22:05 -07:00
device_manager.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00
device_tree.rs vmm: device_manager: Use DeviceTree to store PCI devices 2021-03-18 15:26:25 +01:00
interrupt.rs clippy: Fix redundant allocations 2021-07-29 13:28:57 +02:00
lib.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00
memory_manager.rs vmm: memory_manager: Increase robustness of MemoryManager control device 2021-09-10 10:23:19 -07:00
migration.rs vmm: Simplify snapshot/restore path handling 2021-03-12 13:03:01 +01:00
seccomp_filters.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00
serial_buffer.rs vmm: Introduce a SerialBuffer for buffering serial output 2021-09-02 13:52:18 +01:00
sigwinch_listener.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00
vm.rs vmm: notify virtio-console of pty resizes 2021-09-14 15:43:25 +01:00