From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3ne0-0003P4-6I for qemu-devel@nongnu.org; Tue, 21 Aug 2012 08:33:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3ndz-0000eF-1Y for qemu-devel@nongnu.org; Tue, 21 Aug 2012 08:33:16 -0400 Received: from xvm-169-183.ghst.net ([95.142.169.183]:38586 helo=photon.sigxcpu.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3ndy-0000ds-R9 for qemu-devel@nongnu.org; Tue, 21 Aug 2012 08:33:14 -0400 Received: from honk.sigxcpu.org (localhost [127.0.0.1]) by photon.sigxcpu.org (Postfix) with ESMTPS id 04754890 for ; Tue, 21 Aug 2012 13:57:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by honk.sigxcpu.org (Postfix) with ESMTP id 7F054FB03 for ; Tue, 21 Aug 2012 13:57:56 +0200 (CEST) Received: from honk.sigxcpu.org ([127.0.0.1]) by localhost (honk.sigxcpu.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RiaLLHwBlxIw for ; Tue, 21 Aug 2012 13:57:55 +0200 (CEST) Date: Tue, 21 Aug 2012 13:57:54 +0200 From: Guido =?iso-8859-1?Q?G=FCnther?= Message-ID: <20120821115754.GA5855@bogon.sigxcpu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] Add guest-get-hostname to retrieve the guests current hostname List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This allows to retrieve the guest's hostname via gethostname(2). This can be useful to identify a VM e.g. one without network. Signed-off-by: Guido G=FCnther --- We have an API in libvirt for that (virDomainGetHostname). Cheers -- Guido qapi-schema-guest.json | 12 ++++++++++++ qga/commands-posix.c | 12 ++++++++++++ qga/commands-win32.c | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json index d955cf1..8c7a4a5 100644 --- a/qapi-schema-guest.json +++ b/qapi-schema-guest.json @@ -515,3 +515,15 @@ ## { 'command': 'guest-network-get-interfaces', 'returns': ['GuestNetworkInterface'] } + +## +# @guest-get-hostname: +# +# Get the guest's hostname +# +# Returns: The guest's hostname +# +# Since: 1.2 +## +{ 'command': 'guest-get-hostname', + 'returns': 'str' } diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ce90421..9223f18 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "qga/guest-agent-core.h" #include "qga-qmp-commands.h" #include "qerror.h" @@ -993,6 +994,17 @@ void qmp_guest_fstrim(bool has_minimum, int64_t mini= mum, Error **err) } #endif =20 +char *qmp_guest_get_hostname(Error **err) +{ + char hostname[HOST_NAME_MAX]; + + if (gethostname(hostname, HOST_NAME_MAX)) { + error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno)); + return NULL; + } + return g_strdup(hostname); +} + /* register init/cleanup routines for stateful command groups */ void ga_command_state_init(GAState *s, GACommandState *cs) { diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 54bc546..55e8162 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -280,6 +280,12 @@ GuestNetworkInterfaceList *qmp_guest_network_get_int= erfaces(Error **err) return NULL; } =20 +char *qmp_guest_get_hostname(Error **err) +{ + error_set(err, QERR_UNSUPPORTED); + return NULL; +} + /* register init/cleanup routines for stateful command groups */ void ga_command_state_init(GAState *s, GACommandState *cs) { --=20 1.7.10.4