1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

vsh: Replace vshPrint macro with function

The macro would eat the first parameter. In some cases the format string
for vshPrint was eaten. In other cases the calls referenced variables
which did not exist in the given context. Avoid errors by doing compile
time checking.
This commit is contained in:
Peter Krempa 2016-02-12 14:09:02 +01:00
parent 018010f05c
commit 27fa42b24c
3 changed files with 26 additions and 10 deletions

View File

@ -6360,7 +6360,9 @@ static const vshCmdOptDef opts_vcpupin[] = {
* Helper function to print vcpupin info. * Helper function to print vcpupin info.
*/ */
static bool static bool
virshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen) virshPrintPinInfo(vshControl *ctl,
unsigned char *cpumap,
size_t cpumaplen)
{ {
char *str = NULL; char *str = NULL;
@ -6497,7 +6499,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
continue; continue;
vshPrint(ctl, "%4zu: ", i); vshPrint(ctl, "%4zu: ", i);
ret = virshPrintPinInfo(VIR_GET_CPUMAP(cpumap, cpumaplen, i), ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i),
cpumaplen); cpumaplen);
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
if (!ret) if (!ret)
@ -6606,7 +6608,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity")); vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity"));
vshPrintExtra(ctl, "----------------------------------\n"); vshPrintExtra(ctl, "----------------------------------\n");
vshPrintExtra(ctl, " *: "); vshPrintExtra(ctl, " *: ");
ret = virshPrintPinInfo(cpumap, cpumaplen); ret = virshPrintPinInfo(ctl, cpumap, cpumaplen);
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
} }
goto cleanup; goto cleanup;
@ -6782,7 +6784,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < niothreads; i++) { for (i = 0; i < niothreads; i++) {
vshPrint(ctl, " %-15u ", info[i]->iothread_id); 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"); vshPrint(ctl, "\n");
virDomainIOThreadInfoFree(info[i]); virDomainIOThreadInfoFree(info[i]);
} }
@ -7875,9 +7877,9 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
if (rem) if (rem)
vshPrint("%s\n", _("Metadata removed")); vshPrint(ctl, "%s\n", _("Metadata removed"));
else else
vshPrint("%s\n", _("Metadata modified")); vshPrint(ctl, "%s\n", _("Metadata modified"));
} else if (edit) { } else if (edit) {
#define EDIT_GET_XML \ #define EDIT_GET_XML \
virshDomainGetEditMetadata(ctl, dom, uri, flags) virshDomainGetEditMetadata(ctl, dom, uri, flags)
@ -7893,7 +7895,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
key, uri, flags) == 0) key, uri, flags) == 0)
#include "virsh-edit.c" #include "virsh-edit.c"
vshPrint("%s\n", _("Metadata modified")); vshPrint(ctl, "%s\n", _("Metadata modified"));
} else { } else {
char *data; char *data;
/* get */ /* get */

View File

@ -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 bool
vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED, vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED,
const char chr ATTRIBUTE_UNUSED) const char chr ATTRIBUTE_UNUSED)

View File

@ -300,6 +300,8 @@ const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd,
bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv); bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv);
int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); 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, ...) void vshPrintExtra(vshControl *ctl, const char *format, ...)
ATTRIBUTE_FMT_PRINTF(2, 3); ATTRIBUTE_FMT_PRINTF(2, 3);
bool vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set); 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, ...) void vshDebug(vshControl *ctl, int level, const char *format, ...)
ATTRIBUTE_FMT_PRINTF(3, 4); 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. */ /* User visible sort, so we want locale-specific case comparison. */
# define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) # define vshStrcasecmp(S1, S2) strcasecmp(S1, S2)
int vshNameSorter(const void *a, const void *b); int vshNameSorter(const void *a, const void *b);