Received: from eggs.gnu.org ([140.186.70.92]:49187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwwWV-0002iw-Kn for qemu-devel@nongnu.org; Mon, 13 Feb 2012 09:05:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RwwWT-00054I-2f for qemu-devel@nongnu.org; Mon, 13 Feb 2012 09:04:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwwWS-00053I-SH for qemu-devel@nongnu.org; Mon, 13 Feb 2012 09:04:53 -0500 From: Markus Armbruster References: <1328884453-1067-1-git-send-email-zwu.kernel@gmail.com> <20120210144115.GI2914@redhat.com> <4F353D75.2050801@weilnetz.de> Date: Mon, 13 Feb 2012 15:04:44 +0100 In-Reply-To: <4F353D75.2050801@weilnetz.de> (Stefan Weil's message of "Fri, 10 Feb 2012 16:53:25 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] oslib: make error handling more reasonable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: Zhi Yong Wu , QEMU Developers Stefan Weil writes: > Am 10.02.2012 16:13, schrieb Zhi Yong Wu: >> On Fri, Feb 10, 2012 at 10:41 PM, Daniel P. Berrange >> wrote: >>> On Fri, Feb 10, 2012 at 10:34:13PM +0800, Zhi Yong Wu wrote: >>>> From: Zhi Yong Wu >>>> >>>> Signed-off-by: Zhi Yong Wu >>>> --- >>>> oslib-posix.c | 4 ++-- >>>> oslib-win32.c | 4 ++-- >>>> 2 files changed, 4 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/oslib-posix.c b/oslib-posix.c >>>> index b6a3c7f..f978d56 100644 >>>> --- a/oslib-posix.c >>>> +++ b/oslib-posix.c >>>> @@ -80,7 +80,7 @@ void *qemu_oom_check(void *ptr) >>>> { >>>> if (ptr == NULL) { >>>> fprintf(stderr, "Failed to allocate memory: %s\n", >>>> strerror(errno)); >>>> - abort(); >>>> + exit(EXIT_FAILURE); >>> >>> exit() will call any atexit()/on_exit() handlers, as well as trying >>> to flush I/O streams. Any of these actions may require further >>> memory allocations, which will likely fail, or worse cause this >>> code to re-enter itself if an atexit() handler calls qemu_malloc >> Nice, very reasonable. >>> >>> The only option other than abort(), is to use _Exit() which >>> doesn't try to run cleanup handlers. >> I will try to send out v2 > > Could you please explain why calling exit, _Exit or _exit is more > reasonable than calling abort? > > abort can create core dumps or start a debugger which is > useful for me and maybe other developers, too. I consider abort() on OOM somewhat eccentric. abort() is for programming errors. Resource shortage is an environmental error that is sometimes (but not always) caused by a programming error. I'd rather inconvenience programmers (by making it a little bit harder to debug programming errors that cause OOM) than confuse users with inappropriate scary "crashes".