[systemd-commits] 2 commits - src/libsystemd-network
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Apr 11 16:00:39 PDT 2014
src/libsystemd-network/sd-dhcp-client.c | 49 ++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 14 deletions(-)
New commits:
commit 998d8047029fb922ec42e55c9ed0c8926d1d9223
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Apr 12 01:01:13 2014 +0200
sd-dhcp-client: improve logging
Specify what kind of REQUEST we send, and distinguish between REBOOT and START.
Also log stop reasons as strings rather than numbers.
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index eb4720d..48de213 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -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);
}
@@ -1091,6 +1109,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 +1265,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) {
commit 7739a40b45fcc00874f8760be3d26534ed76cd45
Author: Tom Gundersen <teg at jklm.no>
Date: Sat Apr 12 00:34:05 2014 +0200
sd-dhcp-client: use client_initialiez and client_restart for REBOOT
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 0adcf13..eb4720d 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -485,6 +485,8 @@ static int client_send_request(sd_dhcp_client *client) {
return 0;
}
+static int client_start(sd_dhcp_client *client);
+
static int client_timeout_resend(sd_event_source *s, uint64_t usec,
void *userdata) {
sd_dhcp_client *client = userdata;
@@ -523,17 +525,14 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
case DHCP_STATE_REBOOTING:
/* start over as we did not receive a timely ack or nak */
- client->state = DHCP_STATE_INIT;
- client->attempt = 1;
-
- client->fd = safe_close(client->fd);
- client->xid = random_u32();
- r = dhcp_network_bind_raw_socket(client->index, &client->link, client->xid);
+ r = client_initialize(client);
if (r < 0)
goto error;
- client->fd = r;
- /* fall through */
+ return client_start(client);
+
+ break;
+
case DHCP_STATE_INIT:
case DHCP_STATE_INIT_REBOOT:
case DHCP_STATE_SELECTING:
@@ -677,7 +676,6 @@ static int client_start(sd_dhcp_client *client) {
client->xid = random_u32();
r = dhcp_network_bind_raw_socket(client->index, &client->link, client->xid);
-
if (r < 0) {
client_stop(client, r);
return r;
@@ -726,7 +724,6 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
client_stop(client, r);
return 0;
}
-
client->fd = r;
log_dhcp_client(client, "TIMEOUT T2");
More information about the systemd-commits
mailing list