mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
lldp: do not unref() event sources when update or disable them
This commit is contained in:
parent
8158b90d59
commit
6ec11d46dc
@ -7,6 +7,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "event-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "lldp-internal.h"
|
||||
#include "lldp-neighbor.h"
|
||||
@ -235,7 +236,7 @@ static int lldp_receive_datagram(sd_event_source *s, int fd, uint32_t revents, v
|
||||
static void lldp_reset(sd_lldp *lldp) {
|
||||
assert(lldp);
|
||||
|
||||
lldp->timer_event_source = sd_event_source_unref(lldp->timer_event_source);
|
||||
(void) event_source_disable(lldp->timer_event_source);
|
||||
lldp->io_event_source = sd_event_source_unref(lldp->io_event_source);
|
||||
lldp->fd = safe_close(lldp->fd);
|
||||
}
|
||||
@ -344,6 +345,8 @@ _public_ int sd_lldp_set_ifindex(sd_lldp *lldp, int ifindex) {
|
||||
static sd_lldp* lldp_free(sd_lldp *lldp) {
|
||||
assert(lldp);
|
||||
|
||||
lldp->timer_event_source = sd_event_source_unref(lldp->timer_event_source);
|
||||
|
||||
lldp_reset(lldp);
|
||||
sd_lldp_detach_event(lldp);
|
||||
lldp_flush_neighbors(lldp);
|
||||
@ -406,7 +409,6 @@ static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) {
|
||||
|
||||
static int lldp_start_timer(sd_lldp *lldp, sd_lldp_neighbor *neighbor) {
|
||||
sd_lldp_neighbor *n;
|
||||
int r;
|
||||
|
||||
assert(lldp);
|
||||
|
||||
@ -414,35 +416,17 @@ static int lldp_start_timer(sd_lldp *lldp, sd_lldp_neighbor *neighbor) {
|
||||
lldp_neighbor_start_ttl(neighbor);
|
||||
|
||||
n = prioq_peek(lldp->neighbor_by_expiry);
|
||||
if (!n) {
|
||||
|
||||
if (lldp->timer_event_source)
|
||||
return sd_event_source_set_enabled(lldp->timer_event_source, SD_EVENT_OFF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lldp->timer_event_source) {
|
||||
r = sd_event_source_set_time(lldp->timer_event_source, n->until);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return sd_event_source_set_enabled(lldp->timer_event_source, SD_EVENT_ONESHOT);
|
||||
}
|
||||
if (!n)
|
||||
return event_source_disable(lldp->timer_event_source);
|
||||
|
||||
if (!lldp->event)
|
||||
return 0;
|
||||
|
||||
r = sd_event_add_time(lldp->event, &lldp->timer_event_source, clock_boottime_or_monotonic(), n->until, 0, on_timer_event, lldp);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_event_source_set_priority(lldp->timer_event_source, lldp->event_priority);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(lldp->timer_event_source, "lldp-timer");
|
||||
return 0;
|
||||
return event_reset_time(lldp->event, &lldp->timer_event_source,
|
||||
clock_boottime_or_monotonic(),
|
||||
n->until, 0,
|
||||
on_timer_event, lldp,
|
||||
lldp->event_priority, "lldp-timer", true);
|
||||
}
|
||||
|
||||
_public_ int sd_lldp_get_neighbors(sd_lldp *lldp, sd_lldp_neighbor ***ret) {
|
||||
|
Loading…
Reference in New Issue
Block a user