All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Guido Günther" <agx@sigxcpu.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Add guest-get-hostname to retrieve the guests current hostname
Date: Tue, 21 Aug 2012 19:31:17 +0100	[thread overview]
Message-ID: <20120821183117.GA18191@redhat.com> (raw)
In-Reply-To: <20120821115754.GA5855@bogon.sigxcpu.org>

On Tue, Aug 21, 2012 at 01:57:54PM +0200, Guido Günther wrote:
> 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ünther <agx@sigxcpu.org>
> ---
> 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 <sys/types.h>
>  #include <sys/ioctl.h>
>  #include <sys/wait.h>
> +#include <unistd.h>
>  #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 minimum, Error **err)
>  }
>  #endif
>  
> +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_interfaces(Error **err)
>      return NULL;
>  }
>  
> +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_LINKAGE int WSAAPI gethostname(char *name,int namelen);

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2012-08-21 18:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21 11:57 [Qemu-devel] [PATCH] Add guest-get-hostname to retrieve the guests current hostname Guido Günther
2012-08-21 18:31 ` Daniel P. Berrange [this message]
2012-08-22  8:04   ` Guido Günther
2012-08-22  8:32     ` Daniel P. Berrange
2012-08-24 15:31       ` Guido Günther
2012-08-21 19:16 ` Eric Blake
2012-08-23 12:48 ` Luiz Capitulino
2012-08-23 14:08   ` Michael Roth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120821183117.GA18191@redhat.com \
    --to=berrange@redhat.com \
    --cc=agx@sigxcpu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.