[systemd-devel] [PATCH v2] networkd: send hostname to dhcp server
Lennart Poettering
lennart at poettering.net
Tue Jul 1 12:53:58 PDT 2014
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.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list