qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Bjørn Mork" <bjorn@mork.no>
To: qemu-devel@nongnu.org
Cc: "Bjørn Mork" <bjorn@mork.no>
Subject: [Qemu-devel] [PATCH] os-posix: call system_powerdown on SIGTERM, enabling clean guest shutdown
Date: Thu,  3 Nov 2011 14:08:11 +0100	[thread overview]
Message-ID: <1320325691-9465-1-git-send-email-bjorn@mork.no> (raw)

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ørn Mork <bjorn@mork.no>
---
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 
patch.



Bjørn

 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)
 
 static void termsig_handler(int signal, siginfo_t *info, void *c)
 {
-    qemu_system_killed(info->si_signo, info->si_pid);
+    if (info->si_signo == SIGTERM)
+	qemu_system_powerdown_request();
+    else
+	qemu_system_killed(info->si_signo, info->si_pid);
 }
 
 void os_setup_signal_handling(void)
-- 
1.7.2.5

             reply	other threads:[~2011-11-03 13:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03 13:08 Bjørn Mork [this message]
2011-11-03 15:06 ` [Qemu-devel] [PATCH] os-posix: call system_powerdown on SIGTERM, enabling clean guest shutdown Anthony Liguori
2011-11-03 19:45   ` Bjørn Mork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1320325691-9465-1-git-send-email-bjorn@mork.no \
    --to=bjorn@mork.no \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).