From patchwork Thu Mar 3 18:36:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 8495331 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C374CC0553 for ; Thu, 3 Mar 2016 18:36:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FD8520117 for ; Thu, 3 Mar 2016 18:36:41 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 14F0E200FF for ; Thu, 3 Mar 2016 18:36:40 +0000 (UTC) Received: from localhost ([::1]:36803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abY75-0006WO-Gw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Mar 2016 13:36:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abY6u-0006Od-B9 for qemu-devel@nongnu.org; Thu, 03 Mar 2016 13:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abY6t-000227-C4 for qemu-devel@nongnu.org; Thu, 03 Mar 2016 13:36:28 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:56085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abY6t-000222-4v for qemu-devel@nongnu.org; Thu, 03 Mar 2016 13:36:27 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84) (envelope-from ) id 1abY6s-0000mi-Kn; Thu, 03 Mar 2016 18:36:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 3 Mar 2016 18:36:26 +0000 Message-Id: <1457030186-11499-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Cc: Riku Voipio , patches@linaro.org Subject: [Qemu-devel] [PATCH] linux-user: Consistently return host errnos from do_openat() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Timothy's patchset for fixing signal races had a patch which also addressed this bug. However I preferred to take the opposite tack and have the callers do get_errno() rather than the callee, because it means changes in fewer places and it's generally more natural for the 'fill' functions that do_openat() calls. --- 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 f9dcdd4..39586e4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5557,7 +5557,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; @@ -5577,7 +5579,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; } } @@ -5597,7 +5601,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) { @@ -5741,7 +5745,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 */ @@ -5791,7 +5795,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++) { @@ -5817,7 +5821,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); @@ -5825,7 +5831,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