chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
aba2685
)
libsystemd-dhcp: Factor out common code initializing events
author
Patrik Flykt
<patrik.flykt@linux.intel.com>
Fri, 20 Dec 2013 15:16:19 +0000
(17:16 +0200)
committer
Tom Gundersen
<teg@jklm.no>
Sun, 22 Dec 2013 13:37:53 +0000
(14:37 +0100)
Factor out common code from timeout T1 handling and starting of
the DHCP client.
src/libsystemd-dhcp/dhcp-client.c
patch
|
blob
|
history
diff --git
a/src/libsystemd-dhcp/dhcp-client.c
b/src/libsystemd-dhcp/dhcp-client.c
index 102353894c08089e2675a1a85ba9c22237f95343..23669c7f0375b3a6514aedb957f55918569ed7e1 100644
(file)
--- a/
src/libsystemd-dhcp/dhcp-client.c
+++ b/
src/libsystemd-dhcp/dhcp-client.c
@@
-607,6
+607,28
@@
error:
return 0;
}
return 0;
}
+static int client_initialize_events(sd_dhcp_client *client, usec_t usec)
+{
+ int r;
+
+ r = sd_event_add_io(client->event, client->fd, EPOLLIN,
+ client_receive_message, client,
+ &client->receive_message);
+ if (r < 0)
+ goto error;
+
+ r = sd_event_add_monotonic(client->event, usec, 0,
+ client_timeout_resend, client,
+ &client->timeout_resend);
+
+error:
+ if (r < 0)
+ client_stop(client, r);
+
+ return 0;
+
+}
+
static int client_timeout_expire(sd_event_source *s, uint64_t usec,
void *userdata)
{
static int client_timeout_expire(sd_event_source *s, uint64_t usec,
void *userdata)
{
@@
-632,28
+654,14
@@
static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata)
r = dhcp_network_bind_udp_socket(client->index,
client->lease->address);
r = dhcp_network_bind_udp_socket(client->index,
client->lease->address);
- if (r < 0)
- goto error;
+ if (r < 0) {
+ client_stop(client, r);
+ return 0;
+ }
client->fd = r;
client->fd = r;
- r = sd_event_add_io(client->event, client->fd, EPOLLIN,
- client_receive_message, client,
- &client->receive_message);
- if (r < 0)
- goto error;
- r = sd_event_add_monotonic(client->event, usec, 0,
- client_timeout_resend, client,
- &client->timeout_resend);
- if (r < 0)
- goto error;
-
- return 0;
-
-error:
- client_stop(client, r);
-
- return 0;
+ return client_initialize_events(client, usec);
}
static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
}
static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
@@
-1019,7
+1027,7
@@
error:
int sd_dhcp_client_start(sd_dhcp_client *client)
{
int sd_dhcp_client_start(sd_dhcp_client *client)
{
- int
er
r;
+ int r;
assert_return(client, -EINVAL);
assert_return(client->index >= 0, -EINVAL);
assert_return(client, -EINVAL);
assert_return(client->index >= 0, -EINVAL);
@@
-1028,33
+1036,17
@@
int sd_dhcp_client_start(sd_dhcp_client *client)
client->xid = random_u();
client->xid = random_u();
- client->fd = dhcp_network_bind_raw_socket(client->index,
- &client->link);
+ r = dhcp_network_bind_raw_socket(client->index, &client->link);
- if (
client->fd
< 0) {
-
err = client->fd
;
-
goto erro
r;
+ if (
r
< 0) {
+
client_stop(client, r)
;
+
return
r;
}
}
- err = sd_event_add_io(client->event, client->fd, EPOLLIN,
- client_receive_message, client,
- &client->receive_message);
- if (err < 0)
- goto error;
-
+ client->fd = r;
client->start_time = now(CLOCK_MONOTONIC);
client->start_time = now(CLOCK_MONOTONIC);
- err = sd_event_add_monotonic(client->event, client->start_time, 0,
- client_timeout_resend, client,
- &client->timeout_resend);
- if (err < 0)
- goto error;
-
- return 0;
-error:
- client_stop(client, err);
-
- return err;
+ return client_initialize_events(client, client->start_time);
}
int sd_dhcp_client_stop(sd_dhcp_client *client)
}
int sd_dhcp_client_stop(sd_dhcp_client *client)