From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3tEi-0007Mc-1Q for qemu-devel@nongnu.org; Tue, 21 Aug 2012 14:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3tEb-0003rq-6w for qemu-devel@nongnu.org; Tue, 21 Aug 2012 14:31:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3tEa-0003rf-VR for qemu-devel@nongnu.org; Tue, 21 Aug 2012 14:31:25 -0400 Date: Tue, 21 Aug 2012 19:31:17 +0100 From: "Daniel P. Berrange" Message-ID: <20120821183117.GA18191@redhat.com> References: <20120821115754.GA5855@bogon.sigxcpu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20120821115754.GA5855@bogon.sigxcpu.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] Add guest-get-hostname to retrieve the guests current hostname Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Guido =?utf-8?Q?G=C3=BCnther?= Cc: qemu-devel@nongnu.org On Tue, Aug 21, 2012 at 01:57:54PM +0200, Guido G=C3=BCnther wrote: > This allows to retrieve the guest's hostname via gethostname(2). >=20 > This can be useful to identify a VM e.g. one without network. >=20 > Signed-off-by: Guido G=C3=BCnther > --- > We have an API in libvirt for that (virDomainGetHostname). > Cheers > -- Guido >=20 > qapi-schema-guest.json | 12 ++++++++++++ > qga/commands-posix.c | 12 ++++++++++++ > qga/commands-win32.c | 6 ++++++ > 3 files changed, 30 insertions(+) >=20 > 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 mi= nimum, 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_i= nterfaces(Error **err) > return NULL; > } > =20 > +char *qmp_guest_get_hostname(Error **err) > +{ > + error_set(err, QERR_UNSUPPORTED); > + return NULL; > +} Why no impl ? Winsock has the gethostname() API too $ grep gethostname /usr/i686-w64-mingw32/sys-root/mingw/include/*.h /usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h: WINSOCK_API_LIN= KAGE int WSAAPI gethostname(char *name,int namelen); Regards, Daniel --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|