chiark / gitweb /
test-dhcp-client: unref lease objects to make valgrind happy
[elogind.git] / src / libsystemd-network / sd-dhcp-client.c
index eb4720df586e6b318ba129dbf5369e7fdd4d8b02..489220326e90843872e246b7956ced1e6a6b24bd 100644 (file)
@@ -230,7 +230,7 @@ static int client_initialize(sd_dhcp_client *client) {
 static sd_dhcp_client *client_stop(sd_dhcp_client *client, int error) {
         assert_return(client, NULL);
 
-        log_dhcp_client(client, "STOPPED %d", error);
+        log_dhcp_client(client, "STOPPED: %s", strerror(-error));
 
         client = client_notify(client, error);
 
@@ -480,7 +480,23 @@ static int client_send_request(sd_dhcp_client *client) {
         if (r < 0)
                 return r;
 
-        log_dhcp_client(client, "REQUEST");
+        switch (client->state) {
+        case DHCP_STATE_REQUESTING:
+                log_dhcp_client(client, "REQUEST (requesting)");
+                break;
+        case DHCP_STATE_INIT_REBOOT:
+                log_dhcp_client(client, "REQUEST (init-reboot)");
+                break;
+        case DHCP_STATE_RENEWING:
+                log_dhcp_client(client, "REQUEST (renewing)");
+                break;
+        case DHCP_STATE_REBINDING:
+                log_dhcp_client(client, "REQUEST (rebinding)");
+                break;
+        default:
+                log_dhcp_client(client, "REQUEST (invalid)");
+                break;
+        }
 
         return 0;
 }
@@ -529,9 +545,13 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
                 if (r < 0)
                         goto error;
 
-                return client_start(client);
-
-                break;
+                r = client_start(client);
+                if (r < 0)
+                        goto error;
+                else {
+                        log_dhcp_client(client, "REBOOTED");
+                        return 0;
+                }
 
         case DHCP_STATE_INIT:
         case DHCP_STATE_INIT_REBOOT:
@@ -687,8 +707,6 @@ static int client_start(sd_dhcp_client *client) {
                 client->secs = 0;
         }
 
-        log_dhcp_client(client, "STARTED");
-
         return client_initialize_events(client, client_receive_message_raw);
 }
 
@@ -726,8 +744,6 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
         }
         client->fd = r;
 
-        log_dhcp_client(client, "TIMEOUT T2");
-
         return client_initialize_events(client, client_receive_message_raw);
 }
 
@@ -749,8 +765,6 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
 
         client->fd = r;
 
-        log_dhcp_client(client, "TIMEOUT T1");
-
         return client_initialize_events(client, client_receive_message_udp);
 }
 
@@ -791,6 +805,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
                 }
         }
 
+        sd_dhcp_lease_unref(client->lease);
         client->lease = lease;
         lease = NULL;
 
@@ -1091,6 +1106,8 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
                                 r = client_start(client);
                                 if (r < 0)
                                         goto error;
+
+                                log_dhcp_client(client, "REBOOTED");
                         }
 
                         goto error;
@@ -1245,7 +1262,11 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
         if (client->last_addr)
                 client->state = DHCP_STATE_INIT_REBOOT;
 
-        return client_start(client);
+        r = client_start(client);
+        if (r >= 0)
+                log_dhcp_client(client, "STARTED");
+
+        return r;
 }
 
 int sd_dhcp_client_stop(sd_dhcp_client *client) {
@@ -1310,6 +1331,8 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) {
 
                 sd_dhcp_client_detach_event(client);
 
+                sd_dhcp_lease_unref(client->lease);
+
                 free(client->req_opts);
                 free(client);