ia64/xen-unstable

changeset 17040:bd09d9692bda

device-dm: Use SIGHUP before SIGKILL

Make qemu unblock SIGHUP and make sure the default handler is in
place. Have the domain killer send SIGHUP to the device-model script,
allow the script 10s to clean up, and if still not dead, send
SIGKILL.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 12 10:57:49 2008 +0000 (2008-02-12)
parents c3fd43049492
children 88818d55e95a
files tools/ioemu/vl.c tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/ioemu/vl.c	Tue Feb 12 10:19:12 2008 +0000
     1.2 +++ b/tools/ioemu/vl.c	Tue Feb 12 10:57:49 2008 +0000
     1.3 @@ -7928,11 +7928,13 @@ int main(int argc, char **argv)
     1.4      }
     1.5  #endif
     1.6  
     1.7 -    /* Unblock SIGTERM, which may have been blocked by the caller */
     1.8 +    /* Unblock SIGTERM and SIGHUP, which may have been blocked by the caller */
     1.9 +    signal(SIGHUP, SIG_DFL);
    1.10      sigemptyset(&set);
    1.11      sigaddset(&set, SIGTERM);
    1.12 +    sigaddset(&set, SIGHUP);
    1.13      if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1)
    1.14 -        fprintf(stderr, "Failed to unblock SIGTERM\n");
    1.15 +        fprintf(stderr, "Failed to unblock SIGTERM and SIGHUP\n");
    1.16  
    1.17      main_loop();
    1.18      quit_timers();
     2.1 --- a/tools/python/xen/xend/image.py	Tue Feb 12 10:19:12 2008 +0000
     2.2 +++ b/tools/python/xen/xend/image.py	Tue Feb 12 10:57:49 2008 +0000
     2.3 @@ -335,16 +335,27 @@ class ImageHandler:
     2.4              return
     2.5          if self.pid:
     2.6              try:
     2.7 -                os.kill(self.pid, signal.SIGKILL)
     2.8 +                os.kill(self.pid, signal.SIGHUP)
     2.9              except OSError, exn:
    2.10                  log.exception(exn)
    2.11              try:
    2.12 -                os.waitpid(self.pid, 0)
    2.13 +                # Try to reap the child every 100ms for 10s. Then SIGKILL it.
    2.14 +                for i in xrange(100):
    2.15 +                    (p, rv) = os.waitpid(self.pid, os.WNOHANG)
    2.16 +                    if p == self.pid:
    2.17 +                        break
    2.18 +                    time.sleep(0.1)
    2.19 +                else:
    2.20 +                    log.warning("DeviceModel %d took more than 10s "
    2.21 +                                "to terminate: sending SIGKILL" % self.pid)
    2.22 +                    os.kill(self.pid, signal.SIGKILL)
    2.23 +                    os.waitpid(self.pid, 0)
    2.24              except OSError, exn:
    2.25                  # This is expected if Xend has been restarted within the
    2.26                  # life of this domain.  In this case, we can kill the process,
    2.27                  # but we can't wait for it because it's not our child.
    2.28 -                pass
    2.29 +                # We just make really sure it's going away (SIGKILL) first.
    2.30 +                os.kill(self.pid, signal.SIGKILL)
    2.31              self.pid = None
    2.32              state = xstransact.Remove("/local/domain/0/device-model/%i"
    2.33                                        % self.vm.getDomid())