From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
qemu-devel@nongnu.org,
"Lukas Jünger" <lukas.junger@greensocs.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Warner Losh" <imp@bsdimp.com>
Subject: Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
Date: Mon, 18 Oct 2021 19:30:46 +0200 [thread overview]
Message-ID: <9b8fce9e-a071-6ac9-4447-38562ac90dce@redhat.com> (raw)
In-Reply-To: <87o87mz4uu.fsf@linaro.org>
On 10/18/21 18:14, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>> On 10/18/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>
>>> ---
>>> 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;
>>> +}
>>
>> Hmm this isn't a stub anymore, this is the user-mode implementation.
>
> It is? I don't think any of the chardev code touches user-mode, I had to
> add this because apparently other binaries link the libchardev code.
If it isn't then is should call g_assert_not_reached().
prev parent reply other threads:[~2021-10-18 17:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-18 14:02 [RFC PATCH] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-18 14:20 ` Marc-André Lureau
2021-10-18 14:37 ` Paolo Bonzini
2021-10-18 14:53 ` Alex Bennée
2021-10-18 14:59 ` Paolo Bonzini
2021-10-18 17:20 ` Alex Bennée
2021-10-19 10:49 ` Paolo Bonzini
2021-10-18 15:04 ` Philippe Mathieu-Daudé
2021-10-18 16:14 ` Alex Bennée
2021-10-18 17:30 ` Philippe Mathieu-Daudé [this message]
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=9b8fce9e-a071-6ac9-4447-38562ac90dce@redhat.com \
--to=philmd@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=imp@bsdimp.com \
--cc=lukas.junger@greensocs.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).