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

Eugene Yakubovich eugene.yakubovich at coreos.com
Tue Jul 1 15:24:11 PDT 2014


On Tue, Jul 1, 2014 at 12: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.
>

Absolutely. I have no idea what I was thinking.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140701/6e2e66f2/attachment.html>


More information about the systemd-devel mailing list