From patchwork Mon Oct 31 10:43:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 9405253 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 86FFB60234 for ; Mon, 31 Oct 2016 10:43:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77B2128E75 for ; Mon, 31 Oct 2016 10:43:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B0BA28F0A; Mon, 31 Oct 2016 10:43:38 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 42DDA28E75 for ; Mon, 31 Oct 2016 10:43:36 +0000 (UTC) Received: from localhost ([::1]:34528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1A40-0000AD-Bp for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Oct 2016 06:43:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1A3i-000096-DA for qemu-devel@nongnu.org; Mon, 31 Oct 2016 06:43:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1A3f-0005pi-86 for qemu-devel@nongnu.org; Mon, 31 Oct 2016 06:43:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:55805) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1A3f-0005p7-1S for qemu-devel@nongnu.org; Mon, 31 Oct 2016 06:43:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BDD28ABFB for ; Mon, 31 Oct 2016 10:43:12 +0000 (UTC) From: Andreas Schwab To: qemu-devel@nongnu.org X-Yow: I'm ZIPPY the PINHEAD and I'm totally committed to the festive mode. Date: Mon, 31 Oct 2016 11:43:10 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH] 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- linux-user/syscall.c | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7b77503f94..bf542c58b1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7214,52 +7214,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)