From e3d678733e56160e082d737f2a8f181225f9775f Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Mon, 26 Sep 2016 10:08:59 +0200 Subject: [PATCH] linux-user: skip -0 flag from /proc/self/cmdline This removes the "-0 argv0" flag from /proc/self/cmdline that was passed in by the qemu-ARCH-binfmt wrapper. Signed-off-by: Andreas Schwab --- linux-user/syscall.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 856e75d64a..9be99d6001 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7014,7 +7014,7 @@ 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; + int skip_words = 3; fd_orig = open("/proc/self/cmdline", O_RDONLY); if (fd_orig < 0) { @@ -7036,19 +7036,29 @@ static int open_self_cmdline(void *cpu_env, int fd) break; } - if (!word_skipped) { + while (skip_words) { /* Skip the first string, which is the path to qemu-*-static instead of the actual command. */ - cp_buf = memchr(buf, 0, nb_read); + char *p = cp_buf; + cp_buf = memchr(p, 0, nb_read); if (cp_buf) { /* Null byte found, skip one string */ cp_buf++; - nb_read -= cp_buf - buf; - word_skipped = true; + nb_read -= cp_buf - p; + skip_words--; + if (skip_words == 2) { + /* Check for presence of -0 flag. */ + if (nb_read > 0 && cp_buf[0] != '-' || + nb_read > 1 && cp_buf[1] != '0') { + skip_words = 0; + } + } + } else { + break; } } - if (word_skipped) { + if (skip_words == 0) { if (write(fd, cp_buf, nb_read) != nb_read) { int e = errno; close(fd_orig); -- 2.51.1