All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Morrissey <jwm@horde.net>
To: "Torsten Förtsch" <torsten.foertsch@gmx.net>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] Overwrite argv to set process title, eliminating 16-character prctl() limit.
Date: Tue, 9 Nov 2010 14:21:30 -0500	[thread overview]
Message-ID: <20101109192130.GA10867@boost.horde.net> (raw)
In-Reply-To: <201011072149.28266.torsten.foertsch@gmx.net>

On Sun, Nov 07, 2010 at 09:49:27PM +0100, Torsten Förtsch wrote:
> I am quite new to the list but why not do both call prctl(PR_SET_NAME,
> name) and overwrite argv?
> 
> The point is some tools read /proc/PID/cmdline but others the name field in 
> /proc/PID/status. The former is changed by overwriting argv the latter by 
> prctl.

Seems reasonable. This patch applies on top of the previous to re-add
prctl().

john

diff --git a/os-posix.c b/os-posix.c
index 3ddf7e8..38fb55e 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -39,6 +39,10 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+#ifdef CONFIG_LINUX
+#include <sys/prctl.h>
+#endif
+
 #ifdef CONFIG_EVENTFD
 #include <sys/eventfd.h>
 #endif
@@ -148,12 +152,20 @@ char *os_find_datadir(const char *argv0)
 void os_set_proc_name(int argc, char **argv, const char *name)
 {
 #ifdef CONFIG_LINUX
-    char *last_argv_byte, *p;
+    char prctl_name[16], *last_argv_byte, *p;
     int len, i;
 
     if (!name)
         return;
 
+#if defined(PR_SET_NAME)
+    strncpy(prctl_name, name, sizeof(prctl_name));
+    if (prctl(PR_SET_NAME, prctl_name)) {
+        perror("unable to change process name");
+        exit(1);
+    }
+#endif
+
     last_argv_byte = argv[argc - 1] + strlen(argv[argc - 1]);
 
     len = snprintf(argv[0], last_argv_byte - argv[0], "%s", name);

-- 
John Morrissey          _o            /\         ----  __o
jwm@horde.net        _-< \_          /  \       ----  <  \,
www.horde.net/    __(_)/_(_)________/    \_______(_) /_(_)__

      reply	other threads:[~2010-11-09 19:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-07 15:44 [Qemu-devel] [PATCH] Overwrite argv to set process title, eliminating 16-character prctl() limit John Morrissey
2010-11-07 18:27 ` Andreas Färber
2010-11-07 19:42   ` [Qemu-devel] " John Morrissey
2010-11-07 20:49 ` [Qemu-devel] " Torsten Förtsch
2010-11-09 19:21   ` John Morrissey [this message]

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=20101109192130.GA10867@boost.horde.net \
    --to=jwm@horde.net \
    --cc=qemu-devel@nongnu.org \
    --cc=torsten.foertsch@gmx.net \
    /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.