From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSiPN-0000FN-7k for qemu-devel@nongnu.org; Thu, 28 Jul 2016 06:19:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSiPG-0002Po-7A for qemu-devel@nongnu.org; Thu, 28 Jul 2016 06:19:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSiPG-0002Or-24 for qemu-devel@nongnu.org; Thu, 28 Jul 2016 06:19:10 -0400 From: Markus Armbruster References: <1469611466-31574-1-git-send-email-silbe@linux.vnet.ibm.com> <57991CC1.40003@redhat.com> Date: Thu, 28 Jul 2016 12:19:06 +0200 In-Reply-To: <57991CC1.40003@redhat.com> (Eric Blake's message of "Wed, 27 Jul 2016 14:42:41 -0600") Message-ID: <87twfaysit.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] error: error_setg_errno(): errno gets preserved List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Sascha Silbe , qemu-devel@nongnu.org, Kevin Wolf , Halil Pasic , Michael Roth , Cornelia Huck , Max Reitz Eric Blake writes: > On 07/27/2016 03:24 AM, Sascha Silbe wrote: >> C11 allows errno to be clobbered by pretty much any library function >> call, so in general callers need to take care to save errno before >> calling other functions. >> >> However, for error reporting functions this is rather awkward and can >> make the code on the caller side more complicated than >> necessary. error_setg_errno() already takes care of preserving errno >> and some functions rely on that, so just promise that we continue to >> do so in the future. >> >> Signed-off-by: Sascha Silbe >> --- >> >> Alternative approach to "error: error_setg_errno(): errno may be >> clobbered" [1]. > > I like this alternative better. > > >> +++ b/include/qapi/error.h >> @@ -170,6 +170,9 @@ 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. >> + * >> + * The value of errno (which usually can get clobbered by almost any >> + * function call) will be preserved. >> */ >> #define error_setg_errno(errp, os_error, fmt, ...) \ >> error_setg_errno_internal((errp), __FILE__, __LINE__, __func__, \ > > Do we need/want to make the guarantee of preserving errno across any of > the other functions and macros declared in error.h? I guess we should for the ones that preserve errno, to make that preservation actually useful. These are: error_setv(), error_setg_errno_internal(), error_append_hint(). Indirectly: error_set_internal(), error_set(), error_setg_internal(), error_setg(), error_setg_file_open_internal(), error_setg_file_open(), possibly error_setg_win32_internal() and error_setg_win32().