Received: from eggs.gnu.org ([2001:4830:134:3::10]:42382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIYpi-0007ym-Hl for qemu-devel@nongnu.org; Fri, 24 Jul 2015 04:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIYph-0001Ks-7K for qemu-devel@nongnu.org; Fri, 24 Jul 2015 04:59:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIYph-0001Ko-1n for qemu-devel@nongnu.org; Fri, 24 Jul 2015 04:59:57 -0400 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 (Postfix) with ESMTPS id 9AE688EA20 for ; Fri, 24 Jul 2015 08:59:56 +0000 (UTC) From: Markus Armbruster References: <1437660098-4584-1-git-send-email-armbru@redhat.com> <1437660098-4584-2-git-send-email-armbru@redhat.com> <55B0FC5A.9010906@redhat.com> Date: Fri, 24 Jul 2015 10:59:54 +0200 In-Reply-To: <55B0FC5A.9010906@redhat.com> (Eric Blake's message of "Thu, 23 Jul 2015 08:38:18 -0600") Message-ID: <87oaj2c4mt.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 1/7] error: De-duplicate code creating Error objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: pbonzini@redhat.com, mst@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com Eric Blake writes: > On 07/23/2015 08:01 AM, Markus Armbruster wrote: >> Duplicated when commit 680d16d added error_set_errno(), and again when >> commit 20840d4 added error_set_win32(). >> >> Make the original copy in error_set() reusable by factoring out >> error_setv(), then rewrite error_set_errno() and error_set_win32() on >> top of it. >> >> Signed-off-by: Markus Armbruster >> Reviewed-by: Eric Blake >> --- >> util/error.c | 70 ++++++++++++++++++++++-------------------------------------- >> 1 file changed, 26 insertions(+), 44 deletions(-) >> > >> if (os_errno != 0) { >> - err->msg = g_strdup_printf("%s: %s", msg1, strerror(os_errno)); >> - g_free(msg1); >> - } else { >> - err->msg = msg1; >> + msg = (*errp)->msg; >> + (*errp)->msg = g_strdup_printf("%s: %s", msg, strerror(os_errno)); > > Unrelated comment, so doesn't change R-b: > > strerror() is not required to be thread-safe, and can return NULL on > error. Do we care? Quoting strerror(3): POSIX.1-2001 permits strerror() to set errno if the call encounters an error, but does not specify what value should be returned as the function result in the event of an error. On some systems, strerror() returns NULL if the error number is unknown. On other systems, strerror() returns a string something like "Error nnn occurred" and sets errno to EINVAL if the error number is unknown. C99 and POSIX.1-2008 require the return value to be non-NULL. We already rely on strerror() behaving nicely in many, many places. Let's not start worrying about rotten, NULL-returning implementations until we run into one. I don't want to hand-wave thread safety worries away similarly. However, this patch doesn't add strerror() uses. If we want to discuss the existing potential problems, I feel we should start a new thread.