[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] event: Add signal information to SHUTDOWN
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] event: Add signal information to SHUTDOWN |
Date: |
Thu, 13 Apr 2017 14:11:26 +0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
On 07/04/2017 05:09, Eric Blake wrote:
> ##
> +# @ShutdownSignal:
> +#
> +# The list of host signal types known to cause qemu to shut down a guest.
> +#
> +# @int: SIGINT
> +# @hup: SIGHUP
> +# @term: SIGTERM
> +#
> +# Since: 2.10
> +##
> +{ 'enum': 'ShutdownSignal', 'data': [ 'int', 'hup', 'term' ] }
I follow Markus's suggestion and would even make them uppercase.
Uncommon, but I think justified in this case.
> +##
> # @SHUTDOWN:
> #
> # Emitted when the virtual machine has shut down, indicating that qemu is
> # about to exit.
> #
> +# @signal: If present, the shutdown was (probably) triggered due to
> +# the receipt of the given signal in the host, rather than by a guest
> +# action (note that there is an inherent race with a guest choosing to
> +# shut down near the same time the host sends a signal). (since 2.10)
> +#
> # Note: If the command-line option "-no-shutdown" has been specified, qemu
> will
> # not exit, and a STOP event will eventually follow the SHUTDOWN event
> #
> @@ -21,7 +39,7 @@
> # "timestamp": { "seconds": 1267040730, "microseconds": 682951 } }
> #
> ##
> -{ 'event': 'SHUTDOWN' }
> +{ 'event': 'SHUTDOWN', 'data': { '*signal': 'ShutdownSignal' } }
>
> ##
> # @POWERDOWN:
> diff --git a/vl.c b/vl.c
> index 0b4ed52..af29b2c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1626,9 +1626,23 @@ static int qemu_shutdown_requested(void)
> return atomic_xchg(&shutdown_requested, 0);
> }
>
> -static void qemu_kill_report(void)
> +static ShutdownSignal qemu_kill_report(void)
> {
> + ShutdownSignal ss = SHUTDOWN_SIGNAL__MAX;
> if (!qtest_driver() && shutdown_signal != -1) {
> + switch (shutdown_signal) {
> + case SIGINT:
> + ss = SHUTDOWN_SIGNAL_INT;
> + break;
> +#ifdef SIGHUP
> + case SIGHUP:
> + ss = SHUTDOWN_SIGNAL_HUP;
> + break;
> +#endif
> + case SIGTERM:
> + ss = SHUTDOWN_SIGNAL_TERM;
> + break;
> + }
> if (shutdown_pid == 0) {
> /* This happens for eg ^C at the terminal, so it's worth
> * avoiding printing an odd message in that case.
> @@ -1644,6 +1658,7 @@ static void qemu_kill_report(void)
> }
> shutdown_signal = -1;
> }
> + return ss;
> }
>
> static int qemu_reset_requested(void)
> @@ -1852,8 +1867,8 @@ static bool main_loop_should_exit(void)
> qemu_system_suspend();
> }
> if (qemu_shutdown_requested()) {
> - qemu_kill_report();
> - qapi_event_send_shutdown(&error_abort);
> + ShutdownSignal ss = qemu_kill_report();
> + qapi_event_send_shutdown(ss < SHUTDOWN_SIGNAL__MAX, ss,
> &error_abort);
Maybe call qapi_event_send_shutdown from qemu_kill_report? It is not
obvious that ShutdownSignal is unsigned (except to you and Laszlo of
course).
I think this patch is fine for now; calling qemu_system_killed() from
os-win32.c is an orthogonal improvement.
Paolo
> if (no_shutdown) {
> vm_stop(RUN_STATE_SHUTDOWN);
> } else {
>
- Re: [Qemu-devel] [PATCH] event: Add signal information to SHUTDOWN, (continued)
Re: [Qemu-devel] [PATCH] event: Add signal information to SHUTDOWN, Paolo Bonzini, 2017/04/13
Re: [Qemu-devel] [PATCH] event: Add signal information to SHUTDOWN,
Paolo Bonzini <=