From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS7MJ-0006Xu-02 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 14:45:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bS7MC-0002FZ-LZ for qemu-devel@nongnu.org; Tue, 26 Jul 2016 14:45:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51556) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS7MC-0002FV-Be for qemu-devel@nongnu.org; Tue, 26 Jul 2016 14:45:32 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u6QIii7s100551 for ; Tue, 26 Jul 2016 14:45:31 -0400 Received: from e06smtp06.uk.ibm.com (e06smtp06.uk.ibm.com [195.75.94.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 24dsrpc40c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 26 Jul 2016 14:45:31 -0400 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Jul 2016 19:45:29 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 05D8217D805A for ; Tue, 26 Jul 2016 19:47:00 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u6QIjRFe7602598 for ; Tue, 26 Jul 2016 18:45:27 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u6QIjQbh004223 for ; Tue, 26 Jul 2016 12:45:26 -0600 From: Sascha Silbe Date: Tue, 26 Jul 2016 20:44:59 +0200 Message-Id: <1469558699-23314-1-git-send-email-silbe@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] error: error_setg_errno(): errno may be clobbered List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Max Reitz , Halil Pasic , Kevin Wolf , Cornelia Huck , Michael Roth As a general policy, we want callers to save errno themselves. error_setg_internal() currently goes out of its way to preserve errno, so with the API documentation not mentioning it either way, callers might come to rely on the current behaviour of the implementation. Spell out that we don't want to make that promise. Signed-off-by: Sascha Silbe --- This came up during review of Halil's patch "block: improve error handling in raw_open" [1]. [1] mid:1469532873-78542-1-git-send-email-pasic@linux.vnet.ibm.com "[Qemu-devel] [PATCH v2 1/1] block: improve error handling in raw_open" by Halil Pasic , sent on 2016-07-26. include/qapi/error.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index 0576659..e5417e9 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -170,6 +170,11 @@ void error_setg_internal(Error **errp, * Just like error_setg(), with @os_error info added to the message. * If @os_error is non-zero, ": " + strerror(os_error) is appended to * the human-readable error message. + * + * Reminder: errno may get clobbered by almost any function call. If + * you need the value of errno for another purpose, save it before + * invoking error_setg_errno() (or any other function for that + * matter). */ #define error_setg_errno(errp, os_error, fmt, ...) \ error_setg_errno_internal((errp), __FILE__, __LINE__, __func__, \ -- 1.9.1