Index: exec/amfsu.c =================================================================== --- exec/amfsu.c (revision 1958) +++ exec/amfsu.c (revision 1959) @@ -117,6 +117,7 @@ #include "util.h" #include "print.h" #include "main.h" +#include "service.h" static int presence_state_all_comps_in_su_are_set (struct amf_su *su, SaAmfPresenceStateT state) @@ -207,7 +208,7 @@ csi_assignment = malloc (sizeof (struct amf_csi_assignment)); if (csi_assignment == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } csi_assignment->next = csi->assigned_csis; @@ -280,7 +281,7 @@ si_assignment = malloc (sizeof (struct amf_si_assignment)); if (si_assignment == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } amf_su_dn_make (su, &si_assignment->name); si_assignment->saAmfSISUHAState = 0; /* undefined confirmed HA state */ Index: exec/service.c =================================================================== --- exec/service.c (revision 1958) +++ exec/service.c (revision 1959) @@ -42,6 +42,8 @@ #include "mainconfig.h" #include "util.h" #include "print.h" +#include "main.h" +#include "ipc.h" struct default_service { char *name; @@ -93,6 +95,10 @@ struct openais_service_handler *ais_service[SERVICE_HANDLER_MAXIMUM_COUNT]; +static struct objdb_iface_ver0 *shutdown_objdb; + +static poll_timer_handle shutdown_handle; + static unsigned int default_services_requested (struct objdb_iface_ver0 *objdb) { unsigned int object_service_handle = 0; @@ -388,3 +394,50 @@ return (0); } + +static pthread_t aisexec_exit_thread; + +static const char *shutdown_strings[128]; + +static void *aisexec_exit (void *arg) +{ + if (shutdown_objdb) { + openais_service_unlink_all (shutdown_objdb); + } + + poll_stop (0); + totempg_finalize (); + openais_ipc_exit (); + + if ((int)arg >= OPENAIS_SHUTDOWN_ERRORCODES_START) { + log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting (reason: %s).\n", shutdown_strings[((int)arg) - OPENAIS_SHUTDOWN_ERRORCODES_START]); + log_flush(); + return NULL; + } + openais_exit_error ((enum e_ais_done)arg); + + /* never reached */ + return NULL; +} + +static void init_shutdown (void *data) +{ + pthread_create (&aisexec_exit_thread, NULL, aisexec_exit, data); +} + +void openais_shutdown (int error_code) +{ + poll_timer_add (aisexec_poll_handle, 500, (void *)error_code, init_shutdown, &shutdown_handle); +} + +void openais_shutdown_objdb_register (struct objdb_iface_ver0 *objdb) +{ + shutdown_objdb = objdb; +} + +void openais_shutdown_errorstring_register ( + int error_code, + const char *error_string) +{ + shutdown_strings[error_code - OPENAIS_SHUTDOWN_ERRORCODES_START] = error_string; +} Index: exec/service.h =================================================================== --- exec/service.h (revision 1958) +++ exec/service.h (revision 1959) @@ -126,4 +126,14 @@ extern struct openais_service_handler *ais_service[]; +extern void openais_shutdown_errorstring_register ( + int error_code, + const char *error_string); + +extern void openais_shutdown (int error_code); + +extern void openais_shutdown_objdb_register (struct objdb_iface_ver0 *objdb); + +#define OPENAIS_SHUTDOWN_ERRORCODES_START 64 + #endif /* SERVICE_H_DEFINED */ Index: exec/ipc.c =================================================================== --- exec/ipc.c (revision 1958) +++ exec/ipc.c (revision 1959) @@ -834,14 +834,14 @@ libais_server_fd = socket (PF_UNIX, SOCK_STREAM, 0); if (libais_server_fd == -1) { log_printf (LOG_LEVEL_ERROR ,"Cannot create libais client connections socket.\n"); - openais_exit_error (AIS_DONE_LIBAIS_SOCKET); + openais_shutdown (AIS_DONE_LIBAIS_SOCKET); }; totemip_nosigpipe (libais_server_fd); res = fcntl (libais_server_fd, F_SETFL, O_NONBLOCK); if (res == -1) { log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on server socket: %s\n", strerror (errno)); - openais_exit_error (AIS_DONE_LIBAIS_SOCKET); + openais_shutdown (AIS_DONE_LIBAIS_SOCKET); } #if !defined(OPENAIS_LINUX) @@ -861,7 +861,7 @@ res = bind (libais_server_fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr)); if (res) { log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno)); - openais_exit_error (AIS_DONE_LIBAIS_BIND); + openais_shutdown (AIS_DONE_LIBAIS_BIND); } listen (libais_server_fd, SERVER_BACKLOG); Index: exec/amfcomp.c =================================================================== --- exec/amfcomp.c (revision 1958) +++ exec/amfcomp.c (revision 1959) @@ -368,7 +368,7 @@ /* * TODO: remove this and handle properly later... */ - openais_exit_error (AIS_DONE_FATAL_ERR); + openais_shutdown (AIS_DONE_FATAL_ERR); } xprintf ("process (%d) finished with %d\n", pid, status); if (clc_command_run_data->completion_callback) { @@ -479,7 +479,7 @@ clc_command_run_data = malloc (sizeof (struct clc_command_run_data)); if (clc_command_run_data == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } clc_command_run_data->comp = comp; clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE; @@ -538,7 +538,7 @@ component_terminate_callback_data = malloc (sizeof (struct component_terminate_callback_data)); if (component_terminate_callback_data == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } component_terminate_callback_data->comp = comp; @@ -600,7 +600,7 @@ log_printf (LOG_LEVEL_DEBUG, "clc_cli_cleanup\n"); clc_command_run_data = malloc (sizeof (struct clc_command_run_data)); if (clc_command_run_data == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } clc_command_run_data->comp = comp; clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP; @@ -667,7 +667,7 @@ struct amf_comp *comp = calloc (1, sizeof (struct amf_comp)); if (comp == NULL) { - openais_exit_error(AIS_DONE_OUT_OF_MEMORY); + openais_shutdown(AIS_DONE_OUT_OF_MEMORY); } comp->next = su->comp_head; su->comp_head = comp; @@ -1052,7 +1052,7 @@ p = malloc(sizeof(struct res_lib_amf_csisetcallback) + char_length_of_csi_attrs); if (p == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } res_lib = (struct res_lib_amf_csisetcallback*)p; Index: exec/ckpt.c =================================================================== --- exec/ckpt.c (revision 1958) +++ exec/ckpt.c (revision 1959) @@ -3813,7 +3813,7 @@ checkpoint = malloc (sizeof (struct checkpoint)); if (checkpoint == 0) { LEAVE(); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } memset (checkpoint, 0, sizeof (struct checkpoint)); @@ -3911,13 +3911,13 @@ checkpoint_section = malloc (sizeof (struct checkpoint_section)); if (checkpoint_section == 0) { LEAVE(); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } section_contents = malloc (req_exec_ckpt_sync_checkpoint_section->section_size); if (section_contents == 0) { free (checkpoint_section); LEAVE(); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } if (req_exec_ckpt_sync_checkpoint_section->id_len) { @@ -3926,7 +3926,7 @@ free (checkpoint_section); free (section_contents); LEAVE(); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } /* Index: exec/amfcluster.c =================================================================== --- exec/amfcluster.c (revision 1958) +++ exec/amfcluster.c (revision 1959) @@ -73,6 +73,7 @@ #include "amf.h" #include "util.h" #include "main.h" +#include "service.h" /** * Determine if all applications are started @@ -173,7 +174,7 @@ struct amf_cluster *cluster = calloc (1, sizeof (struct amf_cluster)); if (cluster == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); + openais_shutdown (AIS_DONE_OUT_OF_MEMORY); } cluster->saAmfClusterStartupTimeout = -1; Index: exec/main.c =================================================================== --- exec/main.c (revision 1958) +++ exec/main.c (revision 1959) @@ -132,52 +132,14 @@ .group_len = 1 }; -static void *aisexec_exit (void *arg) -{ - if(objdb) { - openais_service_unlink_all (objdb); - } - -#ifdef DEBUG_MEMPOOL - int stats_inuse[MEMPOOL_GROUP_SIZE]; - int stats_avail[MEMPOOL_GROUP_SIZE]; - int stats_memoryused[MEMPOOL_GROUP_SIZE]; - int i; - - mempool_getstats (stats_inuse, stats_avail, stats_memoryused); - log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n"); - for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) { - log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n", - i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]); - } -#endif - - log_flush (); - poll_stop (0); - totempg_finalize (); - openais_ipc_exit (); - openais_exit_error (AIS_DONE_EXIT); - - /* never reached */ - return NULL; -} - -pthread_t aisexec_exit_thread; -static void init_shutdown(void *data) -{ - pthread_create (&aisexec_exit_thread, NULL, aisexec_exit, NULL); -} - -static poll_timer_handle shutdown_handle; static void sigquit_handler (int num) { - /* avoid creating threads from within the interrupt context */ - poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle); + openais_shutdown (AIS_DONE_EXIT); } void sigintr_handler (int signum) { - poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle); + openais_shutdown (AIS_DONE_EXIT); } static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */