From patchwork Fri Dec 18 09:45:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 41379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 722D5B6EF0 for ; Fri, 18 Dec 2009 20:46:39 +1100 (EST) Received: from localhost ([127.0.0.1]:54403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLZPv-0000cK-Hp for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2009 04:46:35 -0500 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-R.bigfish.com (10.7.14.247) by VA3EHSOBE004.bigfish.com (10.7.40.24) with Microsoft SMTP Server id 8.1.240.5; Fri, 18 Dec 2009 09:45:50 +0000 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) X-SpamScore: -2 X-BigFish: VPS-2(zzab9bh936eMzz1202hzzz32i6bh43j61h) X-Spam-TCS-SCL: 0:0 Received: from mail132-va3 (localhost.localdomain [127.0.0.1]) by mail132-va3 (MessageSwitch) id 1261129547366654_1296; Fri, 18 Dec 2009 09:45:47 +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 ausb3extmailp01.amd.com (163.181.251.8) by VA3EHSMHS020.bigfish.com (10.7.99.30) with Microsoft SMTP Server (TLS) id 14.0.482.32; Fri, 18 Dec 2009 09:45:04 +0000 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 X-WSS-ID: 0KUUDQW-02-0TK-02 X-M-MSG: 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) Received: from sausexmb4.amd.com ([163.181.3.15]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 18 Dec 2009 03:45:00 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb4.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 18 Dec 2009 03:45:00 -0600 Received: from gwo.osrc.amd.com ([165.204.16.204]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 18 Dec 2009 10:44:58 +0100 Received: from localhost.localdomain (tronje.osrc.amd.com [165.204.15.48]) by gwo.osrc.amd.com (Postfix) with ESMTP id 3A59149C145; Fri, 18 Dec 2009 09:44:58 +0000 (GMT) From: Andre Przywara To: qemu-devel@nongnu.org Date: Fri, 18 Dec 2009 10:45:07 +0100 Message-ID: <1261129507-13244-1-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.4 X-OriginalArrivalTime: 18 Dec 2009 09:44:58.0387 (UTC) FILETIME=[C2EA5630:01CA7FC6] MIME-Version: 1.0 X-Reverse-DNS: unknown X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ Cc: Andre Przywara Subject: [Qemu-devel] [PATCH] osdep: Fix runtime failure on older Linux kernels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }