From patchwork Fri May 27 12:59:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9138307 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 E935360759 for ; Fri, 27 May 2016 13:05:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAA95208C2 for ; Fri, 27 May 2016 13:05:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF8AE28135; Fri, 27 May 2016 13:05:53 +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 CD2FB208C2 for ; Fri, 27 May 2016 13:05:50 +0000 (UTC) Received: from localhost ([::1]:45710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HSX-0003O1-O6 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 09:05:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNe-0007IT-SM for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6HNU-00014x-35 for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:46 -0400 Received: from mail-lf0-x22f.google.com ([2a00:1450:4010:c07::22f]:34245) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNT-00014f-Mt for qemu-devel@nongnu.org; Fri, 27 May 2016 09:00:35 -0400 Received: by mail-lf0-x22f.google.com with SMTP id k98so45663388lfi.1 for ; Fri, 27 May 2016 06:00:35 -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=C6wcWvCgfRcejWhrEf6bPcOdW/4DtFPOTUFc7SR0+gKUVMc2NlHiZlELK+DAQk+39S To+7fpF5DUAC01nATIcXOsmZtR0B7SZy1RPwGx+dVFF7RvusiHeIhnrkdodjN69UV8KI tm9XEcW5UxD6QfJAmlVSTb+QBK2peVzmyl7g0= 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=FxCVluxm/bNr55T1g4eayzyT/KTNzu2cP7YuZ6HvNfJRFQYVeDxYIsQjm+UaK4tM8e Vsf5yHp3o0nsIijF4IRsjB0O26bJG0JqJBGrIbfTrLXZNzWuEDm3aBePFz42wsaSHdzg nR5V4MBRHid5ugbDrYKjWjIF03g3wAnMKIoSvm2LfDoFJZOHvq9B5k6f0+9go5Tdc4md xUTO4+CUJj9RCJXGkhP9l9c3mtM3EFpwxwzlrGeKbSn3edcOg+tF9r5fXbJdNNtIPKQu vWvy3Nb0CuepAyA1ar2Sgkdo9its5S6VGdKKX58al+Pkl8AoJ0nP1dZeaSVrP3jt0o6w AG1A== X-Gm-Message-State: ALyK8tI3L3slOa8WaYKPhASUBYjRLoHxB8mwc1EQIsWztSuEKuOA4r+aS5TAmbpaUllX/+ba X-Received: by 10.25.157.204 with SMTP id g195mr3593683lfe.53.1464354034777; Fri, 27 May 2016 06:00:34 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id n16sm2281066lfg.31.2016.05.27.06.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 06:00:33 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 15:59:53 +0300 Message-Id: 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::22f Subject: [Qemu-devel] [PULL v2 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