From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwvwI-00035e-AT for qemu-devel@nongnu.org; Tue, 17 Jun 2014 12:08:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwvwA-00067b-5L for qemu-devel@nongnu.org; Tue, 17 Jun 2014 12:08:50 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:64024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wwvw9-00067J-Vi for qemu-devel@nongnu.org; Tue, 17 Jun 2014 12:08:42 -0400 Received: by mail-we0-f173.google.com with SMTP id t60so7444605wes.18 for ; Tue, 17 Jun 2014 09:08:41 -0700 (PDT) Sender: Wim Vander Schelden From: lists@fixnum.org Date: Tue, 17 Jun 2014 05:16:59 +0200 Message-Id: <1402975019-19503-2-git-send-email-lists@fixnum.org> In-Reply-To: <1402975019-19503-1-git-send-email-lists@fixnum.org> References: <1402975019-19503-1-git-send-email-lists@fixnum.org> Subject: [Qemu-devel] [PATCH] linux-user: added fake open() for /proc/self/cmdline List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Wim Vander Schelden , alex.bennee@linaro.org From: Wim Vander Schelden --- linux-user/syscall.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c134c32..f9fed3e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4947,6 +4947,54 @@ int host_to_target_waitstatus(int status) return 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; + } + + while(true) { + ssize_t nb_read; + char buf[128]; + char* cp_buf = buf; + + nb_read = read(fd_orig, buf, sizeof(buf)); + if(nb_read < 0) + { + fd_orig = close(fd_orig); + return -1; + } else if(nb_read == 0) { + break; + } + + if(nb_read == 0) + break; + + if(! word_skipped) { + // Skip the first string, which is the path to qemu-*-static instead of the actual command. + size_t command_length = strnlen(buf, sizeof(buf)); + if(command_length != sizeof(buf)) { + // Null byte found, skip one string + nb_read -= command_length + 1; + cp_buf += command_length + 1; + word_skipped = true; + } + } + + if(word_skipped) { + if(write(fd, cp_buf, nb_read) != nb_read) { + return -1; + } + } + } + + return close(fd_orig); +} + static int open_self_maps(void *cpu_env, int fd) { #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) @@ -5148,6 +5196,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) { "maps", open_self_maps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, + { "cmdline", open_self_cmdline, is_proc_myself}, #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) { "/proc/net/route", open_net_route, is_proc }, #endif -- 1.9.1