From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53335 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFtl7-0004HG-8I for qemu-devel@nongnu.org; Tue, 09 Nov 2010 14:21:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFtl6-0007Ab-0s for qemu-devel@nongnu.org; Tue, 09 Nov 2010 14:21:33 -0500 Received: from boost.horde.net ([69.55.65.181]:44514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFtl5-0007AJ-Un for qemu-devel@nongnu.org; Tue, 09 Nov 2010 14:21:31 -0500 Date: Tue, 9 Nov 2010 14:21:30 -0500 From: John Morrissey Message-ID: <20101109192130.GA10867@boost.horde.net> References: <1289144652-23463-1-git-send-email-jwm@horde.net> <201011072149.28266.torsten.foertsch@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <201011072149.28266.torsten.foertsch@gmx.net> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH] Overwrite argv to set process title, eliminating 16-character prctl() limit. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Torsten =?iso-8859-1?Q?F=F6rtsch?= Cc: qemu-devel@nongnu.org On Sun, Nov 07, 2010 at 09:49:27PM +0100, Torsten F=F6rtsch wrote: > I am quite new to the list but why not do both call prctl(PR_SET_NAME, > name) and overwrite argv? >=20 > The point is some tools read /proc/PID/cmdline but others the name fiel= d in=20 > /proc/PID/status. The former is changed by overwriting argv the latter = by=20 > 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" =20 +#ifdef CONFIG_LINUX +#include +#endif + #ifdef CONFIG_EVENTFD #include #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; =20 if (!name) return; =20 +#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 =3D argv[argc - 1] + strlen(argv[argc - 1]); =20 len =3D snprintf(argv[0], last_argv_byte - argv[0], "%s", name); --=20 John Morrissey _o /\ ---- __o jwm@horde.net _-< \_ / \ ---- < \, www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__