[systemd-devel] [PATCH v2] networkd: send hostname to dhcp server

Tom Gundersen teg at jklm.no
Tue Jul 1 13:04:33 PDT 2014


On Tue, Jul 1, 2014 at 9:53 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> On Tue, 01.07.14 11:58, Eugene Yakubovich (eugene.yakubovich at coreos.com) wrote:
>
>> +int sd_dhcp_client_set_hostname(sd_dhcp_client *client,
>> +                        const char *hostname) {
>> +
>> +        assert_return(client, -EINVAL);
>> +
>> +        if (streq_ptr(client->hostname, hostname))
>> +                return 0;
>> +
>> +        free(client->hostname);
>> +
>> +        if (hostname) {
>> +                client->hostname = strdup(hostname);
>> +                if (!client->hostname)
>> +                        return -ENOMEM;
>> +        } else
>> +                client->hostname = NULL;
>
> I'd always recommend allocating the new string first, and only then
> freeing the old string. That way the function either fails with no
> change to the object, or it succeeds, but never fails with a changed
> object.


Already fixed this when pushing, so no need for resend.

-t


More information about the systemd-devel mailing list