From patchwork Wed May 31 13:08:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 100753 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp295947obc; Wed, 31 May 2017 06:15:27 -0700 (PDT) X-Received: by 10.200.33.149 with SMTP id 21mr31038724qty.223.1496236527865; Wed, 31 May 2017 06:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496236527; cv=none; d=google.com; s=arc-20160816; b=oTQXmB9NyzX5PtLzSnHojxJHO+UlP0peOabrKA7EaUVGyYoyTV4NrTLVNUcCctUHoC Cg2e5jATk+T7dUXeCA+J0WzIiXeSo0DGtMzu/cnyQzSd5DsPFq1T4oIIgn118mDTP7Na 1cl60jGCKZPiEwadrwIEYvN44S1H6EeGmvBa7vJ1rFcln5SbS2iqXEK5wuxZyHlPWQDc 96lrK/zbyLlgFw7V9Tp9Y4JMnNpJo2aEBiT81R96E8vEgahevw8UOK1V03GHS6+uD4ld OvMeARZUQmQDx7MpbfMOSckoG/8lqdO2j1kzAufdCXgYmHWy0LhuM6EaP3MqfzKUGN62 EIzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=ATZm5CB9ryGIVvWQK1NlMh3EPLzZPN6G0IkLpUJlvkg=; b=pDJuDzTkWc2kCRvdZjOM9yV0hVIwncGI2g4vPIKr2cfUBrIoi5WXb6mlf/GK5ikRoA zcfaGR14vpL7iR4K8e8dgPRQdG/2rk3JPoDziwpQOTcUhEKwikg6VN4p9QnJORoMQbMI daTB3r99xscrU4jkiiPcV8Uts4FDRvAIFvlhMzUXuAlTmxODswjoDvVixbqCOj1m1Zg/ S0YaY0/hUjW6ABJ4ZB8PZOAqr6ZpxV+F+ZdPUr3Lc6RJ6vKChM170tj2Y7pBMHipnB/I 4VYCN0opZoNKpvJ14BM0uZm0stWYnUvcTilcSExMmEU2Jak6vwLh1PxfqtINw55kO0Kx Hv/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h134si11520494qke.194.2017.05.31.06.15.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 31 May 2017 06:15:27 -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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3TB-0004ft-4J for patch@linaro.org; Wed, 31 May 2017 09:15:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Mg-0007WO-MM for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG3Mf-0003dx-Ig for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:42 -0400 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:33152) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG3Mf-0003da-AO for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:41 -0400 Received: by mail-lf0-x22d.google.com with SMTP id m18so8645280lfj.0 for ; Wed, 31 May 2017 06:08:41 -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=ATZm5CB9ryGIVvWQK1NlMh3EPLzZPN6G0IkLpUJlvkg=; b=VSMpe0DTPw9PkTinWGU+Wf5gLr4btHK/MGn7mP86KZpSeaPGyme7dr4McGrSy2FMhC 9UZitxMC1eq4qAem7UWTpriv5TMmpCiwP7dKlXhDl4eL5khKYesK9q3LyvHhaJDP/tOx Nxd+9L1IXwE1IZ5NnwR0QflhKaKBXAoAnrjZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ATZm5CB9ryGIVvWQK1NlMh3EPLzZPN6G0IkLpUJlvkg=; b=WTwnPE56kaDbiYW2v7wcstlpbFAtu2fh8+vaMT1gb4VeYH8Uio/B3YbI3pp988/oqW xGZnv1lM3qkeAFnVJ4YcMG+A4lQ9dAZ1i0+cUcTkutaOvfwGshQr/mDRhpnKFiKE70x5 c/ChADLDFne5aNtM5HP6otXW4vrxaNMkwTCUV8MdoFlAuL3dvt7kcZ9MzolRNueCjP4i v3roO51zKJxyfx3aXWnuaYhSE7HF8KhEW6xki0kl9Mj+f8zigv9/DvilT75enSxgp9AG Bjg2tr42mo61OM4buoRDVXQkG6HmpP+U1QWC+D9vbWkMbJR8m7r3DNVtjpROneOMcSuu EJ/A== X-Gm-Message-State: AODbwcAlOsM/3GNIQ6gLflO9wl3vW0RcH9l/3CrWs+61OqZlo7tQPYro w34MwM2ulFEm8njKmP5zpQ== X-Received: by 10.46.19.2 with SMTP id 2mr8428608ljt.132.1496236119829; Wed, 31 May 2017 06:08:39 -0700 (PDT) Received: from localhost.localdomain (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id o101sm3741766lfg.3.2017.05.31.06.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 06:08:38 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 16:08:18 +0300 Message-Id: <58de8b9684cc7b4b1fb3cd47678a04d6924b28de.1496234766.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::22d Subject: [Qemu-devel] [PULL 06/15] linux-user: remove all traces of qemu from /proc/self/cmdline 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@linaro.org, stefanha@redhat.com, Andreas Schwab Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Andreas Schwab Instead of post-processing the real contents use the remembered target argv. That removes all traces of qemu, including command line options, and handles QEMU_ARGV0. Signed-off-by: Andreas Schwab Signed-off-by: Riku Voipio --- linux-user/syscall.c | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) -- 2.11.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c8f6efc89c..909dde6de6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7358,52 +7358,19 @@ int host_to_target_waitstatus(int 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; - } + CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env); + struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm; + int i; - while (true) { - ssize_t nb_read; - char buf[128]; - char *cp_buf = buf; + for (i = 0; i < bprm->argc; i++) { + size_t len = strlen(bprm->argv[i]) + 1; - nb_read = read(fd_orig, buf, sizeof(buf)); - if (nb_read < 0) { - int e = errno; - fd_orig = close(fd_orig); - errno = e; + if (write(fd, bprm->argv[i], len) != len) { 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, nb_read); - 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) { - int e = errno; - close(fd_orig); - errno = e; - return -1; - } } } - return close(fd_orig); + return 0; } static int open_self_maps(void *cpu_env, int fd)