diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-08-15 22:23:03 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-08-16 08:18:03 +0200 |
commit | 8e4e526f811fb0e1d358f79707d488b619a60e47 (patch) | |
tree | e9cd673554c30568ac30946cf9378dfe045041cc /src | |
parent | c995538b1c6483996c979df62feee3d79acd0e45 (diff) | |
download | ouroboros-8e4e526f811fb0e1d358f79707d488b619a60e47.tar.gz ouroboros-8e4e526f811fb0e1d358f79707d488b619a60e47.zip |
ipcpd: Refactor normal IPCP failure handling
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/normal/main.c | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 325c1285..27fefdb6 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -366,66 +366,39 @@ int main(int argc, char * argv[]) { if (ipcp_init(argc, argv, THIS_TYPE, &normal_ops) < 0) { - ipcp_create_r(getpid(), -1); - exit(EXIT_FAILURE); + log_err("Failed to init IPCP."); + goto fail_init; } if (irm_bind_api(getpid(), ipcpi.name)) { log_err("Failed to bind AP name."); - ipcp_create_r(getpid(), -1); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_bind_api; } if (rib_init()) { log_err("Failed to initialize RIB."); - ipcp_create_r(getpid(), -1); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_rib_init; } if (connmgr_init()) { log_err("Failed to initialize connection manager."); - ipcp_create_r(getpid(), -1); - rib_fini(); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_connmgr_init; } if (enroll_init()) { log_err("Failed to initialize enroll component."); - ipcp_create_r(getpid(), -1); - connmgr_fini(); - rib_fini(); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_enroll_init; } - if (ipcp_boot() < 0) { log_err("Failed to boot IPCP."); - ipcp_create_r(getpid(), -1); - enroll_fini(); - connmgr_fini(); - rib_fini(); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_boot; } if (ipcp_create_r(getpid(), 0)) { log_err("Failed to notify IRMd we are initialized."); ipcp_set_state(IPCP_NULL); - ipcp_shutdown(); - enroll_fini(); - connmgr_fini(); - rib_fini(); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); - exit(EXIT_FAILURE); + goto fail_create_r; } ipcp_shutdown(); @@ -444,4 +417,20 @@ int main(int argc, ipcp_fini(); exit(EXIT_SUCCESS); + + fail_create_r: + ipcp_shutdown(); + fail_boot: + enroll_fini(); + fail_enroll_init: + connmgr_fini(); + fail_connmgr_init: + rib_fini(); + fail_rib_init: + irm_unbind_api(getpid(), ipcpi.name); + fail_bind_api: + ipcp_fini(); + fail_init: + ipcp_create_r(getpid(), -1); + exit(EXIT_FAILURE); } |