[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] Re: [PATCH] Overwrite argv to set process title, eliminatin
From: |
John Morrissey |
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 |
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
address@hidden _-< \_ / \ ---- < \,
www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__