qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
@ 2016-09-28 14:36 Andreas Schwab
  2016-09-28 14:43 ` no-reply
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2016-09-28 14:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: afaerber

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 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."

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
  2016-09-28 14:36 [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline Andreas Schwab
@ 2016-09-28 14:43 ` no-reply
  0 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2016-09-28 14:43 UTC (permalink / raw)
  To: schwab; +Cc: famz, qemu-devel, afaerber

Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: mvma8es147b.fsf@hawking.suse.de
Subject: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20160928143810.25558-1-marcandre.lureau@redhat.com -> patchew/20160928143810.25558-1-marcandre.lureau@redhat.com
 * [new tag]         patchew/mvma8es147b.fsf@hawking.suse.de -> patchew/mvma8es147b.fsf@hawking.suse.de
Switched to a new branch 'test'
7506c8f linux-user: remove all traces of qemu from /proc/self/cmdline

=== OUTPUT BEGIN ===
Checking PATCH 1/1: linux-user: remove all traces of qemu from /proc/self/cmdline...
ERROR: space prohibited between function name and open parenthesis '('
#37: FILE: linux-user/syscall.c:7123:
+        size_t len = strlen (bprm->argv[i]) + 1;

total: 1 errors, 0 warnings, 59 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
@ 2016-10-31 10:43 Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2016-10-31 10:43 UTC (permalink / raw)
  To: qemu-devel

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."

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
@ 2017-03-20 11:31 Andreas Schwab
  2017-05-19 13:59 ` Riku Voipio
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2017-03-20 11:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

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 cec8428589..ec1fd20386 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7358,52 +7358,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.12.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."

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline
  2017-03-20 11:31 Andreas Schwab
@ 2017-05-19 13:59 ` Riku Voipio
  0 siblings, 0 replies; 5+ messages in thread
From: Riku Voipio @ 2017-05-19 13:59 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: qemu-devel

On Mon, Mar 20, 2017 at 12:31:55PM +0100, Andreas Schwab wrote:
> 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.

Applied to Linux-user, thanks

Riku
 
> 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 cec8428589..ec1fd20386 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7358,52 +7358,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.12.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."

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-19 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-28 14:36 [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline Andreas Schwab
2016-09-28 14:43 ` no-reply
  -- strict thread matches above, loose matches on Subject: below --
2016-10-31 10:43 Andreas Schwab
2017-03-20 11:31 Andreas Schwab
2017-05-19 13:59 ` Riku Voipio

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).