From patchwork Mon Jun 23 13:26:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32353 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1E83820540 for ; Mon, 23 Jun 2014 13:29:56 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf43277984oac.3 for ; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=WQ2BauyLYW73N/ovCgrDCUN2iOQOeZ8Ae+1Co0tuaZ0=; b=X7kBMEAQOXNN9UiQezuurAPVPWmlwYq/apxyqRo8XduCwkHjW2/y0UG5cB7ylx4rE4 tIXT7yiWe1g5SbDpd3CIVcVL2zj3OjjzXOO2SetNXBp+5cZo6gThXPe1Oq0sdvJaJ4cE GBMK4uQW1zpsflXk7oJcfZ37rYH3S3UrojmTlarOrVc1Rxtvvjlycou5fRdK+haTRv5S wtPici/d81dVdCfMWL9krkFUqtqeVZuzC1d/90tRu9+y32qkTywvDWfVvHNdQWxNW09F R354Al33YdJvN0SRnSw2VnP6jDW7b+vNSE5lCn7hh68i6QObIJMIn33hf5vuVlhQy7i1 nEcQ== X-Gm-Message-State: ALoCoQkAePxMauALToMykX2QRhXpsRLz1LtYg9omdE6GX+EJSMQQB6JiLjs3WnJNYG3B0Fd79Fwz X-Received: by 10.51.17.10 with SMTP id ga10mr9710074igd.4.1403530195731; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.100 with SMTP id f91ls1997295qge.65.gmail; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) X-Received: by 10.53.8.162 with SMTP id dl2mr16186988vdd.24.1403530195551; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id c10si8966490vdg.83.2014.06.23.06.29.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 06:29:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id im17so5991242vcb.11 for ; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) X-Received: by 10.220.44.141 with SMTP id a13mr448621vcf.71.1403530195471; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp130762vcb; Mon, 23 Jun 2014 06:29:55 -0700 (PDT) X-Received: by 10.140.80.14 with SMTP id b14mr4200780qgd.113.1403530194340; Mon, 23 Jun 2014 06:29:54 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b2si22444266qce.27.2014.06.23.06.29.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 23 Jun 2014 06:29:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:53512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Jl-0007n0-UR for patch@linaro.org; Mon, 23 Jun 2014 09:29:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gl-0003iH-E0 for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz4Gc-0001A5-Ol for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:47 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=37350 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gc-00019X-Ii for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:38 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 02FBA26547; Mon, 23 Jun 2014 15:26:36 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 23 Jun 2014 16:26:18 +0300 Message-Id: <7951c7273aea9f6bb393909068dbd385d09b2fab.1403529800.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Wim Vander Schelden Subject: [Qemu-devel] [PULL 03/19] linux-user: added fake open() for /proc/self/cmdline 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Wim Vander Schelden Signed-off-by: Wim Vander Schelden Signed-off-by: Riku Voipio --- linux-user/syscall.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 007d59d..5c175ba 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4949,6 +4949,51 @@ int host_to_target_waitstatus(int status) return status; } +static int open_self_cmdline(void *cpu_env, int fd) +{ + int fd_orig = -1; + bool word_skipped = false; + + fd_orig = open("/proc/self/cmdline", O_RDONLY); + if (fd_orig < 0) { + return fd_orig; + } + + while (true) { + ssize_t nb_read; + char buf[128]; + char *cp_buf = buf; + + nb_read = read(fd_orig, buf, sizeof(buf)); + if (nb_read < 0) { + fd_orig = close(fd_orig); + return -1; + } else if (nb_read == 0) { + break; + } + + if (!word_skipped) { + /* Skip the first string, which is the path to qemu-*-static + instead of the actual command. */ + cp_buf = memchr(buf, 0, sizeof(buf)); + if (cp_buf) { + /* Null byte found, skip one string */ + cp_buf++; + nb_read -= cp_buf - buf; + word_skipped = true; + } + } + + if (word_skipped) { + if (write(fd, cp_buf, nb_read) != nb_read) { + return -1; + } + } + } + + return close(fd_orig); +} + static int open_self_maps(void *cpu_env, int fd) { #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) @@ -5150,6 +5195,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) { "maps", open_self_maps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, + { "cmdline", open_self_cmdline, is_proc_myself }, #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) { "/proc/net/route", open_net_route, is_proc }, #endif