Skip to content

Commit

Permalink
monitor: allow register hmp commands
Browse files Browse the repository at this point in the history
Allow commands having a NULL cmd pointer, add a function to set the
pointer later.  Use case: allow modules implement hmp commands.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jose R. Ziviani <jziviani@suse.de>
Message-Id: <20210624103836.2382472-31-kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
kraxel authored and bonzini committed Jul 9, 2021
1 parent dae0ec1 commit f0e48cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/monitor/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
void monitor_fdset_dup_fd_remove(int dup_fd);
int64_t monitor_fdset_dup_fd_find(int dup_fd);

void monitor_register_hmp(const char *name, bool info,
void (*cmd)(Monitor *mon, const QDict *qdict));

#endif /* MONITOR_H */
7 changes: 7 additions & 0 deletions monitor/hmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,13 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
return;
}

if (!cmd->cmd) {
/* FIXME: is it useful to try autoload modules here ??? */
monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
(int)(cmdline - cmd_start), cmd_start);
return;
}

qdict = monitor_parse_arguments(&mon->common, &cmdline, cmd);
if (!qdict) {
while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
Expand Down
16 changes: 16 additions & 0 deletions monitor/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,22 @@ static void sortcmdlist(void)
compare_mon_cmd);
}

void monitor_register_hmp(const char *name, bool info,
void (*cmd)(Monitor *mon, const QDict *qdict))
{
HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;

while (table->name != NULL) {
if (strcmp(table->name, name) == 0) {
g_assert(table->cmd == NULL);
table->cmd = cmd;
return;
}
table++;
}
g_assert_not_reached();
}

void monitor_init_globals(void)
{
monitor_init_globals_core();
Expand Down

0 comments on commit f0e48cb

Please sign in to comment.