chiark / gitweb /
sd-dhcp6-client: Initialize fd to -1 and rename function
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 19 Jun 2014 13:08:37 +0000 (09:08 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 19 Jun 2014 13:09:56 +0000 (09:09 -0400)
client_initialize name is misleading, since the function is actually
useful at the *end*, to reinitialize the object. But reset is shorter,
so rename it to client_reset.

src/libsystemd-network/sd-dhcp6-client.c

index 01d9ec4..ef5fb44 100644 (file)
@@ -153,15 +153,13 @@ static sd_dhcp6_client *client_notify(sd_dhcp6_client *client, int event) {
         return client;
 }
 
-static int client_initialize(sd_dhcp6_client *client)
-{
+static int client_reset(sd_dhcp6_client *client) {
         assert_return(client, -EINVAL);
 
         client->receive_message =
                 sd_event_source_unref(client->receive_message);
 
-        if (client->fd > 0)
-                client->fd = safe_close(client->fd);
+        client->fd = safe_close(client->fd);
 
         client->transaction_id = 0;
 
@@ -186,7 +184,7 @@ static sd_dhcp6_client *client_stop(sd_dhcp6_client *client, int error) {
 
         client = client_notify(client, error);
         if (client)
-                client_initialize(client);
+                client_reset(client);
 
         return client;
 }
@@ -873,7 +871,7 @@ int sd_dhcp6_client_start(sd_dhcp6_client *client)
         assert_return(client->event, -EINVAL);
         assert_return(client->index > 0, -EINVAL);
 
-        r = client_initialize(client);
+        r = client_reset(client);
         if (r < 0)
                 return r;
 
@@ -925,7 +923,7 @@ sd_dhcp6_client *sd_dhcp6_client_ref(sd_dhcp6_client *client) {
 
 sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
         if (client && REFCNT_DEC(client->n_ref) <= 0) {
-                client_initialize(client);
+                client_reset(client);
 
                 sd_dhcp6_client_detach_event(client);
 
@@ -958,6 +956,8 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
 
         client->index = -1;
 
+        client->fd = -1;
+
         /* initialize DUID */
         client->duid.type = htobe16(DHCP6_DUID_EN);
         client->duid.pen = htobe32(SYSTEMD_PEN);