mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
qga: move qga_get_host_name()
The function is specific to qemu-ga, no need to share it in QEMU. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-Id: <20220420132624.2439741-32-marcandre.lureau@redhat.com>
This commit is contained in:
parent
756a98dd70
commit
548fb0da73
7 changed files with 60 additions and 59 deletions
|
@ -3278,3 +3278,38 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
# ifdef _POSIX_HOST_NAME_MAX
|
||||
# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
|
||||
# else
|
||||
# define HOST_NAME_MAX 255
|
||||
# endif
|
||||
#endif
|
||||
|
||||
char *qga_get_host_name(Error **errp)
|
||||
{
|
||||
long len = -1;
|
||||
g_autofree char *hostname = NULL;
|
||||
|
||||
#ifdef _SC_HOST_NAME_MAX
|
||||
len = sysconf(_SC_HOST_NAME_MAX);
|
||||
#endif /* _SC_HOST_NAME_MAX */
|
||||
|
||||
if (len < 0) {
|
||||
len = HOST_NAME_MAX;
|
||||
}
|
||||
|
||||
/* Unfortunately, gethostname() below does not guarantee a
|
||||
* NULL terminated string. Therefore, allocate one byte more
|
||||
* to be sure. */
|
||||
hostname = g_new0(char, len + 1);
|
||||
|
||||
if (gethostname(hostname, len) < 0) {
|
||||
error_setg_errno(errp, errno,
|
||||
"cannot get hostname");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_steal_pointer(&hostname);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue