From nobody Wed May 8 01:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149000974282419.63861464474701; Mon, 20 Mar 2017 04:35:42 -0700 (PDT) Received: from localhost ([::1]:60464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpvbB-0005OJ-I0 for importer@patchew.org; Mon, 20 Mar 2017 07:35:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpvXf-0003VV-97 for qemu-devel@nongnu.org; Mon, 20 Mar 2017 07:32:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpvXb-0004yD-Au for qemu-devel@nongnu.org; Mon, 20 Mar 2017 07:32:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:60097) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpvXa-0004xo-Np for qemu-devel@nongnu.org; Mon, 20 Mar 2017 07:31:59 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 59AC3AB22; Mon, 20 Mar 2017 11:31:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Andreas Schwab To: qemu-devel@nongnu.org X-Yow: I'm encased in the lining of a pure pork sausage!! Date: Mon, 20 Mar 2017 12:31:55 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] 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: , Cc: Riku Voipio Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 cec8428589..ec1fd20386 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7358,52 +7358,19 @@ int host_to_target_waitstatus(int status) =20 static int open_self_cmdline(void *cpu_env, int fd) { - int fd_orig =3D -1; - bool word_skipped =3D false; - - fd_orig =3D open("/proc/self/cmdline", O_RDONLY); - if (fd_orig < 0) { - return fd_orig; - } + CPUState *cpu =3D ENV_GET_CPU((CPUArchState *)cpu_env); + struct linux_binprm *bprm =3D ((TaskState *)cpu->opaque)->bprm; + int i; =20 - while (true) { - ssize_t nb_read; - char buf[128]; - char *cp_buf =3D buf; + for (i =3D 0; i < bprm->argc; i++) { + size_t len =3D strlen(bprm->argv[i]) + 1; =20 - nb_read =3D read(fd_orig, buf, sizeof(buf)); - if (nb_read < 0) { - int e =3D errno; - fd_orig =3D close(fd_orig); - errno =3D e; + if (write(fd, bprm->argv[i], len) !=3D len) { return -1; - } else if (nb_read =3D=3D 0) { - break; - } - - if (!word_skipped) { - /* Skip the first string, which is the path to qemu-*-static - instead of the actual command. */ - cp_buf =3D memchr(buf, 0, nb_read); - if (cp_buf) { - /* Null byte found, skip one string */ - cp_buf++; - nb_read -=3D cp_buf - buf; - word_skipped =3D true; - } - } - - if (word_skipped) { - if (write(fd, cp_buf, nb_read) !=3D nb_read) { - int e =3D errno; - close(fd_orig); - errno =3D e; - return -1; - } } } =20 - return close(fd_orig); + return 0; } =20 static int open_self_maps(void *cpu_env, int fd) --=20 2.12.0 --=20 Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint =3D 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."