virsh: event: Introduce virshEventPrintf

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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2023-04-13 09:31:34 +02:00
parent 13af21fb74
commit 9dc2a41f1e

View File

@ -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,