From patchwork Thu Jun 10 09:42:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 55189 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 D3661B7D84 for ; Thu, 10 Jun 2010 20:08:33 +1000 (EST) Received: from localhost ([127.0.0.1]:44412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMegZ-0004JG-1P for incoming@patchwork.ozlabs.org; Thu, 10 Jun 2010 06:08:31 -0400 Received: from [140.186.70.92] (port=49982 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMeI4-0005fr-Ji for qemu-devel@nongnu.org; Thu, 10 Jun 2010 05:43:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMeI2-0001sm-IG for qemu-devel@nongnu.org; Thu, 10 Jun 2010 05:43:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47707) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMeI2-0001sZ-8U for qemu-devel@nongnu.org; Thu, 10 Jun 2010 05:43:10 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5A9h820016799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Jun 2010 05:43:08 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5A9gdkE020632; Thu, 10 Jun 2010 05:43:07 -0400 From: Jes.Sorensen@redhat.com To: anthony@codemonkey.ws Date: Thu, 10 Jun 2010 11:42:31 +0200 Message-Id: <1276162951-842-18-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1276162951-842-1-git-send-email-Jes.Sorensen@redhat.com> References: <1276162951-842-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 17/17] 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 Acked-by: Juan Quintela Acked-by: Richard Henderson --- 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 9bae8fe..d89020d 100644 --- a/os-posix.c +++ b/os-posix.c @@ -37,6 +37,10 @@ #include "net/slirp.h" #include "qemu-options.h" +#ifdef CONFIG_LINUX +#include +#endif + static struct passwd *user_pwd; static const char *chroot_dir; static int daemonize; @@ -139,6 +143,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 +} + /* * Parse OS specific command line options. * return 0 if option handled, -1 otherwise 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 5a97d8d..6323f7f 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 f18886a..9eac300 100644 --- a/vl.c +++ b/vl.c @@ -59,7 +59,6 @@ #ifdef __linux__ #include #include -#include #include #include @@ -284,22 +283,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 */ @@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp) exit(1); } p += 8; - set_proc_name(p); + os_set_proc_name(p); } } break;