提交 8eaa7089 编写于 作者: M Michal Privoznik

Use g_strdup_vprintf() instead of virVasprintf() everywhere

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
上级 d36a15f9
......@@ -74,8 +74,7 @@ libvirt_vmessage(xentoollog_logger *logger_in,
if (level < lg->minLevel)
return;
if (virVasprintf(&message, format, args) < 0)
return;
message = g_strdup_vprintf(format, args);
/* Should we print to a domain-specific log file? */
if ((start = strstr(message, ": Domain ")) &&
......
......@@ -9430,8 +9430,7 @@ int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
va_start(argptr, fmt);
if (virVasprintf(&message, fmt, argptr) < 0)
goto cleanup;
message = g_strdup_vprintf(fmt, argptr);
if (!ctxt->manager &&
lseek(ctxt->writefd, 0, SEEK_END) < 0) {
virReportSystemError(errno, "%s",
......@@ -9524,8 +9523,7 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
va_start(ap, fmt);
if (virVasprintf(&message, fmt, ap) < 0)
goto cleanup;
message = g_strdup_vprintf(fmt, ap);
VIR_DEBUG("Append log message (vm='%s' message='%s) stdioLogD=%d",
vm->def->name, message, cfg->stdioLogD);
......
......@@ -110,8 +110,7 @@ void virAuditSend(virLogSourcePtr source,
#endif
va_start(args, fmt);
if (virVasprintf(&str, fmt, args) < 0)
VIR_WARN("Out of memory while formatting audit message");
str = g_strdup_vprintf(fmt, args);
va_end(args);
if (auditlog && str) {
......
......@@ -1314,11 +1314,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
return;
va_start(list, format);
if (virVasprintf(&env, format, list) < 0) {
cmd->has_error = ENOMEM;
va_end(list);
return;
}
env = g_strdup_vprintf(format, list);
va_end(list);
virCommandAddEnv(cmd, env);
......@@ -1541,11 +1537,7 @@ virCommandAddArgFormat(virCommandPtr cmd, const char *format, ...)
return;
va_start(list, format);
if (virVasprintf(&arg, format, list) < 0) {
cmd->has_error = ENOMEM;
va_end(list);
return;
}
arg = g_strdup_vprintf(format, list);
va_end(list);
/* Arg plus trailing NULL. */
......
......@@ -830,7 +830,7 @@ virRaiseErrorFull(const char *filename,
} else {
va_list ap;
va_start(ap, fmt);
ignore_value(virVasprintfQuiet(&str, fmt, ap));
str = g_strdup_vprintf(fmt, ap);
va_end(ap);
}
......@@ -1484,16 +1484,13 @@ virLastErrorPrefixMessage(const char *fmt, ...)
return;
va_start(args, fmt);
if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0)
goto cleanup;
fmtmsg = g_strdup_vprintf(fmt, args);
va_end(args);
newmsg = g_strdup_printf("%s: %s", fmtmsg, err->message);
VIR_FREE(err->message);
err->message = g_steal_pointer(&newmsg);
cleanup:
va_end(args);
errno = save_errno;
}
......@@ -3374,9 +3374,9 @@ virFileRemoveLastComponent(char *path)
/**
* virFilePrintf:
*
* A replacement for fprintf() which uses virVasprintf to
* ensure that portable string format placeholders can be
* used, since gnulib's fprintf() replacement is not
* A replacement for fprintf() which uses g_strdup_vprintf
* to ensure that portable string format placeholders can
* be used, since gnulib's fprintf() replacement is not
* LGPLV2+ compatible
*/
int virFilePrintf(FILE *fp, const char *msg, ...)
......@@ -3387,8 +3387,7 @@ int virFilePrintf(FILE *fp, const char *msg, ...)
va_start(vargs, msg);
if (virVasprintf(&str, msg, vargs) < 0)
goto cleanup;
str = g_strdup_vprintf(msg, vargs);
ret = strlen(str);
if (fwrite(str, 1, ret, fp) != ret) {
......@@ -3397,7 +3396,6 @@ int virFilePrintf(FILE *fp, const char *msg, ...)
ret = -1;
}
cleanup:
va_end(vargs);
return ret;
......@@ -4149,10 +4147,7 @@ virFileReadValueInt(int *value, const char *format, ...)
va_list ap;
va_start(ap, format);
if (virVasprintf(&path, format, ap) < 0) {
va_end(ap);
return -1;
}
path = g_strdup_vprintf(format, ap);
va_end(ap);
if (!virFileExists(path))
......@@ -4192,10 +4187,7 @@ virFileReadValueUint(unsigned int *value, const char *format, ...)
va_list ap;
va_start(ap, format);
if (virVasprintf(&path, format, ap) < 0) {
va_end(ap);
return -1;
}
path = g_strdup_vprintf(format, ap);
va_end(ap);
if (!virFileExists(path))
......@@ -4236,10 +4228,7 @@ virFileReadValueScaledInt(unsigned long long *value, const char *format, ...)
va_list ap;
va_start(ap, format);
if (virVasprintf(&path, format, ap) < 0) {
va_end(ap);
return -1;
}
path = g_strdup_vprintf(format, ap);
va_end(ap);
if (!virFileExists(path))
......@@ -4282,10 +4271,7 @@ virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...)
va_list ap;
va_start(ap, format);
if (virVasprintf(&path, format, ap) < 0) {
va_end(ap);
return -1;
}
path = g_strdup_vprintf(format, ap);
va_end(ap);
if (!virFileExists(path))
......@@ -4323,10 +4309,7 @@ virFileReadValueString(char **value, const char *format, ...)
va_list ap;
va_start(ap, format);
if (virVasprintf(&path, format, ap) < 0) {
va_end(ap);
return -1;
}
path = g_strdup_vprintf(format, ap);
va_end(ap);
if (!virFileExists(path))
......
......@@ -509,19 +509,15 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewall,
VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule);
va_start(list, fmt);
if (virVasprintf(&arg, fmt, list) < 0)
goto no_memory;
arg = g_strdup_vprintf(fmt, list);
va_end(list);
ADD_ARG(rule, arg);
va_end(list);
return;
no_memory:
firewall->err = ENOMEM;
va_end(list);
}
......
......@@ -594,8 +594,7 @@ virLogVMessage(virLogSourcePtr source,
/*
* serialize the error message, add level and timestamp
*/
if (virVasprintfQuiet(&str, fmt, vargs) < 0)
goto cleanup;
str = g_strdup_vprintf(fmt, vargs);
virLogFormatString(&msg, linenr, funcname, priority, str);
......
......@@ -89,8 +89,8 @@ testEventReport(const char *name, bool failed, const char *msg, ...)
char *str = NULL;
struct testEventResultData data;
if (msg && virVasprintfQuiet(&str, msg, vargs) != 0)
failed = true;
if (msg)
str = g_strdup_vprintf(msg, vargs);
data.failed = failed;
data.msg = str;
......
......@@ -186,15 +186,13 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...)
va_start(msgargs, errmsg);
if (virVasprintf(&msg, errmsg, msgargs) < 0)
goto cleanup;
msg = g_strdup_vprintf(errmsg, msgargs);
jsonmsg = g_strdup_printf("{ \"error\": " " { \"desc\": \"%s\", "
" \"class\": \"UnexpectedCommand\" } }", msg);
ret = qemuMonitorTestAddResponse(test, jsonmsg);
cleanup:
va_end(msgargs);
return ret;
}
......
......@@ -59,10 +59,7 @@ void virHostMsgCheck(const char *prefix,
return;
va_start(args, format);
if (virVasprintf(&msg, format, args) < 0) {
perror("malloc");
abort();
}
msg = g_strdup_vprintf(format, args);
va_end(args);
fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg);
......@@ -120,10 +117,7 @@ void virHostMsgFail(virHostValidateLevel level,
return;
va_start(args, format);
if (virVasprintf(&msg, format, args) < 0) {
perror("malloc");
abort();
}
msg = g_strdup_vprintf(format, args);
va_end(args);
if (virHostMsgWantEscape())
......
......@@ -1847,11 +1847,7 @@ vshDebug(vshControl *ctl, int level, const char *format, ...)
va_end(ap);
va_start(ap, format);
if (virVasprintf(&str, format, ap) < 0) {
/* Skip debug messages on low memory */
va_end(ap);
return;
}
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
......@@ -1867,8 +1863,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
return;
va_start(ap, format);
if (virVasprintfQuiet(&str, format, ap) < 0)
vshErrorOOM();
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
......@@ -1882,8 +1877,7 @@ vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...)
char *str;
va_start(ap, format);
if (virVasprintfQuiet(&str, format, ap) < 0)
vshErrorOOM();
str = g_strdup_vprintf(format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
......@@ -2015,9 +2009,7 @@ vshError(vshControl *ctl, const char *format, ...)
fputs(_("error: "), stderr);
va_start(ap, format);
/* We can't recursively call vshError on an OOM situation, so ignore
failure here. */
ignore_value(virVasprintf(&str, format, ap));
str = g_strdup_vprintf(format, ap);
va_end(ap);
fprintf(stderr, "%s\n", NULLSTR(str));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册