From patchwork Fri Dec 18 12:37:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 41400 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 AA425B6F0A for ; Fri, 18 Dec 2009 23:39:18 +1100 (EST) Received: from localhost ([127.0.0.1]:51913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLc71-0007ng-ME for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2009 07:39:15 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLc6J-0007jt-Qy for qemu-devel@nongnu.org; Fri, 18 Dec 2009 07:38:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLc6E-0007WS-Bu for qemu-devel@nongnu.org; Fri, 18 Dec 2009 07:38:31 -0500 Received: from [199.232.76.173] (port=43222 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLc6E-0007WD-8J for qemu-devel@nongnu.org; Fri, 18 Dec 2009 07:38:26 -0500 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.15]:20352 helo=VA3EHSOBE005.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1NLc6D-0004Y0-VD for qemu-devel@nongnu.org; Fri, 18 Dec 2009 07:38:26 -0500 Received: from mail181-va3-R.bigfish.com (10.7.14.247) by VA3EHSOBE005.bigfish.com (10.7.40.25) with Microsoft SMTP Server id 8.1.340.0; Fri, 18 Dec 2009 12:38:24 +0000 Received: from mail181-va3 (localhost.localdomain [127.0.0.1]) by mail181-va3-R.bigfish.com (Postfix) with ESMTP id 912731820528; Fri, 18 Dec 2009 12:38:24 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzab9bh936eMzz1202hzzz32i6bh43j61h) X-Spam-TCS-SCL: 0:0 Received: from mail181-va3 (localhost.localdomain [127.0.0.1]) by mail181-va3 (MessageSwitch) id 1261139900325142_18979; Fri, 18 Dec 2009 12:38:20 +0000 (UTC) Received: from VA3EHSMHS020.bigfish.com (unknown [10.7.14.236]) by mail181-va3.bigfish.com (Postfix) with ESMTP id 5AFA077006E; Fri, 18 Dec 2009 12:37:48 +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 12:37:47 +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 nBICbgMv006769; Fri, 18 Dec 2009 06:37:45 -0600 X-WSS-ID: 0KUULQR-02-54G-02 X-M-MSG: Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2ACEAC90DB; Fri, 18 Dec 2009 06:37:38 -0600 (CST) Received: from sausexmb2.amd.com ([163.181.3.157]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 18 Dec 2009 06:37:43 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 18 Dec 2009 06:37:42 -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 13:37:40 +0100 Received: from localhost.localdomain (tronje.osrc.amd.com [165.204.15.48]) by gwo.osrc.amd.com (Postfix) with ESMTP id 0B62649C145; Fri, 18 Dec 2009 12:37:40 +0000 (GMT) From: Andre Przywara To: qemu-devel@nongnu.org Date: Fri, 18 Dec 2009 13:37:58 +0100 Message-ID: <1261139878-28751-1-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1261129507-13244-1-git-send-email-andre.przywara@amd.com> References: <1261129507-13244-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 18 Dec 2009 12:37:40.0207 (UTC) FILETIME=[E30A97F0:01CA7FDE] MIME-Version: 1.0 X-Reverse-DNS: unknown X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ Cc: kwolf@redhat.com, Andre Przywara Subject: [Qemu-devel] [PATCH v2] 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 Acked-by: Kevin Wolf --- osdep.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) v2 changed the errno check from EINVAL to ENOSYS for accept4 diff --git a/osdep.c b/osdep.c index 7509c5b..60469ed 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 != ENOSYS) { + return ret; + } +#endif ret = accept(s, addr, addrlen); if (ret >= 0) { qemu_set_cloexec(ret); } -#endif return ret; }