From patchwork Wed May 25 05:27:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9134741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 964456075C for ; Wed, 25 May 2016 05:37:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AE1726FC9 for ; Wed, 25 May 2016 05:37:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DA3E282AD; Wed, 25 May 2016 05:37:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D3C426FC9 for ; Wed, 25 May 2016 05:37:37 +0000 (UTC) Received: from localhost ([::1]:57415 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RVg-0006wu-8w for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 01:37:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RMs-000800-NO for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5RMq-0001M5-Mj for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:29 -0400 Received: from mail-lf0-x230.google.com ([2a00:1450:4010:c07::230]:36345) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5RMq-0001LM-Ea for qemu-devel@nongnu.org; Wed, 25 May 2016 01:28:28 -0400 Received: by mail-lf0-x230.google.com with SMTP id e130so13711834lfe.3 for ; Tue, 24 May 2016 22:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RRDQu9vjE/d/wrZTkedS+/ko6Igsu0OXXuwoES3rKRM=; b=d9Fww629s44FOXwYoXGiEfcnlx3UGxrSlueG9sm8E+GxUWmoAocEfDX5+CP/piB4y6 KE/HDeHssRghiWXBTZ6XnRhA5kD32Ucw4AldR6mA+6tHSRkoJsk9Ur7yUzqX2jd2xp9U TMgiPzMbxOKVYIhr52zOdjQag5XBCxDca/Ihk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RRDQu9vjE/d/wrZTkedS+/ko6Igsu0OXXuwoES3rKRM=; b=MTqJqvhqCwTgJ1ysp55p/q9ZbeRWrTMZ2CuzTSdWvVeRee9Kx7EWQG8OtpLOMr8ZLJ KGZ5bMf7vt7tXuxUjCk8l1SrRaIcEgK7K4ddlgSY9OmL5d8LK0HThlozUcMi7XjZfhhY JcnVccWDpUpCG6z+/kDvMfPvWu82PWAKb4oouyQwii5I2kAsYorS72jmXwpGvuqinxvg CTumQhVFO1/0QJXYu/r5v8t1rNFCh87DcR9JwAXrLUrsCT+h1N+YDSt3mbVyqVkL0KrL 99xKPeY+kgYrtEIP0FPpqdR5rsyBtXmn+uK2l0s8BoeqSFNbEseJG5+eFmcVL2JC3sbi g4CA== X-Gm-Message-State: ALyK8tIWi9RJYKXHH3FqKIO/LJ4wq2iZnqsLz9Np94eZr6gCl1YQH0WXyqS2UUAa94d5pphm X-Received: by 10.25.160.77 with SMTP id j74mr321884lfe.72.1464154107655; Tue, 24 May 2016 22:28:27 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id g10sm1136823lbc.43.2016.05.24.22.28.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 May 2016 22:28:26 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 08:27:36 +0300 Message-Id: <48f249abb5888d3022ac9b9d47da4240b3f40f5b.1464153942.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::230 Subject: [Qemu-devel] [PULL 02/38] linux-user: Consistently return host errnos from do_openat() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Maydell The function do_openat() is not consistent about whether it is returning a host errno or a guest errno in case of failure. Standardise on returning -1 with errno set (ie caller has to call get_errno()). Signed-off-by: Peter Maydell Reported-by: Timothy Edward Baldwin Signed-off-by: Riku Voipio Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5246f36..f4c2e19 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5559,7 +5559,9 @@ static int open_self_cmdline(void *cpu_env, int fd) nb_read = read(fd_orig, buf, sizeof(buf)); if (nb_read < 0) { + int e = errno; fd_orig = close(fd_orig); + errno = e; return -1; } else if (nb_read == 0) { break; @@ -5579,7 +5581,9 @@ static int open_self_cmdline(void *cpu_env, int fd) if (word_skipped) { if (write(fd, cp_buf, nb_read) != nb_read) { + int e = errno; close(fd_orig); + errno = e; return -1; } } @@ -5599,7 +5603,7 @@ static int open_self_maps(void *cpu_env, int fd) fp = fopen("/proc/self/maps", "r"); if (fp == NULL) { - return -EACCES; + return -1; } while ((read = getline(&line, &len, fp)) != -1) { @@ -5743,7 +5747,7 @@ static int open_net_route(void *cpu_env, int fd) fp = fopen("/proc/net/route", "r"); if (fp == NULL) { - return -EACCES; + return -1; } /* read header */ @@ -5793,7 +5797,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, if (is_proc_myself(pathname, "exe")) { int execfd = qemu_getauxval(AT_EXECFD); - return execfd ? execfd : get_errno(sys_openat(dirfd, exec_path, flags, mode)); + return execfd ? execfd : sys_openat(dirfd, exec_path, flags, mode); } for (fake_open = fakes; fake_open->filename; fake_open++) { @@ -5819,7 +5823,9 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, unlink(filename); if ((r = fake_open->fill(cpu_env, fd))) { + int e = errno; close(fd); + errno = e; return r; } lseek(fd, 0, SEEK_SET); @@ -5827,7 +5833,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, return fd; } - return get_errno(sys_openat(dirfd, path(pathname), flags, mode)); + return sys_openat(dirfd, path(pathname), flags, mode); } #define TIMER_MAGIC 0x0caf0000