From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MMGoO-0000Lq-0p for qemu-devel@nongnu.org; Thu, 02 Jul 2009 03:34:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MMGoI-0000LS-H4 for qemu-devel@nongnu.org; Thu, 02 Jul 2009 03:34:26 -0400 Received: from [199.232.76.173] (port=33364 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MMGoI-0000LP-BN for qemu-devel@nongnu.org; Thu, 02 Jul 2009 03:34:22 -0400 Received: from one.firstfloor.org ([213.235.205.2]:34722) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MMGoH-0003Lc-Pi for qemu-devel@nongnu.org; Thu, 02 Jul 2009 03:34:22 -0400 Received: from basil.firstfloor.org (p5B3CB7C5.dip0.t-ipconnect.de [91.60.183.197]) by one.firstfloor.org (Postfix) with ESMTP id 8284B1A98002 for ; Thu, 2 Jul 2009 09:34:17 +0200 (CEST) Date: Thu, 2 Jul 2009 09:34:17 +0200 From: Andi Kleen Message-ID: <20090702073417.GA11198@basil.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] Allow setting qemu process name v2 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Set the Linux process name to the name argument specified with name. I find this useful to see which guests are taking CPU time in top. This doesn't affect ps, which checks argv[0], but rewriting the environment uses much more code, so I only used this simple way. v2: Use separate process= argument, no prefixes. Signed-off-by: Andi Kleen diff --git a/qemu-options.hx b/qemu-options.hx index a94f9d3..5ca7260 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -365,12 +365,14 @@ Network adapter that supports CDC ethernet and RNDIS protocols. ETEXI DEF("name", HAS_ARG, QEMU_OPTION_name, - "-name string set the name of the guest\n") + "-name string1[,process=string2] set the name of the guest\n" + " string1 sets the window title and string2 the process name (on Linux)\n") STEXI @item -name @var{name} Sets the @var{name} of the guest. This name will be displayed in the SDL window caption. The @var{name} will also be used for the VNC server. +Also optionally set the top visible process name in Linux. ETEXI DEF("uuid", HAS_ARG, QEMU_OPTION_uuid, diff --git a/vl.c b/vl.c index 7b7489c..5818640 100644 --- a/vl.c +++ b/vl.c @@ -68,6 +68,7 @@ #include #include #include +#include /* For the benefit of older linux systems which don't supply it, we use a local copy of hpet.h. */ @@ -526,6 +527,20 @@ void hw_error(const char *fmt, ...) va_end(ap); abort(); } + +static void set_proc_name(const char *s) +{ +#ifdef __linux__ + char name[16]; + if (!s) + return; + name[sizeof(name) - 1] = 0; + strncpy(name, s, sizeof(name)); + /* Could rewrite argv[0] too, but that's a bit more complicated. + This simple way is enough for `top'. */ + prctl(PR_SET_NAME, name); +#endif +} /***************/ /* ballooning */ @@ -5644,7 +5659,19 @@ int main(int argc, char **argv, char **envp) break; #endif case QEMU_OPTION_name: - qemu_name = optarg; + qemu_name = qemu_strdup(optarg); + { + char *p = strchr(qemu_name, ','); + if (p != NULL) { + *p++ = 0; + if (strncmp(p, "process=", 8)) { + fprintf(stderr, "Unknown subargument %s to -name", p); + exit(1); + } + p += 8; + set_proc_name(p); + } + } break; #if defined(TARGET_SPARC) || defined(TARGET_PPC) case QEMU_OPTION_prom_env: -- ak@linux.intel.com -- Speaking for myself only.