Received: from eggs.gnu.org ([140.186.70.92]:54106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLx1t-0005qb-Vx for qemu-devel@nongnu.org; Thu, 03 Nov 2011 09:08:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLx1r-0008TA-Li for qemu-devel@nongnu.org; Thu, 03 Nov 2011 09:08:25 -0400 Received: from canardo.mork.no ([148.122.252.1]:53330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLx1r-0008Rr-3h for qemu-devel@nongnu.org; Thu, 03 Nov 2011 09:08:23 -0400 From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= Date: Thu, 3 Nov 2011 14:08:11 +0100 Message-Id: <1320325691-9465-1-git-send-email-bjorn@mork.no> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] os-posix: call system_powerdown on SIGTERM, enabling clean guest shutdown List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Bj=C3=B8rn=20Mork?= Allow well behaved guests to shutdown cleanly when we receive SIGTERM, e.g. when the host reboots. The host may be powered down or rebooted while guests are running without any outer supervision scripts. These guests will be stopped by the generic host "sendsigs" script, usually by sending SIGTERM to all processes still running and then SIGKILL if that didn't work. Let the guest power down instead of just killing i instantly. Signed-off-by: Bj=C3=B8rn Mork --- I wonder if I miss something obvious here... So this patch should be considered a RFC. It certainly fixes a small problem for me: I often run a number of guests which are started manually, or by simple "runme" scripts, without any libvirt wrapper or similar. If/when the host is rebooted, these guests will be shut down abrubtly with possible guest file system corruption and other data loss as a consequence. Powering down on SIGTERM seems like an obious win-win. I also wonder if it would be useful to do a reboot on HUP, but that wouldn't solve any real problem so I'm not including it in this=20 patch. Bj=C3=B8rn os-posix.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/os-posix.c b/os-posix.c index dbf3b24..167fd3b 100644 --- a/os-posix.c +++ b/os-posix.c @@ -65,7 +65,10 @@ void os_setup_early_signal_handling(void) =20 static void termsig_handler(int signal, siginfo_t *info, void *c) { - qemu_system_killed(info->si_signo, info->si_pid); + if (info->si_signo =3D=3D SIGTERM) + qemu_system_powerdown_request(); + else + qemu_system_killed(info->si_signo, info->si_pid); } =20 void os_setup_signal_handling(void) --=20 1.7.2.5