qemu-io: Factor out qemuio_command

It's duplicated code. Move it to qemu-io-cmds.c because it's not
dependent on any static data of the qemu-io tool.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Kevin Wolf 2013-06-05 14:19:32 +02:00 committed by Stefan Hajnoczi
parent 797ac58cb2
commit dd5832967a
3 changed files with 31 additions and 39 deletions

View file

@ -1807,6 +1807,30 @@ static int init_check_command(BlockDriverState *bs, const cmdinfo_t *ct)
return 1;
}
bool qemuio_command(const char *cmd)
{
char *input;
const cmdinfo_t *ct;
char **v;
int c;
bool done = false;
input = g_strdup(cmd);
v = breakline(input, &c);
if (c) {
ct = find_command(v[0]);
if (ct) {
done = command(ct, c, v);
} else {
fprintf(stderr, "command \"%s\" not found\n", v[0]);
}
}
g_free(input);
g_free(v);
return done;
}
static void __attribute((constructor)) init_qemuio_commands(void)
{
/* initialize commands */