aboutsummaryrefslogtreecommitdiff
path: root/qemu-io-cmds.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-06-05 14:19:32 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2013-06-06 11:27:04 +0200
commitdd5832967ac3fe96bd5bf9f199639176998ead69 (patch)
treea5053905409672db4fc98332fcc44824ed01a521 /qemu-io-cmds.c
parent797ac58cb2093ab9192d8998a1fef85d87cc8661 (diff)
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>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r--qemu-io-cmds.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 0a3817ae7a..8b1244601e 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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 */