From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpFya-00011m-Or for qemu-devel@nongnu.org; Wed, 28 Sep 2016 10:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpFyU-0006Cx-P1 for qemu-devel@nongnu.org; Wed, 28 Sep 2016 10:36:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:36980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpFyU-0006C2-Gb for qemu-devel@nongnu.org; Wed, 28 Sep 2016 10:36:42 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A5BBD75015 for ; Wed, 28 Sep 2016 14:36:40 +0000 (UTC) From: Andreas Schwab Date: Wed, 28 Sep 2016 16:36:40 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: afaerber@suse.de 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 ca06943..e11eeab 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6988,52 +6988,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) -- 2.10.0 -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."