提交 04315514 编写于 作者: S Supriya Kannery 提交者: Eric Blake

virsh: fix regression in log to file

Commit 36deff04 introduced a regression due to which virsh is not able
to log to a file - msg_buf was changed from an array to a pointer
without corresponding change to usage of "sizeof()".

Fix regression in virsh logging
Signed-off-by: NSupriya Kannery <supriyak@in.ibm.com>
上级 0e7c7b8b
......@@ -169,6 +169,7 @@ Patches have also been contributed by:
Richard Laager <rlaager@wiktel.com>
Mark Wu <dwu@redhat.com>
Yufang Zhang <yuzhang@redhat.com>
Supriya Kannery <supriyak@in.ibm.com>
[....send patches to get your name here....]
......
......@@ -12227,7 +12227,8 @@ vshOpenLogFile(vshControl *ctl)
* Outputting an error to log file.
*/
static void
vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, va_list ap)
vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
va_list ap)
{
char *msg_buf;
const char *lvl = "";
......@@ -12246,7 +12247,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, va_list
*/
gettimeofday(&stTimeval, NULL);
stTm = localtime(&stTimeval.tv_sec);
snprintf(msg_buf, sizeof(msg_buf),
snprintf(msg_buf, MSG_BUFFER,
"[%d.%02d.%02d %02d:%02d:%02d ",
(1900 + stTm->tm_year),
(1 + stTm->tm_mon),
......@@ -12254,7 +12255,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, va_list
(stTm->tm_hour),
(stTm->tm_min),
(stTm->tm_sec));
snprintf(msg_buf + strlen(msg_buf), sizeof(msg_buf) - strlen(msg_buf),
snprintf(msg_buf + strlen(msg_buf), MSG_BUFFER - strlen(msg_buf),
"%s] ", SIGN_NAME);
switch (log_level) {
case VSH_ERR_DEBUG:
......@@ -12276,13 +12277,13 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, va_list
lvl = LVL_DEBUG;
break;
}
snprintf(msg_buf + strlen(msg_buf), sizeof(msg_buf) - strlen(msg_buf),
snprintf(msg_buf + strlen(msg_buf), MSG_BUFFER - strlen(msg_buf),
"%s ", lvl);
vsnprintf(msg_buf + strlen(msg_buf), sizeof(msg_buf) - strlen(msg_buf),
vsnprintf(msg_buf + strlen(msg_buf), MSG_BUFFER - strlen(msg_buf),
msg_format, ap);
if (msg_buf[strlen(msg_buf) - 1] != '\n')
snprintf(msg_buf + strlen(msg_buf), sizeof(msg_buf) - strlen(msg_buf), "\n");
snprintf(msg_buf + strlen(msg_buf), MSG_BUFFER - strlen(msg_buf), "\n");
/* write log */
if (safewrite(ctl->log_fd, msg_buf, strlen(msg_buf)) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册