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:
parent
13af21fb74
commit
9dc2a41f1e
@ -286,6 +286,33 @@ struct virshDomEventData {
|
|||||||
};
|
};
|
||||||
typedef struct virshDomEventData 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:
|
* virshEventPrint:
|
||||||
*
|
*
|
||||||
@ -305,25 +332,10 @@ virshEventPrint(virshDomEventData *data,
|
|||||||
if (!(msg = virBufferContentAndReset(buf)))
|
if (!(msg = virBufferContentAndReset(buf)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!data->loop && *data->count)
|
virshEventPrintf(data, "%s", msg);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED,
|
virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED,
|
||||||
virDomainPtr dom,
|
virDomainPtr dom,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user