Extract internals of virshEventPrint into a function that can take the format string. The function will be used in upcoming patches which make the event formatting translatable. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- tools/virsh-domain-event.c | 46 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index 1ed204fa9a..a8a321590c 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -286,6 +286,33 @@ struct virshDomEventData { }; typedef struct virshDomEventData virshDomEventData; + +static void G_GNUC_PRINTF(2, 3) +virshEventPrintf(virshDomEventData *data, + const char *fmt, + ...) +{ + va_list ap; + + if (!data->loop && *data->count) + return; + + if (data->timestamp) { + char timestamp[VIR_TIME_STRING_BUFLEN] = ""; + + ignore_value(virTimeStringNowRaw(timestamp)); + vshPrint(data->ctl, "%s: ", timestamp); + } + + va_start(ap, fmt); + vshPrintVa(data->ctl, fmt, ap); + va_end(ap); + + (*data->count)++; + if (!data->loop) + vshEventDone(data->ctl); +} + /** * virshEventPrint: * @@ -305,25 +332,10 @@ virshEventPrint(virshDomEventData *data, if (!(msg = virBufferContentAndReset(buf))) return; - if (!data->loop && *data->count) - return; - - if (data->timestamp) { - char timestamp[VIR_TIME_STRING_BUFLEN]; - - if (virTimeStringNowRaw(timestamp) < 0) - timestamp[0] = '\0'; - - vshPrint(data->ctl, "%s: %s", timestamp, msg); - } else { - vshPrint(data->ctl, "%s", msg); - } - - (*data->count)++; - if (!data->loop) - vshEventDone(data->ctl); + virshEventPrintf(data, "%s", msg); } + static void virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED, virDomainPtr dom, -- 2.39.2