diff options
author | Dimitri Staessens <[email protected]> | 2024-02-23 13:27:38 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2024-02-23 16:41:38 +0100 |
commit | b65e5c1d45c8bfc38b3745cb28ac9074b1c1bdc1 (patch) | |
tree | 19aac189a295822ca597b6c923b27becc6249c20 /src/irmd/reg/reg.c | |
parent | b7baa89fbaa04ceb3227d4d43089d8e6a5326b65 (diff) | |
download | ouroboros-b65e5c1d45c8bfc38b3745cb28ac9074b1c1bdc1.tar.gz ouroboros-b65e5c1d45c8bfc38b3745cb28ac9074b1c1bdc1.zip |
irmd: Always use reg_destroy_proc
Destroying a process will now always be done with reg_destroy_proc,
regardless of whether it was an IPCP or spawned. This makes it easier
to keep the registry consistent and avoid races.
Also improves some logs and updates some default settings.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/irmd/reg/reg.c')
-rw-r--r-- | src/irmd/reg/reg.c | 99 |
1 files changed, 21 insertions, 78 deletions
diff --git a/src/irmd/reg/reg.c b/src/irmd/reg/reg.c index 87641f1a..0a0a1786 100644 --- a/src/irmd/reg/reg.c +++ b/src/irmd/reg/reg.c @@ -798,41 +798,6 @@ int reg_create_ipcp(const struct ipcp_info * info) } -int reg_destroy_ipcp(pid_t pid) -{ - struct reg_ipcp * ipcp; - struct pid_entry * entry; - - pthread_mutex_lock(®.mtx); - - ipcp = __reg_get_ipcp(pid); - if (ipcp == NULL) { - log_err("IPCP %d does not exist.", pid); - goto no_ipcp; - } - - list_del(&ipcp->next); - - reg.n_ipcps--; - - entry = __reg_get_spawned(pid); - assert(entry != NULL); - - list_del(&entry->next); - free(entry); - reg.n_spawned--; - - pthread_mutex_unlock(®.mtx); - - reg_ipcp_destroy(ipcp); - - return 0; - - no_ipcp: - pthread_mutex_unlock(®.mtx); - return -1; -} - int reg_update_ipcp(struct ipcp_info * info) { struct reg_ipcp * ipcp; @@ -1134,33 +1099,38 @@ int reg_create_proc(const struct proc_info * info) int reg_destroy_proc(pid_t pid) { - struct reg_proc * proc; + struct reg_proc * proc; + struct pid_entry * spawn; + struct reg_ipcp * ipcp; pthread_mutex_lock(®.mtx); proc = __reg_get_proc(pid); - if (proc == NULL) { - log_err("Process %d does not exist.", pid); - goto no_proc; + if (proc != NULL) { + list_del(&proc->next); + reg.n_procs--; + reg_proc_destroy(proc); + __reg_del_proc_from_names(pid); + __reg_cancel_flows_for_proc(pid); } - __reg_del_proc_from_names(pid); - - list_del(&proc->next); - - reg.n_procs--; + spawn = __reg_get_spawned(pid); + if (spawn != NULL) { + list_del(&spawn->next); + reg.n_spawned--; + free(spawn); + } - __reg_cancel_flows_for_proc(pid); + ipcp = __reg_get_ipcp(pid); + if (ipcp != NULL) { + list_del(&ipcp->next); + reg.n_ipcps--; + reg_ipcp_destroy(ipcp); + } pthread_mutex_unlock(®.mtx); - reg_proc_destroy(proc); - return 0; - - no_proc: - pthread_mutex_unlock(®.mtx); - return -1; } bool reg_has_proc(pid_t pid) @@ -1229,33 +1199,6 @@ int reg_create_spawned(pid_t pid) return -1; } -int reg_destroy_spawned(pid_t pid) -{ - struct pid_entry * entry; - - pthread_mutex_lock(®.mtx); - - entry = __reg_get_spawned(pid); - if (entry == NULL) { - log_err("Spawned process %d does not exist.", pid); - goto no_proc; - } - - list_del(&entry->next); - - reg.n_spawned--; - - pthread_mutex_unlock(®.mtx); - - free(entry); - - return 0; - - no_proc: - pthread_mutex_unlock(®.mtx); - return -1; -} - bool reg_has_spawned(pid_t pid) { bool ret; |