golang/xenlight: Notify xenlight of SIGCHLD
authorGeorge Dunlap <george.dunlap@citrix.com>
Thu, 26 Dec 2019 17:35:27 +0000 (17:35 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Thu, 23 Apr 2020 15:00:13 +0000 (16:00 +0100)
commita73964c18e25ec451d5d0fd89e21702817f6b3dd
tree6fe15aca5feee6aed58bb2f2f235f116bdaa1090
parentb70275d0d9fb626102a9521794f2bd75b4d420eb
golang/xenlight: Notify xenlight of SIGCHLD

libxl forks external processes and waits for them to complete; it
therefore needs to be notified when children exit.

In absence of instructions to the contrary, libxl sets up its own
SIGCHLD handlers.

Golang always unmasks and handles SIGCHLD itself.  libxl thankfully
notices this and throws an assert() rather than clobbering SIGCHLD
handlers.

Tell libxl that we'll be responsible for getting SIGCHLD notifications
to it.  Arrange for a channel in the context to receive notifications
on SIGCHLD, and set up a goroutine that will pass these on to libxl.

NB that every libxl context needs a notification; so multiple contexts
will each spin up their own goroutine when opening a context, and shut
it down on close.

libxl also wants to hold on to a const pointer to
xenlight_childproc_hooks rather than do a copy; so make a global
structure in C space.  Make it `static const`, just for extra safety;
this requires making a function in the C space to pass it to libxl.

While here, add a few comments to make the context set-up a bit easier
to follow.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Nick Rosbrook <rosbrookn@ainfosec.com>
tools/golang/xenlight/xenlight.go