提交 27fa42b2 编写于 作者: P Peter Krempa

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.
上级 018010f0
......@@ -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 */
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册