1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

ipv4acd: do not unref() event sources when update or disable them

This commit is contained in:
Yu Watanabe 2018-11-13 14:18:41 +09:00
parent 4ca5acb35f
commit 32ab66c5ee

View File

@ -14,6 +14,7 @@
#include "alloc-util.h"
#include "arp-util.h"
#include "ether-addr-util.h"
#include "event-util.h"
#include "fd-util.h"
#include "in-addr-util.h"
#include "list.h"
@ -89,7 +90,7 @@ static void ipv4acd_set_state(sd_ipv4acd *acd, IPv4ACDState st, bool reset_count
static void ipv4acd_reset(sd_ipv4acd *acd) {
assert(acd);
acd->timer_event_source = sd_event_source_unref(acd->timer_event_source);
(void) event_source_disable(acd->timer_event_source);
acd->receive_message_event_source = sd_event_source_unref(acd->receive_message_event_source);
acd->fd = safe_close(acd->fd);
@ -100,6 +101,8 @@ static void ipv4acd_reset(sd_ipv4acd *acd) {
static sd_ipv4acd *ipv4acd_free(sd_ipv4acd *acd) {
assert(acd);
acd->timer_event_source = sd_event_source_unref(acd->timer_event_source);
ipv4acd_reset(acd);
sd_ipv4acd_detach_event(acd);
@ -153,9 +156,7 @@ int sd_ipv4acd_stop(sd_ipv4acd *acd) {
static int ipv4acd_on_timeout(sd_event_source *s, uint64_t usec, void *userdata);
static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_usec) {
_cleanup_(sd_event_source_unrefp) sd_event_source *timer = NULL;
usec_t next_timeout, time_now;
int r;
assert(acd);
@ -166,20 +167,11 @@ static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_u
assert_se(sd_event_now(acd->event, clock_boottime_or_monotonic(), &time_now) >= 0);
r = sd_event_add_time(acd->event, &timer, clock_boottime_or_monotonic(), time_now + next_timeout, 0, ipv4acd_on_timeout, acd);
if (r < 0)
return r;
r = sd_event_source_set_priority(timer, acd->event_priority);
if (r < 0)
return r;
(void) sd_event_source_set_description(timer, "ipv4acd-timer");
sd_event_source_unref(acd->timer_event_source);
acd->timer_event_source = TAKE_PTR(timer);
return 0;
return event_reset_time(acd->event, &acd->timer_event_source,
clock_boottime_or_monotonic(),
time_now + next_timeout, 0,
ipv4acd_on_timeout, acd,
acd->event_priority, "ipv4acd-timer", true);
}
static bool ipv4acd_arp_conflict(sd_ipv4acd *acd, struct ether_arp *arp) {