]> xenbits.xensource.com Git - libvirt.git/commit
Rewrite LXC I/O forwarding to use main event loop
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 19 Oct 2011 15:22:24 +0000 (16:22 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 3 Nov 2011 12:01:12 +0000 (12:01 +0000)
commit86b53e59d8a89f35f29e89725e3746f70c909938
treeda038a9b6e4d8f64ff133598c9f20db7d3be9cba
parent5990d92192e53c0215c1dd0bd03e446c33c7eb22
Rewrite LXC I/O forwarding to use main event loop

The current I/O code for LXC uses a hand crafted event loop
to forward I/O between the container & host app, based on
epoll to handle EOF on PTYs. This event loop is not easily
extensible to add more consoles, or monitor other types of
file descriptors.

Remove the custom event loop and replace it with a normal
libvirt event loop. When detecting EOF on a PTY, disable
the event watch on that FD, and fork off a background thread
that does a edge-triggered epoll() on the FD. When the FD
finally shows new incoming data, the thread re-enables the
watch on the FD and exits.

When getting EOF from a read() on the PTY, the existing code
would do waitpid(WNOHANG) to see if the container had exited.
Unfortunately there is a race condition, because even though
the process has closed its stdio handles, it might still
exist.

To deal with this the new event loop uses a SIG_CHILD handler
to perform the waitpid only when the container is known to
have actually exited.

* src/lxc/lxc_controller.c: Rewrite the event loop to use
  the standard APIs.
cfg.mk
src/lxc/lxc_controller.c