From patchwork Thu Jun 3 16:48:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 54495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 524FAB7D30 for ; Fri, 4 Jun 2010 02:52:32 +1000 (EST) Received: from localhost ([127.0.0.1]:46296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKDef-0004JB-NF for incoming@patchwork.ozlabs.org; Thu, 03 Jun 2010 12:52:29 -0400 Received: from [140.186.70.92] (port=59693 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKDb9-0002ma-T8 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 12:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKDb4-0006Ae-N8 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 12:48:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42548) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKDb4-0006AW-G1 for qemu-devel@nongnu.org; Thu, 03 Jun 2010 12:48:46 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o53Gmi2G024140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 3 Jun 2010 12:48:44 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o53GmE8r028747; Thu, 3 Jun 2010 12:48:42 -0400 From: Jes.Sorensen@redhat.com To: anthony@codemonkey.ws Date: Thu, 3 Jun 2010 18:48:12 +0200 Message-Id: <1275583692-11678-17-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1275583692-11678-1-git-send-email-Jes.Sorensen@redhat.com> References: <1275583692-11678-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jes Sorensen , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 16/16] Move set_proc_name() to OS specific files. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen Move handling to change process name to POSIX specific files plus add a better error message to cover the case where the feature isn't supported. Signed-off-by: Jes Sorensen --- os-posix.c | 24 ++++++++++++++++++++++++ qemu-os-posix.h | 1 + qemu-os-win32.h | 1 + vl.c | 19 +------------------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/os-posix.c b/os-posix.c index 7530276..03105f7 100644 --- a/os-posix.c +++ b/os-posix.c @@ -36,6 +36,10 @@ #include "sysemu.h" #include "net/slirp.h" +#ifdef CONFIG_LINUX +#include +#endif + static struct passwd *user_pwd; static const char *chroot_dir; static int daemonize; @@ -138,6 +142,26 @@ char *os_find_datadir(const char *argv0) #undef SHARE_SUFFIX #undef BUILD_SUFFIX +void os_set_proc_name(const char *s) +{ +#if defined(PR_SET_NAME) + 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'. */ + if (prctl(PR_SET_NAME, name)) { + perror("unable to change process name"); + exit(1); + } +#else + fprintf(stderr, "Change of process name not supported by your OS\n"); + exit(1); +#endif +} + /* * Duplicate definition from vl.c to avoid messing up the entire build */ diff --git a/qemu-os-posix.h b/qemu-os-posix.h index cb210ba..ed5c058 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout) } void os_set_line_buffering(void); +void os_set_proc_name(const char *s); void os_setup_signal_handling(void); void os_daemonize(void); void os_setup_post(void); diff --git a/qemu-os-win32.h b/qemu-os-win32.h index 1709cf6..bb7126b 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -47,5 +47,6 @@ static inline void os_daemonize(void) {}; static inline void os_setup_post(void) {}; /* Win32 doesn't support line-buffering and requires size >= 2 */ static inline void os_set_line_buffering(void) {}; +static inline void os_set_proc_name(const char *dummy) {}; #endif diff --git a/vl.c b/vl.c index 3dbc789..b77dce8 100644 --- a/vl.c +++ b/vl.c @@ -59,7 +59,6 @@ #ifdef __linux__ #include #include -#include #include #include @@ -283,22 +282,6 @@ static int default_driver_check(QemuOpts *opts, void *opaque) } /***********************************************************/ - -static void set_proc_name(const char *s) -{ -#if defined(__linux__) && defined(PR_SET_NAME) - 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 -} - -/***********************************************************/ /* real time host monotonic timer */ /* compute with 96 bit intermediate result: (a*b)/c */ @@ -2990,7 +2973,7 @@ int main(int argc, char **argv, char **envp) exit(1); } p += 8; - set_proc_name(p); + os_set_proc_name(p); } } break;