summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2023-09-19 12:45:07 +0200
committerSander Vrijders <sander@ouroboros.rocks>2023-09-20 18:51:19 +0200
commitcd649633abae9a0fd2bdbcda965ee1dfd4c6fedd (patch)
tree67f2b42f11c41aced65d22c1abf60ad805f956db
parent01df685d0e116a0da43f2a7b19b32e617db4ba3a (diff)
downloadouroboros-cd649633abae9a0fd2bdbcda965ee1dfd4c6fedd.tar.gz
ouroboros-cd649633abae9a0fd2bdbcda965ee1dfd4c6fedd.zip
ipcpd: Register event handler after scheduler start
The event handler was registered before the scheduler was started. Which could in theory cause addition of fds to an uninitialized scheduler. The event handler is now registered after the scheduler is created as part of dt_start. Likewise it now unregisters as part of dt_stop. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--src/ipcpd/unicast/dt.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/ipcpd/unicast/dt.c b/src/ipcpd/unicast/dt.c
index f62b0d5b..af2a6e29 100644
--- a/src/ipcpd/unicast/dt.c
+++ b/src/ipcpd/unicast/dt.c
@@ -596,11 +596,6 @@ int dt_init(struct dt_config cfg)
dt_pci_info.eid_o = dt_pci_info.ecn_o + ECN_LEN;
dt_pci_info.head_size = dt_pci_info.eid_o + dt_pci_info.eid_size;
- if (notifier_reg(handle_event, NULL)) {
- log_err("Failed to register with notifier.");
- goto fail_notifier_reg;
- }
-
if (connmgr_comp_init(COMPID_DT, &info)) {
log_err("Failed to register with connmgr.");
goto fail_connmgr_comp_init;
@@ -680,8 +675,6 @@ int dt_init(struct dt_config cfg)
fail_routing:
connmgr_comp_fini(COMPID_DT);
fail_connmgr_comp_init:
- notifier_unreg(&handle_event);
- fail_notifier_reg:
return -1;
}
@@ -709,8 +702,6 @@ void dt_fini(void)
routing_fini();
connmgr_comp_fini(COMPID_DT);
-
- notifier_unreg(&handle_event);
}
int dt_start(void)
@@ -718,7 +709,12 @@ int dt_start(void)
dt.psched = psched_create(packet_handler, ipcp_flow_read);
if (dt.psched == NULL) {
log_err("Failed to create N-1 packet scheduler.");
- return -1;
+ goto fail_psched;
+ }
+
+ if (notifier_reg(handle_event, NULL)) {
+ log_err("Failed to register with notifier.");
+ goto fail_notifier_reg;
}
if (pthread_create(&dt.listener, NULL, dt_conn_handle, NULL)) {
@@ -728,12 +724,21 @@ int dt_start(void)
}
return 0;
+
+ fail_notifier_reg:
+ psched_destroy(dt.psched);
+ fail_psched:
+ return -1;
+
}
void dt_stop(void)
{
pthread_cancel(dt.listener);
pthread_join(dt.listener, NULL);
+
+ notifier_unreg(&handle_event);
+
psched_destroy(dt.psched);
}