From: Andreas Schwab <schwab@suse.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
Date: Mon, 31 Oct 2016 11:43:10 +0100 [thread overview]
Message-ID: <mvm60o8hk8x.fsf@hawking.suse.de> (raw)
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 <schwab@suse.de>
---
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)
--
2.10.2
--
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."
next reply other threads:[~2016-10-31 10:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-31 10:43 Andreas Schwab [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-03-20 11:31 [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline Andreas Schwab
2017-05-19 13:59 ` Riku Voipio
2016-09-28 14:36 Andreas Schwab
2016-09-28 14:43 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mvm60o8hk8x.fsf@hawking.suse.de \
--to=schwab@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).