From patchwork Wed Mar 16 10:04:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8597141 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C161F9F44D for ; Wed, 16 Mar 2016 10:04:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08E38202F0 for ; Wed, 16 Mar 2016 10:04:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3ECDA20225 for ; Wed, 16 Mar 2016 10:04:29 +0000 (UTC) Received: from localhost ([::1]:54253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8JY-0008QT-Mw for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 06:04:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8JR-0008QN-5O for qemu-devel@nongnu.org; Wed, 16 Mar 2016 06:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ag8JN-0002tI-R5 for qemu-devel@nongnu.org; Wed, 16 Mar 2016 06:04:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8JN-0002su-K1 for qemu-devel@nongnu.org; Wed, 16 Mar 2016 06:04:17 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 4590912B36 for ; Wed, 16 Mar 2016 10:04:17 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-49.ams2.redhat.com [10.36.116.49]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GA4FGd006487 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 16 Mar 2016 06:04:16 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BB3EA303F916; Wed, 16 Mar 2016 11:04:14 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 16 Mar 2016 11:04:14 +0100 Message-Id: <1458122654-17305-2-git-send-email-armbru@redhat.com> In-Reply-To: <1458122654-17305-1-git-send-email-armbru@redhat.com> References: <1458122654-17305-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] error: ensure errno detail is printed with error_abort X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Daniel P. Berrange" When &error_abort is passed in, the error reporting code will print the current error message and then abort() the process. Unfortunately at the time it aborts, we've not yet appended the errno detail. This makes debugging certain problems significantly harder as the log is incomplete. Signed-off-by: Daniel P. Berrange Message-Id: <1457544504-8548-22-git-send-email-berrange@redhat.com> Signed-off-by: Markus Armbruster --- util/error.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/util/error.c b/util/error.c index 471b8b3..47f93af 100644 --- a/util/error.c +++ b/util/error.c @@ -44,7 +44,8 @@ static void error_handle_fatal(Error **errp, Error *err) static void error_setv(Error **errp, const char *src, int line, const char *func, - ErrorClass err_class, const char *fmt, va_list ap) + ErrorClass err_class, const char *fmt, va_list ap, + const char *suffix) { Error *err; int saved_errno = errno; @@ -56,6 +57,11 @@ static void error_setv(Error **errp, err = g_malloc0(sizeof(*err)); err->msg = g_strdup_vprintf(fmt, ap); + if (suffix) { + char *msg = err->msg; + err->msg = g_strdup_printf("%s: %s", msg, suffix); + g_free(msg); + } err->err_class = err_class; err->src = src; err->line = line; @@ -74,7 +80,7 @@ void error_set_internal(Error **errp, va_list ap; va_start(ap, fmt); - error_setv(errp, src, line, func, err_class, fmt, ap); + error_setv(errp, src, line, func, err_class, fmt, ap, NULL); va_end(ap); } @@ -85,7 +91,7 @@ void error_setg_internal(Error **errp, va_list ap; va_start(ap, fmt); - error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap); + error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap, NULL); va_end(ap); } @@ -94,7 +100,6 @@ void error_setg_errno_internal(Error **errp, int os_errno, const char *fmt, ...) { va_list ap; - char *msg; int saved_errno = errno; if (errp == NULL) { @@ -102,15 +107,10 @@ void error_setg_errno_internal(Error **errp, } va_start(ap, fmt); - error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap); + error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap, + os_errno != 0 ? strerror(os_errno) : NULL); va_end(ap); - if (os_errno != 0) { - msg = (*errp)->msg; - (*errp)->msg = g_strdup_printf("%s: %s", msg, strerror(os_errno)); - g_free(msg); - } - errno = saved_errno; } @@ -174,24 +174,22 @@ void error_setg_win32_internal(Error **errp, int win32_err, const char *fmt, ...) { va_list ap; - char *msg1, *msg2; + char *suffix = NULL; if (errp == NULL) { return; } - va_start(ap, fmt); - error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap); - va_end(ap); - if (win32_err != 0) { - msg1 = (*errp)->msg; - msg2 = g_win32_error_message(win32_err); - (*errp)->msg = g_strdup_printf("%s: %s (error: %x)", msg1, msg2, - (unsigned)win32_err); - g_free(msg2); - g_free(msg1); + suffix = g_win32_error_message(win32_err); } + + va_start(ap, fmt); + error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, + fmt, ap, suffix); + va_end(ap); + + g_free(suffix); } #endif