diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 57df10aa00fe..0ea9eacc406a 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -151,6 +151,13 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, */ void qemu_chr_disconnect(CharDriverState *chr); +/** + * @qemu_chr_cleanup: + * + * Delete all chardevs (when leaving qemu) + */ +void qemu_chr_cleanup(void); + /** * @qemu_chr_new_noreplay: * diff --git a/qemu-char.c b/qemu-char.c index 0698b9875057..e4b844842291 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4548,7 +4548,7 @@ void qmp_chardev_remove(const char *id, Error **errp) qemu_chr_delete(chr); } -static void qemu_chr_cleanup(void) +void qemu_chr_cleanup(void) { CharDriverState *chr, *tmp; @@ -4603,8 +4603,6 @@ static void register_types(void) * is specified */ qemu_add_machine_init_done_notifier(&muxes_realize_notify); - - atexit(qemu_chr_cleanup); } type_init(register_types); diff --git a/vl.c b/vl.c index cad4da2487b5..d3ec5320ead2 100644 --- a/vl.c +++ b/vl.c @@ -4608,7 +4608,9 @@ int main(int argc, char **argv, char **envp) tpm_cleanup(); #endif + /* vhost-user must be cleaned up before chardevs. */ net_cleanup(); + qemu_chr_cleanup(); return 0; }