From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeUyV-0005dM-Jj for qemu-devel@nongnu.org; Thu, 07 Nov 2013 14:10:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VeUyP-0000df-JO for qemu-devel@nongnu.org; Thu, 07 Nov 2013 14:10:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeUyP-0000dN-B1 for qemu-devel@nongnu.org; Thu, 07 Nov 2013 14:10:33 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA7JAWVQ005367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Nov 2013 14:10:32 -0500 From: Max Reitz Date: Thu, 7 Nov 2013 20:10:29 +0100 Message-Id: <1383851429-9213-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] util/error: Save errno from clobbering List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz There may be calls to error_setg() and especially error_setg_errno() which blindly (and until now wrongly) assume these functions not to clobber errno (e.g., they pass errno to error_setg_errno() and return -errno afterwards). Instead of trying to find and fix all of these constructs, just make sure error_setg() and error_setg_errno() indeed do not clobber errno. Suggested-by: Eric Blake Signed-off-by: Max Reitz --- util/error.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/error.c b/util/error.c index ec0faa6..3ee362a 100644 --- a/util/error.c +++ b/util/error.c @@ -27,6 +27,7 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { Error *err; va_list ap; + int saved_errno = errno; if (errp == NULL) { return; @@ -41,6 +42,8 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) err->err_class = err_class; *errp = err; + + errno = saved_errno; } void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, @@ -49,6 +52,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, Error *err; char *msg1; va_list ap; + int saved_errno = errno; if (errp == NULL) { return; @@ -69,6 +73,8 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, err->err_class = err_class; *errp = err; + + errno = saved_errno; } void error_setg_file_open(Error **errp, int os_errno, const char *filename) -- 1.8.4.2