Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLZPI-0000c0-SX for qemu-devel@nongnu.org; Fri, 18 Dec 2009 04:45:56 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLZPD-0000bP-Cm for qemu-devel@nongnu.org; Fri, 18 Dec 2009 04:45:55 -0500 Received: from [199.232.76.173] (port=54837 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLZPD-0000bM-99 for qemu-devel@nongnu.org; Fri, 18 Dec 2009 04:45:51 -0500 Received: from va3ehsobe004.messaging.microsoft.com ([216.32.180.14]:12163 helo=VA3EHSOBE004.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1NLZPC-0005as-Sc for qemu-devel@nongnu.org; Fri, 18 Dec 2009 04:45:51 -0500 Received: from mail132-va3 (localhost.localdomain [127.0.0.1]) by mail132-va3-R.bigfish.com (Postfix) with ESMTP id 745CB13B8582 for ; Fri, 18 Dec 2009 09:45:49 +0000 (UTC) Received: from VA3EHSMHS020.bigfish.com (unknown [10.7.14.248]) by mail132-va3.bigfish.com (Postfix) with ESMTP id A9681108005F for ; Fri, 18 Dec 2009 09:45:05 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id nBI9iuah010541 for ; Fri, 18 Dec 2009 03:44:59 -0600 Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2D78BC90B4 for ; Fri, 18 Dec 2009 03:44:56 -0600 (CST) From: Andre Przywara Date: Fri, 18 Dec 2009 10:45:07 +0100 Message-ID: <1261129507-13244-1-git-send-email-andre.przywara@amd.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Andre Przywara If QEMU finds newer kernel header files on compilation time, it will use advertised features like pipe2 or SOCK_CLOEXEC by just doing a compile test. If later the executables are executed on an older kernel (<2.6.27, like Xen Dom0 2.6.18), then QEMU will fail on opening sockets and creating pipes and returns the rather unspecific "qemu_init_main_loop failed". This patch fixes this by checking the return values of these calls for EINVAL and ENOSYS and falling back to the older versions automatically. Signed-off-by: Andre Przywara --- osdep.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/osdep.c b/osdep.c index 7509c5b..9949606 100644 --- a/osdep.c +++ b/osdep.c @@ -262,13 +262,15 @@ int qemu_pipe(int pipefd[2]) #ifdef CONFIG_PIPE2 ret = pipe2(pipefd, O_CLOEXEC); -#else + if (ret != -1 || errno != ENOSYS) { + return ret; + } +#endif ret = pipe(pipefd); if (ret == 0) { qemu_set_cloexec(pipefd[0]); qemu_set_cloexec(pipefd[1]); } -#endif return ret; } @@ -283,12 +285,14 @@ int qemu_socket(int domain, int type, int protocol) #ifdef SOCK_CLOEXEC ret = socket(domain, type | SOCK_CLOEXEC, protocol); -#else + if (ret != -1 || errno != EINVAL) { + return ret; + } +#endif ret = socket(domain, type, protocol); if (ret >= 0) { qemu_set_cloexec(ret); } -#endif return ret; } @@ -302,12 +306,14 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen) #ifdef CONFIG_ACCEPT4 ret = accept4(s, addr, addrlen, SOCK_CLOEXEC); -#else + if (ret != -1 || errno != EINVAL) { + return ret; + } +#endif ret = accept(s, addr, addrlen); if (ret >= 0) { qemu_set_cloexec(ret); } -#endif return ret; } -- 1.6.4