/* when we catch a signal and want to exit we call this function to do it gracefully */ static void mk_signal_exit() { int i; uint64_t val; /* ignore future signals to properly handle the cleanup */ signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); /* Distribute worker signals to stop working */ val = MK_SCHEDULER_SIGNAL_FREE_ALL; for (i = 0; i < config->workers; i++) { write(sched_list[i].signal_channel, &val, sizeof(val)); } /* Wait for workers to finish */ for (i = 0; i < config->workers; i++) { pthread_join(sched_list[i].tid, NULL); } mk_utils_remove_pid(); mk_plugin_exit_all(); mk_config_free_all(); mk_mem_free(sched_list); mk_clock_exit(); mk_info("Exiting... >:("); exit(EXIT_SUCCESS); }
void mk_exit_all() { int i; int n; uint64_t val; /* Distribute worker signals to stop working */ val = MK_SCHEDULER_SIGNAL_FREE_ALL; for (i = 0; i < mk_config->workers; i++) { n = write(sched_list[i].signal_channel_w, &val, sizeof(val)); if (n < 0) { perror("write"); } } /* Wait for workers to finish */ for (i = 0; i < mk_config->workers; i++) { pthread_join(sched_list[i].tid, NULL); } mk_utils_remove_pid(); mk_plugin_exit_all(); mk_config_free_all(); mk_mem_free(sched_list); mk_clock_exit(); }
/* when we catch a signal and want to exit we call this function to do it gracefully */ static void mk_signal_exit() { /* ignore future signals to properly handle the cleanup */ signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); mk_utils_remove_pid(); mk_plugin_exit_all(); #ifdef SAFE_FREE mk_config_free_all(); #endif mk_info("Exiting... >:("); _exit(EXIT_SUCCESS); }