All of lore.kernel.org
 help / color / mirror / Atom feed
From: riku.voipio@linaro.org
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Wim Vander Schelden <wim@fixnum.org>,
	Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL v2 02/13] linux-user: added fake open() for /proc/self/cmdline
Date: Sun, 29 Jun 2014 15:14:42 +0300	[thread overview]
Message-ID: <76b94245507881a0621c5bb3b144c3c19dcbcb4d.1404041926.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1404041926.git.riku.voipio@linaro.org>

From: Wim Vander Schelden <wim@fixnum.org>

Signed-off-by: Wim Vander Schelden <wim@fixnum.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 007d59d..5c175ba 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4949,6 +4949,51 @@ 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 (!word_skipped) {
+            /* Skip the first string, which is the path to qemu-*-static
+               instead of the actual command. */
+            cp_buf = memchr(buf, 0, sizeof(buf));
+            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) {
+                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)
@@ -5150,6 +5195,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
-- 
2.0.0.rc2

  parent reply	other threads:[~2014-06-29 12:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-29 12:14 [Qemu-devel] [PULL v2 00/13] linux-user changes for 2.1 riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 01/13] Add support for MAP_NORESERVE mmap flag riku.voipio
2014-06-29 12:14 ` riku.voipio [this message]
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 03/13] linux-user: translate the result of getsockopt SO_TYPE riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 04/13] linux-user: support SO_ACCEPTCONN getsockopt option riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 05/13] linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 06/13] linux-user: support SO_PASSSEC setsockopt option riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 07/13] linux-user: allow NULL arguments to mount riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 08/13] linux-user: support strace of epoll_create1 riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 09/13] linux-user: fix struct target_epoll_event layout for MIPS riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 10/13] linux-user: respect timezone for settimeofday riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 11/13] linux-user: allow NULL tv argument " riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 12/13] linux-user: support the KDSIGACCEPT ioctl riku.voipio
2014-06-29 12:14 ` [Qemu-devel] [PULL v2 13/13] linux-user: support the SIOCGIFINDEX ioctl riku.voipio
2014-06-29 17:09 ` [Qemu-devel] [PULL v2 00/13] linux-user changes for 2.1 Peter Maydell

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=76b94245507881a0621c5bb3b144c3c19dcbcb4d.1404041926.git.riku.voipio@linaro.org \
    --to=riku.voipio@linaro.org \
    --cc=aliguori@amazon.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wim@fixnum.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.