mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virsh: Do not format messages twice
The same message was formatted both in vshOutputLogFile and in vshDebug and vshError functions. This patch refactor vshOutputLogFile and its callers to only format each message once. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
af0507e2e4
commit
575b3ea925
27
tools/vsh.c
27
tools/vsh.c
@ -1967,13 +1967,12 @@ vshDebug(vshControl *ctl, int level, const char *format, ...)
|
||||
if (level < ctl->debug)
|
||||
return;
|
||||
|
||||
va_start(ap, format);
|
||||
vshOutputLogFile(ctl, level, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
va_start(ap, format);
|
||||
str = g_strdup_vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
vshOutputLogFile(ctl, level, str);
|
||||
|
||||
fputs(str, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
@ -2118,11 +2117,12 @@ vshError(vshControl *ctl, const char *format, ...)
|
||||
va_list ap;
|
||||
g_autofree char *str = NULL;
|
||||
|
||||
if (ctl != NULL) {
|
||||
va_start(ap, format);
|
||||
vshOutputLogFile(ctl, VSH_ERR_ERROR, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_start(ap, format);
|
||||
str = g_strdup_vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (ctl)
|
||||
vshOutputLogFile(ctl, VSH_ERR_ERROR, str);
|
||||
|
||||
/* Most output is to stdout, but if someone ran virsh 2>&1, then
|
||||
* printing to stderr will not interleave correctly with stdout
|
||||
@ -2130,10 +2130,6 @@ vshError(vshControl *ctl, const char *format, ...)
|
||||
fflush(stdout);
|
||||
fputs(_("error: "), stderr);
|
||||
|
||||
va_start(ap, format);
|
||||
str = g_strdup_vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s\n", NULLSTR(str));
|
||||
fflush(stderr);
|
||||
}
|
||||
@ -2337,8 +2333,7 @@ vshOpenLogFile(vshControl *ctl)
|
||||
* Outputting an error to log file.
|
||||
*/
|
||||
void
|
||||
vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
|
||||
va_list ap)
|
||||
vshOutputLogFile(vshControl *ctl, int log_level, const char *msg)
|
||||
{
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
g_autofree char *str = NULL;
|
||||
@ -2381,7 +2376,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
|
||||
break;
|
||||
}
|
||||
virBufferAsprintf(&buf, "%s ", lvl);
|
||||
virBufferVasprintf(&buf, msg_format, ap);
|
||||
virBufferAddStr(&buf, msg);
|
||||
virBufferTrim(&buf, "\n");
|
||||
virBufferAddChar(&buf, '\n');
|
||||
|
||||
|
@ -241,9 +241,7 @@ struct _vshCmdGrp {
|
||||
void vshError(vshControl *ctl, const char *format, ...)
|
||||
G_GNUC_PRINTF(2, 3);
|
||||
void vshOpenLogFile(vshControl *ctl);
|
||||
void vshOutputLogFile(vshControl *ctl, int log_level, const char *format,
|
||||
va_list ap)
|
||||
G_GNUC_PRINTF(3, 0);
|
||||
void vshOutputLogFile(vshControl *ctl, int log_level, const char *msg);
|
||||
void vshCloseLogFile(vshControl *ctl);
|
||||
|
||||
int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd,
|
||||
|
Loading…
x
Reference in New Issue
Block a user