diff --git a/hmp-commands.hx b/hmp-commands.hx index 9e1cca8e3d26b9648d9bd077cf10c1be8d1565ed..2163e6f5f4ffd38120ccdbdd0864eec40f8b1e90 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -43,7 +43,7 @@ ETEXI .params = "", .help = "quit the emulator", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_quit, + .mhandler.cmd = hmp_quit, }, STEXI diff --git a/hmp.c b/hmp.c index 30c6cc9511cc7ba70070c163b869b6f6ce12526f..7695dfc4673112519499ffd0d885a3d99bb4f505 100644 --- a/hmp.c +++ b/hmp.c @@ -93,3 +93,9 @@ void hmp_info_chardev(Monitor *mon) qapi_free_ChardevInfoList(char_info); } + +void hmp_quit(Monitor *mon, const QDict *qdict) +{ + monitor_suspend(mon); + qmp_quit(NULL); +} diff --git a/hmp.h b/hmp.h index 7388f9a6eae3af8affb04de5287f24bc97a886cb..a3dfafd8e978c93e31c57083a14467ef9cf9cc2e 100644 --- a/hmp.h +++ b/hmp.h @@ -23,5 +23,6 @@ void hmp_info_kvm(Monitor *mon); void hmp_info_status(Monitor *mon); void hmp_info_uuid(Monitor *mon); void hmp_info_chardev(Monitor *mon); +void hmp_quit(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor.c b/monitor.c index 0c90506cdd37413bdeb9cdeb77a312d3b2a35853..6e13ef6571687c3a30e00e082205a4c038ef582c 100644 --- a/monitor.c +++ b/monitor.c @@ -946,18 +946,6 @@ static void do_trace_print_events(Monitor *mon) trace_print_events((FILE *)mon, &monitor_fprintf); } -/** - * do_quit(): Quit QEMU execution - */ -static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - monitor_suspend(mon); - no_shutdown = 0; - qemu_system_shutdown_request(); - - return 0; -} - #ifdef CONFIG_VNC static int change_vnc_password(const char *password) { diff --git a/qapi-schema.json b/qapi-schema.json index 35434c1eb6e07d66655adef8442292a9abad7126..38104635c027ec32c619175e657e73bcd1d243bb 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -225,3 +225,14 @@ ## { 'command': 'query-commands', 'returns': ['CommandInfo'] } +## +# @quit: +# +# This command will cause the QEMU process to exit gracefully. While every +# attempt is made to send the QMP response before terminating, this is not +# guaranteed. When using this interface, a premature EOF would not be +# unexpected. +# +# Since: 0.14.0 +## +{ 'command': 'quit' } diff --git a/qmp-commands.hx b/qmp-commands.hx index 0fda5c3b9792971935bab28cdb9f4c1163115076..151a5fa651e7e58be5fbb41d9bd7192bb1923961 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -63,10 +63,7 @@ EQMP { .name = "quit", .args_type = "", - .params = "", - .help = "quit the emulator", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_quit, + .mhandler.cmd_new = qmp_marshal_input_quit, }, SQMP diff --git a/qmp.c b/qmp.c index 58337c79f19aa005f6ef019ee9e8939e1f2e3217..1d380b6a5f598de611e239565c691c5e4e3fc7b4 100644 --- a/qmp.c +++ b/qmp.c @@ -70,3 +70,9 @@ UuidInfo *qmp_query_uuid(Error **errp) return info; } +void qmp_quit(Error **err) +{ + no_shutdown = 0; + qemu_system_shutdown_request(); +} +