diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 8019d4488cc..26f896b90a8 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -1370,7 +1370,7 @@ static const struct hash_ops dhcp6_prefixes_hash_ops = { .compare = dhcp6_prefixes_compare_func, }; -int manager_new(Manager **ret, sd_event *event) { +int manager_new(Manager **ret) { _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -1382,7 +1382,13 @@ int manager_new(Manager **ret, sd_event *event) { if (!m->state_file) return -ENOMEM; - m->event = sd_event_ref(event); + r = sd_event_default(&m->event); + if (r < 0) + return r; + + sd_event_set_watchdog(m->event, true); + sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL); + sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); r = sd_event_add_post(m->event, NULL, manager_dirty_handler, m); if (r < 0) diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 3543e5861d2..a6cb1e2d44a 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -65,7 +65,7 @@ static inline const DUID* link_duid(const Link *link) { extern const sd_bus_vtable manager_vtable[]; -int manager_new(Manager **ret, sd_event *event); +int manager_new(Manager **ret); void manager_free(Manager *m); int manager_connect_bus(Manager *m); diff --git a/src/network/networkd.c b/src/network/networkd.c index b59b3081413..d2467b70cee 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -10,7 +10,6 @@ #include "user-util.h" int main(int argc, char *argv[]) { - sd_event *event = NULL; _cleanup_(manager_freep) Manager *m = NULL; const char *user = "systemd-network"; uid_t uid; @@ -71,15 +70,7 @@ int main(int argc, char *argv[]) { assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); - r = sd_event_default(&event); - if (r < 0) - goto out; - - sd_event_set_watchdog(event, true); - sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); - sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - - r = manager_new(&m, event); + r = manager_new(&m); if (r < 0) { log_error_errno(r, "Could not create manager: %m"); goto out; @@ -137,7 +128,7 @@ int main(int argc, char *argv[]) { "READY=1\n" "STATUS=Processing requests..."); - r = sd_event_loop(event); + r = sd_event_loop(m->event); if (r < 0) { log_error_errno(r, "Event loop failed: %m"); goto out; @@ -147,7 +138,5 @@ out: "STOPPING=1\n" "STATUS=Shutting down..."); - sd_event_unref(event); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/src/network/test-network.c b/src/network/test-network.c index 5349b668bee..35c982a91d7 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -219,7 +219,6 @@ static void test_dhcp_hostname_shorten_overlong(void) { int main(void) { _cleanup_(manager_freep) Manager *manager = NULL; - _cleanup_(sd_event_unrefp) sd_event *event = NULL; _cleanup_(udev_unrefp) struct udev *udev = NULL; _cleanup_(udev_device_unrefp) struct udev_device *loopback = NULL; int r; @@ -229,9 +228,7 @@ int main(void) { test_address_equality(); test_dhcp_hostname_shorten_overlong(); - assert_se(sd_event_default(&event) >= 0); - - assert_se(manager_new(&manager, event) >= 0); + assert_se(manager_new(&manager) >= 0); r = test_load_config(manager); if (r == -EPERM)