diff options
Diffstat (limited to 'src/irmd/reg')
| -rw-r--r-- | src/irmd/reg/reg.c | 99 | ||||
| -rw-r--r-- | src/irmd/reg/reg.h | 53 | ||||
| -rw-r--r-- | src/irmd/reg/tests/reg_test.c | 12 | 
3 files changed, 52 insertions, 112 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; diff --git a/src/irmd/reg/reg.h b/src/irmd/reg/reg.h index e6deb8e4..17dfcc32 100644 --- a/src/irmd/reg/reg.h +++ b/src/irmd/reg/reg.h @@ -43,9 +43,32 @@ int   reg_destroy_flow(int flow_id);  bool  reg_has_flow(int flow_id); -int   reg_create_ipcp(const struct ipcp_info * info); +int   reg_create_proc(const struct proc_info * info); + +/* Use this for all processes, including ipcps */ +int   reg_destroy_proc(pid_t pid); -int   reg_destroy_ipcp(pid_t pid); +bool  reg_has_proc(pid_t pid); + +void  reg_kill_all_proc(int signal); + +pid_t reg_get_dead_proc(void); + +int   reg_create_spawned(pid_t pid); + +bool  reg_has_spawned(pid_t pid); + +void  reg_kill_all_spawned(int signal); + +int   reg_first_spawned(void); + +int   reg_bind_proc(const char * name, +                    pid_t        proc); + +int   reg_unbind_proc(const char * name, +                      pid_t        proc); + +int   reg_create_ipcp(const struct ipcp_info * info);  bool  reg_has_ipcp(pid_t pid); @@ -70,32 +93,6 @@ bool  reg_has_name(const char * name);  /* TODO don't rely on protobuf here */  int   reg_list_names(name_info_msg_t *** names); -int   reg_create_proc(const struct proc_info * info); - -int   reg_destroy_proc(pid_t pid); - -bool  reg_has_proc(pid_t pid); - -void  reg_kill_all_proc(int signal); - -pid_t reg_get_dead_proc(void); - -int   reg_create_spawned(pid_t pid); - -int   reg_destroy_spawned(pid_t pid); - -bool  reg_has_spawned(pid_t pid); - -void  reg_kill_all_spawned(int signal); - -int   reg_first_spawned(void); - -int   reg_bind_proc(const char * name, -                    pid_t        proc); - -int   reg_unbind_proc(const char * name, -                      pid_t        proc); -  int   reg_create_prog(const struct prog_info * info);  int   reg_destroy_prog(const char * name); diff --git a/src/irmd/reg/tests/reg_test.c b/src/irmd/reg/tests/reg_test.c index f840a3e0..c341c297 100644 --- a/src/irmd/reg/tests/reg_test.c +++ b/src/irmd/reg/tests/reg_test.c @@ -538,7 +538,7 @@ static int test_reg_create_ipcp(void)                  goto fail;          } -        if (reg_destroy_ipcp(info.pid) < 0) { +        if (reg_destroy_proc(info.pid) < 0) {                  printf("Failed to destroy ipcp.\n");                  goto fail;          } @@ -605,7 +605,7 @@ static int test_set_layer(void)                  goto fail;          } -        if (reg_destroy_ipcp(info.pid) < 0) { +        if (reg_destroy_proc(info.pid) < 0) {                  printf("Failed to destroy ipcp.\n");                  goto fail;          } @@ -771,7 +771,7 @@ static int test_reg_spawned(void)                  goto fail;          } -        if (reg_destroy_spawned(TEST_PID) < 0) { +        if (reg_destroy_proc(TEST_PID) < 0) {                  printf("Failed to destroy spawned.\n");                  goto fail;          } @@ -1291,7 +1291,7 @@ static int test_wait_ipcp_boot_timeout(void)                  goto fail;          } -        if (reg_destroy_ipcp(info.pid) < 0) { +        if (reg_destroy_proc(info.pid) < 0) {                  printf("Failed to destroy ipcp.\n");                  goto fail;          } @@ -1357,7 +1357,7 @@ static int test_wait_ipcp_boot_fail(void)          pthread_join(thr, NULL); -        if (reg_destroy_ipcp(info.pid) < 0) { +        if (reg_destroy_proc(info.pid) < 0) {                  printf("Failed to destroy ipcp.\n");                  goto fail;          } @@ -1424,7 +1424,7 @@ static int test_wait_ipcp_boot_success(void)                  goto fail;          } -        if (reg_destroy_ipcp(info.pid) < 0) { +        if (reg_destroy_proc(info.pid) < 0) {                  printf("Failed to destroy ipcp.\n");                  goto fail;          } | 
