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

network: move sd_event initialization to manager_new()

This commit is contained in:
Yu Watanabe 2018-07-18 12:37:50 +09:00
parent 57916ea352
commit 3534a04300
4 changed files with 12 additions and 20 deletions

View File

@ -1370,7 +1370,7 @@ static const struct hash_ops dhcp6_prefixes_hash_ops = {
.compare = dhcp6_prefixes_compare_func, .compare = dhcp6_prefixes_compare_func,
}; };
int manager_new(Manager **ret, sd_event *event) { int manager_new(Manager **ret) {
_cleanup_(manager_freep) Manager *m = NULL; _cleanup_(manager_freep) Manager *m = NULL;
int r; int r;
@ -1382,7 +1382,13 @@ int manager_new(Manager **ret, sd_event *event) {
if (!m->state_file) if (!m->state_file)
return -ENOMEM; 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); r = sd_event_add_post(m->event, NULL, manager_dirty_handler, m);
if (r < 0) if (r < 0)

View File

@ -65,7 +65,7 @@ static inline const DUID* link_duid(const Link *link) {
extern const sd_bus_vtable manager_vtable[]; 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); void manager_free(Manager *m);
int manager_connect_bus(Manager *m); int manager_connect_bus(Manager *m);

View File

@ -10,7 +10,6 @@
#include "user-util.h" #include "user-util.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
sd_event *event = NULL;
_cleanup_(manager_freep) Manager *m = NULL; _cleanup_(manager_freep) Manager *m = NULL;
const char *user = "systemd-network"; const char *user = "systemd-network";
uid_t uid; uid_t uid;
@ -71,15 +70,7 @@ int main(int argc, char *argv[]) {
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0);
r = sd_event_default(&event); r = manager_new(&m);
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);
if (r < 0) { if (r < 0) {
log_error_errno(r, "Could not create manager: %m"); log_error_errno(r, "Could not create manager: %m");
goto out; goto out;
@ -137,7 +128,7 @@ int main(int argc, char *argv[]) {
"READY=1\n" "READY=1\n"
"STATUS=Processing requests..."); "STATUS=Processing requests...");
r = sd_event_loop(event); r = sd_event_loop(m->event);
if (r < 0) { if (r < 0) {
log_error_errno(r, "Event loop failed: %m"); log_error_errno(r, "Event loop failed: %m");
goto out; goto out;
@ -147,7 +138,5 @@ out:
"STOPPING=1\n" "STOPPING=1\n"
"STATUS=Shutting down..."); "STATUS=Shutting down...");
sd_event_unref(event);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }

View File

@ -219,7 +219,6 @@ static void test_dhcp_hostname_shorten_overlong(void) {
int main(void) { int main(void) {
_cleanup_(manager_freep) Manager *manager = NULL; _cleanup_(manager_freep) Manager *manager = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(udev_unrefp) struct udev *udev = NULL; _cleanup_(udev_unrefp) struct udev *udev = NULL;
_cleanup_(udev_device_unrefp) struct udev_device *loopback = NULL; _cleanup_(udev_device_unrefp) struct udev_device *loopback = NULL;
int r; int r;
@ -229,9 +228,7 @@ int main(void) {
test_address_equality(); test_address_equality();
test_dhcp_hostname_shorten_overlong(); test_dhcp_hostname_shorten_overlong();
assert_se(sd_event_default(&event) >= 0); assert_se(manager_new(&manager) >= 0);
assert_se(manager_new(&manager, event) >= 0);
r = test_load_config(manager); r = test_load_config(manager);
if (r == -EPERM) if (r == -EPERM)