From patchwork Sun Jun 29 12:14:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32673 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2710723577 for ; Sun, 29 Jun 2014 12:21:09 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id r10sf14335356igi.4 for ; Sun, 29 Jun 2014 05:21:09 -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=Sw0ZQtDbUgv5DR8D0Gc1Q21a0mYQCljm/GAZEJg8HTc=; b=BQwSALbi866D95gDHGWhKPBRoHYgjODeaTNV0ShXvfN/Ffish6ZKH8Q+vni7bOLrSX yG2OHFxu1IAGo7PPyhdVVVBLTwr3jXjVrkyPvcYN6BfSD7MZ0viMh1My3To1TFujefTf 6dkYAF7oGQHF54diSkwekne8eZxfUl6g8dYt+IlWc0GMdyriZXIxoZ3ev/sW7/71SN+Q 9AmNQcVsgPKOx45bjnVPg8dk9OVhJ62OW+rwTSna+8hghH4k52RpERk96mxChruk3rxo mJg2ZrjgTPr5eDZ9PfzVjHr9oKKwz7hwaSqJfX1tAfG8zaXfw3JbIAVtKA8RpfRhlGXQ gzyQ== X-Gm-Message-State: ALoCoQn4+9AZB4ylGzkcqkkvIYph8upQ82/G0mjKInmPrxCohUKaaN07WtONHw6zaSosdqr/WHoT X-Received: by 10.182.28.136 with SMTP id b8mr19157310obh.19.1404044469495; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.74 with SMTP id d68ls1214934qga.12.gmail; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) X-Received: by 10.221.27.8 with SMTP id ro8mr32252132vcb.30.1404044469381; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id io2si8819935vcb.84.2014.06.29.05.21.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id lf12so6536649vcb.18 for ; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) X-Received: by 10.220.174.137 with SMTP id t9mr32383179vcz.12.1404044469299; Sun, 29 Jun 2014 05:21:09 -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 tc5csp72551vcb; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) X-Received: by 10.224.172.201 with SMTP id m9mr5227799qaz.32.1404044468641; Sun, 29 Jun 2014 05:21:08 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u9si20979370qcj.0.2014.06.29.05.21.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:21:08 -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]:57552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E6W-0006U6-6c for patch@linaro.org; Sun, 29 Jun 2014 08:21:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0j-0004F4-9S for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1E0X-0000au-2K for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:09 -0400 Received: from afflict.kos.to ([92.243.29.197]:54958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0W-0000ag-SJ for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:14:57 -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 8B2F026546; Sun, 29 Jun 2014 14:14:55 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Sun, 29 Jun 2014 15:14:42 +0300 Message-Id: <76b94245507881a0621c5bb3b144c3c19dcbcb4d.1404041926.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: 92.243.29.197 Cc: Peter Maydell , Wim Vander Schelden , Anthony Liguori Subject: [Qemu-devel] [PULL v2 02/13] 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.173 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