qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michal Privoznik <mprivozn@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
	vfeenstr@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [PATCH] qga: Use gethostname() instead of g_get_host_name()
Date: Mon, 22 Jun 2020 15:08:53 +0200	[thread overview]
Message-ID: <1708cb61-0dbf-0537-28dd-cd82c8b30378@redhat.com> (raw)
In-Reply-To: <7e31a988-7d6f-7bc5-3563-e77efff87ca3@redhat.com>

On 6/22/20 12:14 PM, Philippe Mathieu-Daudé wrote:
> Hi Michal,
> 
> On 6/16/20 10:34 AM, Michal Privoznik wrote:
>> Problem with g_get_host_name() is that on the first call it saves
>> the hostname into a global variable and from then on, every
>> subsequent call returns the saved hostname. Even if the hostname
>> changes. This doesn't play nicely with guest agent, because if
>> the hostname is acquired before the guest is set up (e.g. on the
>> first boot, or before DHCP) we will report old, invalid hostname.
>>
>> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1845127
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>>   qga/commands.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++----
>>   1 file changed, 52 insertions(+), 4 deletions(-)
>>
>> diff --git a/qga/commands.c b/qga/commands.c
>> index efc8b90281..ce3c2041a6 100644
>> --- a/qga/commands.c
>> +++ b/qga/commands.c
>> @@ -512,14 +512,62 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
>>       return -1;
>>   }
>>   
>> +#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
>> +
>>   GuestHostName *qmp_guest_get_host_name(Error **errp)
>>   {
>>       GuestHostName *result = NULL;
>> -    gchar const *hostname = g_get_host_name();
>> -    if (hostname != NULL) {
>> -        result = g_new0(GuestHostName, 1);
>> -        result->host_name = g_strdup(hostname);
>> +    g_autofree char *hostname = NULL;
>> +
>> +    /*
>> +     * We want to avoid using g_get_host_name() because that
>> +     * caches the result and we wouldn't reflect changes in the
>> +     * host name.
>> +     */
> 
> I see there is only one g_get_host_name() call in the
> codebase, but can we have a generic qemu_get_host_name()
> helper implemented in util/oslib-*c instead?

Sure. Let me post a v2 so that I can include Richard's suggestion too.

Michal



      reply	other threads:[~2020-06-22 13:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16  8:34 [PATCH] qga: Use gethostname() instead of g_get_host_name() Michal Privoznik
2020-06-16  8:43 ` Marc-André Lureau
2020-06-19 21:54 ` Richard Henderson
2020-06-22 10:06   ` Michal Privoznik
2020-06-22 10:14 ` Philippe Mathieu-Daudé
2020-06-22 13:08   ` Michal Privoznik [this message]

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=1708cb61-0dbf-0537-28dd-cd82c8b30378@redhat.com \
    --to=mprivozn@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=vfeenstr@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).