Signed-off-by: Lin Ma <lma@xxxxxxxx> --- tools/virsh-domain.c | 76 +++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 89aefbf86a..b35c9adaaa 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13347,10 +13347,6 @@ static const vshCmdInfo info_event[] = { static const vshCmdOptDef opts_event[] = { VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uuid"), 0), - {.name = "event", - .type = VSH_OT_STRING, - .help = N_("which event type to wait for") - }, {.name = "all", .type = VSH_OT_BOOL, .help = N_("wait for all events instead of just one type") @@ -13371,6 +13367,10 @@ static const vshCmdOptDef opts_event[] = { .type = VSH_OT_BOOL, .help = N_("show timestamp for each printed event") }, + {.name = "event", + .type = VSH_OT_ARGV, + .help = N_("which event type to wait for") + }, {.name = NULL} }; @@ -13382,12 +13382,14 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) int timeout = 0; virshDomEventData *data = NULL; size_t i; - const char *eventName = NULL; + int *eventIdxList = NULL; + size_t nevents = 0; int event = -1; bool all = vshCommandOptBool(cmd, "all"); bool loop = vshCommandOptBool(cmd, "loop"); bool timestamp = vshCommandOptBool(cmd, "timestamp"); int count = 0; + const vshCmdOpt *opt = NULL; virshControlPtr priv = ctl->privData; if (vshCommandOptBool(cmd, "list")) { @@ -13396,15 +13398,25 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) return true; } - if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) - return false; - if (eventName) { - for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - if (STREQ(eventName, vshEventCallbacks[event].name)) - break; - if (event == VIR_DOMAIN_EVENT_ID_LAST) { - vshError(ctl, _("unknown event type %s"), eventName); - return false; + if (vshCommandOptBool(cmd, "event")) { + if (VIR_ALLOC_N(eventIdxList, 1) < 0) + goto cleanup; + nevents = 1; + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { + if (opt->data) { + for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) + if (STREQ(opt->data, vshEventCallbacks[event].name)) + break; + if (event == VIR_DOMAIN_EVENT_ID_LAST) { + vshError(ctl, _("unknown event type %s"), opt->data); + return false; + } + if (VIR_INSERT_ELEMENT(eventIdxList, + nevents - 1, + nevents, + event) < 0) + goto cleanup; + } } } else if (!all) { vshError(ctl, "%s", @@ -13412,26 +13424,15 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) return false; } - if (all) { - if (VIR_ALLOC_N(data, VIR_DOMAIN_EVENT_ID_LAST) < 0) - goto cleanup; - for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - data[i].ctl = ctl; - data[i].loop = loop; - data[i].count = &count; - data[i].timestamp = timestamp; - data[i].cb = &vshEventCallbacks[i]; - data[i].id = -1; - } - } else { - if (VIR_ALLOC_N(data, 1) < 0) - goto cleanup; - data[0].ctl = ctl; - data[0].loop = vshCommandOptBool(cmd, "loop"); - data[0].count = &count; - data[0].timestamp = timestamp; - data[0].cb = &vshEventCallbacks[event]; - data[0].id = -1; + if (VIR_ALLOC_N(data, all ? VIR_DOMAIN_EVENT_ID_LAST : nevents - 1) < 0) + goto cleanup; + for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : nevents - 1); i++) { + data[i].ctl = ctl; + data[i].loop = loop; + data[i].count = &count; + data[i].timestamp = timestamp; + data[i].cb = &vshEventCallbacks[all ? i : eventIdxList[i]]; + data[i].id = -1; } if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; @@ -13441,9 +13442,9 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (vshEventStart(ctl, timeout) < 0) goto cleanup; - for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : nevents - 1); i++) { if ((data[i].id = virConnectDomainEventRegisterAny(priv->conn, dom, - all ? i : event, + all ? i : eventIdxList[i], data[i].cb->cb, &data[i], NULL)) < 0) { @@ -13476,13 +13477,14 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) cleanup: vshEventCleanup(ctl); if (data) { - for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : nevents - 1); i++) { if (data[i].id >= 0 && virConnectDomainEventDeregisterAny(priv->conn, data[i].id) < 0) ret = false; } VIR_FREE(data); } + VIR_FREE(eventIdxList); virshDomainFree(dom); return ret; } -- 2.15.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list