* [PATCH v2] chardev: don't exit() straight away on C-a x
@ 2021-10-19 9:29 Alex Bennée
2021-10-19 9:56 ` Philippe Mathieu-Daudé
2021-10-19 10:11 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Alex Bennée @ 2021-10-19 9:29 UTC (permalink / raw)
To: qemu-devel
Cc: Marc-André Lureau, Lukas Jünger, Alex Bennée,
Paolo Bonzini
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 qmp_quit() instead which takes care of some housekeeping before
triggering the shutdown.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20211018140226.838137-1-alex.bennee@linaro.org>
---
v2
- use qmp_quit instead of direct qemu_system_shutdown_request
- g_assert_not_reached() for the stub definition
---
chardev/char-mux.c | 3 ++-
stubs/qmp-quit.c | 8 ++++++++
stubs/meson.build | 1 +
3 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 stubs/qmp-quit.c
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index ada0c6866f..ee2d47b20d 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 "qapi/qapi-commands-control.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);
+ qmp_quit(NULL);
break;
}
case 's':
diff --git a/stubs/qmp-quit.c b/stubs/qmp-quit.c
new file mode 100644
index 0000000000..a3ff47f7bd
--- /dev/null
+++ b/stubs/qmp-quit.c
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "qapi/qapi-commands-control.h"
+#include "qapi/qmp/dispatch.h"
+
+void qmp_quit(Error **errp)
+{
+ g_assert_not_reached();
+}
diff --git a/stubs/meson.build b/stubs/meson.build
index f6aa3aa94f..71469c1d50 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -31,6 +31,7 @@ stub_ss.add(files('pci-bus.c'))
stub_ss.add(files('qemu-timer-notify-cb.c'))
stub_ss.add(files('qmp_memory_device.c'))
stub_ss.add(files('qmp-command-available.c'))
+stub_ss.add(files('qmp-quit.c'))
stub_ss.add(files('qtest.c'))
stub_ss.add(files('ram-block.c'))
stub_ss.add(files('ramfb.c'))
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] chardev: don't exit() straight away on C-a x
2021-10-19 9:29 [PATCH v2] chardev: don't exit() straight away on C-a x Alex Bennée
@ 2021-10-19 9:56 ` Philippe Mathieu-Daudé
2021-10-19 10:11 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-19 9:56 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Marc-André Lureau, Lukas Jünger, Paolo Bonzini
On 10/19/21 11:29, 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 qmp_quit() instead which takes care of some housekeeping before
> triggering the shutdown.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Message-Id: <20211018140226.838137-1-alex.bennee@linaro.org>
>
> ---
> v2
> - use qmp_quit instead of direct qemu_system_shutdown_request
> - g_assert_not_reached() for the stub definition
> ---
> chardev/char-mux.c | 3 ++-
> stubs/qmp-quit.c | 8 ++++++++
> stubs/meson.build | 1 +
> 3 files changed, 11 insertions(+), 1 deletion(-)
> create mode 100644 stubs/qmp-quit.c
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] chardev: don't exit() straight away on C-a x
2021-10-19 9:29 [PATCH v2] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-19 9:56 ` Philippe Mathieu-Daudé
@ 2021-10-19 10:11 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-10-19 10:11 UTC (permalink / raw)
To: Alex Bennée, qemu-devel; +Cc: Marc-André Lureau, Lukas Jünger
On 19/10/21 11:29, 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 qmp_quit() instead which takes care of some housekeeping before
> triggering the shutdown.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Message-Id: <20211018140226.838137-1-alex.bennee@linaro.org>
>
> ---
> v2
> - use qmp_quit instead of direct qemu_system_shutdown_request
> - g_assert_not_reached() for the stub definition
Either g_assert_not_reached() or exit(0) should be okay, so
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Thanks,
Paolo
> ---
> chardev/char-mux.c | 3 ++-
> stubs/qmp-quit.c | 8 ++++++++
> stubs/meson.build | 1 +
> 3 files changed, 11 insertions(+), 1 deletion(-)
> create mode 100644 stubs/qmp-quit.c
>
> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> index ada0c6866f..ee2d47b20d 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 "qapi/qapi-commands-control.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);
> + qmp_quit(NULL);
> break;
> }
> case 's':
> diff --git a/stubs/qmp-quit.c b/stubs/qmp-quit.c
> new file mode 100644
> index 0000000000..a3ff47f7bd
> --- /dev/null
> +++ b/stubs/qmp-quit.c
> @@ -0,0 +1,8 @@
> +#include "qemu/osdep.h"
> +#include "qapi/qapi-commands-control.h"
> +#include "qapi/qmp/dispatch.h"
> +
> +void qmp_quit(Error **errp)
> +{
> + g_assert_not_reached();
> +}
> diff --git a/stubs/meson.build b/stubs/meson.build
> index f6aa3aa94f..71469c1d50 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -31,6 +31,7 @@ stub_ss.add(files('pci-bus.c'))
> stub_ss.add(files('qemu-timer-notify-cb.c'))
> stub_ss.add(files('qmp_memory_device.c'))
> stub_ss.add(files('qmp-command-available.c'))
> +stub_ss.add(files('qmp-quit.c'))
> stub_ss.add(files('qtest.c'))
> stub_ss.add(files('ram-block.c'))
> stub_ss.add(files('ramfb.c'))
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-19 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 9:29 [PATCH v2] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-19 9:56 ` Philippe Mathieu-Daudé
2021-10-19 10:11 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.