From nobody Sat Apr 27 14:27:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1511354227861291.48260439594003; Wed, 22 Nov 2017 04:37:07 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BE49780D0; Wed, 22 Nov 2017 12:37:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA74A60F91; Wed, 22 Nov 2017 12:37:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A19524BB79; Wed, 22 Nov 2017 12:37:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAMCb1sb028864 for ; Wed, 22 Nov 2017 07:37:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id A625A60C80; Wed, 22 Nov 2017 12:37:01 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A62860F9F for ; Wed, 22 Nov 2017 12:36:58 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 8AAA7100425; Wed, 22 Nov 2017 13:36:57 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 22 Nov 2017 13:36:54 +0100 Message-Id: <579d5c19e080ee3d7123cd2bcb952983d6d871f0.1511354114.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] qemu: Properly skip "char device redirected to" in QEMU log X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 22 Nov 2017 12:37:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When reading QEMU log for reporting it as an error message, we want to skip "char device redirected to" line. However, this string is not printed at the beginning of a line, which means STRPREFIX will never find it. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6d242b1b51..3da297c16f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1847,7 +1847,7 @@ qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, c= har **msg) while ((eol =3D strchr(filter_next, '\n'))) { *eol =3D '\0'; if (virLogProbablyLogMessage(filter_next) || - STRPREFIX(filter_next, "char device redirected to")) { + strstr(filter_next, "char device redirected to")) { size_t skip =3D (eol + 1) - filter_next; memmove(filter_next, eol + 1, buf + got - eol); got -=3D skip; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 14:27:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1511354238355423.4166116339851; Wed, 22 Nov 2017 04:37:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EC50A58B9; Wed, 22 Nov 2017 12:37:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E93463F84; Wed, 22 Nov 2017 12:37:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 46B324A46A; Wed, 22 Nov 2017 12:37:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAMCb1Ko028865 for ; Wed, 22 Nov 2017 07:37:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id A763C60E3D; Wed, 22 Nov 2017 12:37:01 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B1D760FA2 for ; Wed, 22 Nov 2017 12:36:58 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 8D3F91004F4; Wed, 22 Nov 2017 13:36:57 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 22 Nov 2017 13:36:55 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] vierror: Define VIR_ERROR_MAX_LENGTH macro X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 22 Nov 2017 12:37:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" And use it instead of a magic 1024 constant. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/util/virerror.c | 6 +++--- src/util/virerror.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/virerror.c b/src/util/virerror.c index 1f15c5dbbe..91022c3b63 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1480,7 +1480,7 @@ void virReportErrorHelper(int domcode, { int save_errno =3D errno; va_list args; - char errorMessage[1024]; + char errorMessage[VIR_ERROR_MAX_LENGTH]; const char *virerr; =20 if (fmt) { @@ -1541,8 +1541,8 @@ void virReportSystemErrorFull(int domcode, const char *fmt, ...) { int save_errno =3D errno; - char strerror_buf[1024]; - char msgDetailBuf[1024]; + char strerror_buf[VIR_ERROR_MAX_LENGTH]; + char msgDetailBuf[VIR_ERROR_MAX_LENGTH]; =20 const char *errnoDetail =3D virStrerror(theerrno, strerror_buf, sizeof(strerror_buf)); diff --git a/src/util/virerror.h b/src/util/virerror.h index fba18ba589..cf434f45fc 100644 --- a/src/util/virerror.h +++ b/src/util/virerror.h @@ -24,6 +24,8 @@ =20 # include "internal.h" =20 +# define VIR_ERROR_MAX_LENGTH 1024 + extern virErrorFunc virErrorHandler; extern void *virUserData; =20 --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 14:27:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1511354226480677.0752752064935; Wed, 22 Nov 2017 04:37:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37328356C7; Wed, 22 Nov 2017 12:37:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D92D17C2D; Wed, 22 Nov 2017 12:37:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F15E41800BDC; Wed, 22 Nov 2017 12:37:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAMCb0VC028854 for ; Wed, 22 Nov 2017 07:37:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE1C517C21; Wed, 22 Nov 2017 12:37:00 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9281912A40 for ; Wed, 22 Nov 2017 12:36:58 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 911871005AC; Wed, 22 Nov 2017 13:36:57 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 22 Nov 2017 13:36:56 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] qemu: Use the end of QEMU log for reporting errors X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 22 Nov 2017 12:37:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When QEMU dies, we read its output stored in a log file and use it for reporting a hopefully useful error. However, virReportError will trim the message to (VIR_ERROR_MAX_LENGTH - 1) characters, which means the end of the log (which likely contains the error message we want to report) may get lost. We should trim the beginning of the log instead. https://bugzilla.redhat.com/show_bug.cgi?id=3D1335534 Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_process.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3da297c16f..214f41dd85 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1827,17 +1827,24 @@ qemuConnectMonitor(virQEMUDriverPtr driver, virDoma= inObjPtr vm, int asyncJob, * qemuProcessReadLog: Read log file of a qemu VM * @logCtxt: the domain log context * @msg: pointer to buffer to store the read messages in + * @max: maximum length of the message returned in @msg * * Reads log of a qemu VM. Skips messages not produced by qemu or irreleva= nt - * messages. Returns returns 0 on success or -1 on error + * messages. If @max is not zero, @msg will contain at most @max characters + * from the end of the log and @msg will start after a new line if possibl= e. + * + * Returns 0 on success or -1 on error */ static int -qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, char **msg) +qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, + char **msg, + size_t max) { char *buf; ssize_t got; char *eol; char *filter_next; + size_t skip; =20 if ((got =3D qemuDomainLogContextRead(logCtxt, &buf)) < 0) return -1; @@ -1848,7 +1855,7 @@ qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, c= har **msg) *eol =3D '\0'; if (virLogProbablyLogMessage(filter_next) || strstr(filter_next, "char device redirected to")) { - size_t skip =3D (eol + 1) - filter_next; + skip =3D (eol + 1) - filter_next; memmove(filter_next, eol + 1, buf + got - eol); got -=3D skip; } else { @@ -1863,6 +1870,19 @@ qemuProcessReadLog(qemuDomainLogContextPtr logCtxt, = char **msg) buf[got - 1] =3D '\0'; got--; } + + if (max > 0 && got > max) { + skip =3D got - max; + + if (buf[skip - 1] !=3D '\n' && + (eol =3D strchr(buf + skip, '\n')) && + !virStringIsEmpty(eol + 1)) + skip =3D eol + 1 - buf; + + memmove(buf, buf + skip, got - skip + 1); + got -=3D skip; + } + ignore_value(VIR_REALLOC_N_QUIET(buf, got + 1)); *msg =3D buf; return 0; @@ -1874,8 +1894,14 @@ qemuProcessReportLogError(qemuDomainLogContextPtr lo= gCtxt, const char *msgprefix) { char *logmsg =3D NULL; + size_t max; =20 - if (qemuProcessReadLog(logCtxt, &logmsg) < 0) + max =3D VIR_ERROR_MAX_LENGTH - 1; + max -=3D strlen(msgprefix); + /* The length of the formatting string minus two '%s' */ + max -=3D strlen(_("%s: %s")) - 4; + + if (qemuProcessReadLog(logCtxt, &logmsg, max) < 0) return -1; =20 virResetLastError(); --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list