[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
From: |
Alex Bennée |
Subject: |
Re: [RFC PATCH] chardev: don't exit() straight away on C-a x |
Date: |
Mon, 18 Oct 2021 15:53:09 +0100 |
User-agent: |
mu4e 1.7.0; emacs 28.0.60 |
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 18/10/21 16:02, Alex Bennée wrote:
>> While there are a number of uses in the code-base of the exit(0)
>> pattern it gets in the way of clean exit which can do all of it's
>> house-keeping. In particular it was reported that you can crash
>> plugins this way because TCG can still be running on other threads
>> when the atexit callback is called.
>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>> the runstate stub seeing as it now contains two functions.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>
> That won't work with -no-shutdown, but you can just call qmp_quit()
> instead.
How does calling qmp_quit() fix --no-shutdown? Isn't it just a thin
wrapper around the qemu_system_shutdown_request()?
>
> Paolo
>
>> ---
>> chardev/char-mux.c | 3 ++-
>> stubs/{runstate-check.c => runstate.c} | 5 +++++
>> stubs/meson.build | 2 +-
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>> rename stubs/{runstate-check.c => runstate.c} (64%)
>> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
>> index ada0c6866f..a46897fcd5 100644
>> --- a/chardev/char-mux.c
>> +++ b/chardev/char-mux.c
>> @@ -28,6 +28,7 @@
>> #include "qemu/option.h"
>> #include "chardev/char.h"
>> #include "sysemu/block-backend.h"
>> +#include "sysemu/runstate.h"
>> #include "chardev-internal.h"
>> /* MUX driver for serial I/O splitting */
>> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d,
>> int ch)
>> {
>> const char *term = "QEMU: Terminated\n\r";
>> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
>> - exit(0);
>> +
>> qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
>> break;
>> }
>> case 's':
>> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
>> similarity index 64%
>> rename from stubs/runstate-check.c
>> rename to stubs/runstate.c
>> index 2ccda2b70f..f47dbcd3e0 100644
>> --- a/stubs/runstate-check.c
>> +++ b/stubs/runstate.c
>> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
>> {
>> return state == RUN_STATE_PRELAUNCH;
>> }
>> +
>> +void qemu_system_shutdown_request(ShutdownCause reason)
>> +{
>> + return;
>> +}
>> diff --git a/stubs/meson.build b/stubs/meson.build
>> index f6aa3aa94f..8f6a9f17e5 100644
>> --- a/stubs/meson.build
>> +++ b/stubs/meson.build
>> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
>> stub_ss.add(files('ram-block.c'))
>> stub_ss.add(files('ramfb.c'))
>> stub_ss.add(files('replay.c'))
>> -stub_ss.add(files('runstate-check.c'))
>> +stub_ss.add(files('runstate.c'))
>> stub_ss.add(files('sysbus.c'))
>> stub_ss.add(files('target-get-monitor-def.c'))
>> stub_ss.add(files('target-monitor-defs.c'))
>>
--
Alex Bennée
Re: [RFC PATCH] chardev: don't exit() straight away on C-a x, Philippe Mathieu-Daudé, 2021/10/18