diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bf65a60cae758be79ecc9c853886df53ac8e8e01..6dd75e224d2e5668ebc24e15498905c50fc616b7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6360,7 +6360,9 @@ static const vshCmdOptDef opts_vcpupin[] = { * Helper function to print vcpupin info. */ static bool -virshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen) +virshPrintPinInfo(vshControl *ctl, + unsigned char *cpumap, + size_t cpumaplen) { char *str = NULL; @@ -6497,7 +6499,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) continue; vshPrint(ctl, "%4zu: ", i); - ret = virshPrintPinInfo(VIR_GET_CPUMAP(cpumap, cpumaplen, i), + ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i), cpumaplen); vshPrint(ctl, "\n"); if (!ret) @@ -6606,7 +6608,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity")); vshPrintExtra(ctl, "----------------------------------\n"); vshPrintExtra(ctl, " *: "); - ret = virshPrintPinInfo(cpumap, cpumaplen); + ret = virshPrintPinInfo(ctl, cpumap, cpumaplen); vshPrint(ctl, "\n"); } goto cleanup; @@ -6782,7 +6784,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < niothreads; i++) { vshPrint(ctl, " %-15u ", info[i]->iothread_id); - ignore_value(virshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen)); + ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpumaplen)); vshPrint(ctl, "\n"); virDomainIOThreadInfoFree(info[i]); } @@ -7875,9 +7877,9 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) goto cleanup; if (rem) - vshPrint("%s\n", _("Metadata removed")); + vshPrint(ctl, "%s\n", _("Metadata removed")); else - vshPrint("%s\n", _("Metadata modified")); + vshPrint(ctl, "%s\n", _("Metadata modified")); } else if (edit) { #define EDIT_GET_XML \ virshDomainGetEditMetadata(ctl, dom, uri, flags) @@ -7893,7 +7895,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) key, uri, flags) == 0) #include "virsh-edit.c" - vshPrint("%s\n", _("Metadata modified")); + vshPrint(ctl, "%s\n", _("Metadata modified")); } else { char *data; /* get */ diff --git a/tools/vsh.c b/tools/vsh.c index 91e3106aba7eeb5e546b10d4b10933c79a0bfc55..44674451f0c44a4b53827d8049566af079150c81 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1720,6 +1720,21 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) } +void +vshPrint(vshControl *ctl ATTRIBUTE_UNUSED, const char *format, ...) +{ + va_list ap; + char *str; + + va_start(ap, format); + if (virVasprintfQuiet(&str, format, ap) < 0) + vshErrorOOM(); + va_end(ap); + fputs(str, stdout); + VIR_FREE(str); +} + + bool vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED, const char chr ATTRIBUTE_UNUSED) diff --git a/tools/vsh.h b/tools/vsh.h index 0c5abdc5ac4fc1d9827961fc17731af37bf2d297..f6e40e64e80e46f41a6193ec9197b3c31ceeb5f2 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -300,6 +300,8 @@ const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv); int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); +void vshPrint(vshControl *ctl, const char *format, ...) + ATTRIBUTE_FMT_PRINTF(2, 3); void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); bool vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set); @@ -308,9 +310,6 @@ void vshDeinit(vshControl *ctl); void vshDebug(vshControl *ctl, int level, const char *format, ...) ATTRIBUTE_FMT_PRINTF(3, 4); -/* XXX: add batch support */ -# define vshPrint(_ctl, ...) vshPrintExtra(NULL, __VA_ARGS__) - /* User visible sort, so we want locale-specific case comparison. */ # define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) int vshNameSorter(const void *a, const void *b);