/* Execute external script/program */ int notify_exec(char *cmd) { pid_t pid; int ret; pid = fork(); /* In case of fork is error. */ if (pid < 0) { log_message(LOG_INFO, "Failed fork process"); return -1; } /* In case of this is parent process */ if (pid) return 0; signal_handler_destroy(); closeall(0); open("/dev/null", O_RDWR); ret = dup(0); ret = dup(0); system_call(cmd); exit(0); }
void obs_shutdown(void) { if (!obs) return; da_free(obs->input_types); da_free(obs->filter_types); da_free(obs->encoder_types); da_free(obs->transition_types); da_free(obs->output_types); da_free(obs->service_types); da_free(obs->modal_ui_callbacks); da_free(obs->modeless_ui_callbacks); stop_video(); obs_free_data(); obs_free_video(); obs_free_graphics(); obs_free_audio(); proc_handler_destroy(obs->procs); signal_handler_destroy(obs->signals); for (size_t i = 0; i < obs->modules.num; i++) free_module(obs->modules.array+i); da_free(obs->modules); bfree(obs->locale); bfree(obs); obs = NULL; }
/* Daemon stop sequence */ static void stop_check(void) { /* Destroy master thread */ signal_handler_destroy(); thread_destroy_master(master); free_checkers_queue(); free_ssl(); if (!(debug & 16)) clear_services(); ipvs_stop(); /* Stop daemon */ pidfile_rm(checkers_pidfile); /* Clean data */ free_global_data(data); free_check_data(check_data); #ifdef _WITH_VRRP_ free_interface_queue(); #endif #ifdef _DEBUG_ keepalived_free_final("Healthcheck child process"); #endif /* * Reached when terminate signal catched. * finally return to parent process. */ closelog(); exit(0); }
void obs_shutdown(void) { size_t i; if (!obs) return; da_free(obs->input_types); da_free(obs->filter_types); da_free(obs->transition_types); da_free(obs->output_types); da_free(obs->service_types); obs_free_data(); obs_free_video(); obs_free_graphics(); obs_free_audio(); media_close(obs->media); proc_handler_destroy(obs->procs); signal_handler_destroy(obs->signals); for (i = 0; i < obs->modules.num; i++) free_module(obs->modules.array+i); da_free(obs->modules); bfree(obs); obs = NULL; }
void obs_output_destroy(obs_output_t output) { if (output) { if (output->valid) { if (output->info.active) { if (output->info.active(output->data)) output->info.stop(output->data); } pthread_mutex_lock(&obs->data.outputs_mutex); da_erase_item(obs->data.outputs, &output); pthread_mutex_unlock(&obs->data.outputs_mutex); } if (output->data) output->info.destroy(output->data); signal_handler_destroy(output->signals); proc_handler_destroy(output->procs); obs_data_release(output->settings); bfree(output->name); bfree(output); } }
void obs_fader_destroy(obs_fader_t *fader) { if (!fader) return; obs_fader_detach_source(fader); signal_handler_destroy(fader->signals); pthread_mutex_destroy(&fader->mutex); bfree(fader); }
/* Daemon stop sequence */ static void stop_vrrp(void) { signal_handler_destroy(); if (!(debug & 8)) shutdown_vrrp_instances(); /* Clear static entries */ netlink_rtlist(vrrp_data->static_routes, IPROUTE_DEL); netlink_iplist(vrrp_data->static_addresses, IPADDRESS_DEL, NULL); #ifdef _WITH_SNMP_ if (snmp) vrrp_snmp_agent_close(); #endif /* Stop daemon */ pidfile_rm(vrrp_pidfile); #ifdef _WITH_LVS_ if (vrrp_ipvs_needed()) { /* Clean ipvs related */ ipvs_stop(); } #endif /* Clean data */ free_global_data(global_data); vrrp_dispatcher_release(vrrp_data); free_vrrp_data(vrrp_data); free_vrrp_buffer(); free_interface_queue(); kernel_netlink_close(); thread_destroy_master(master); gratuitous_arp_close(); ndisc_close(); #ifdef _DEBUG_ keepalived_free_final("VRRP Child process"); #endif /* * Reached when terminate signal catched. * finally return to parent process. */ closelog(); exit(0); }
void obs_context_data_free(struct obs_context_data *context) { signal_handler_destroy(context->signals); proc_handler_destroy(context->procs); obs_data_release(context->settings); obs_context_data_remove(context); pthread_mutex_destroy(&context->rename_cache_mutex); bfree(context->name); for (size_t i = 0; i < context->rename_cache.num; i++) bfree(context->rename_cache.array[i]); da_free(context->rename_cache); memset(context, 0, sizeof(*context)); }
/* Reload thread */ int reload_vrrp_thread(thread_t * thread) { /* set the reloading flag */ SET_RELOAD; /* Signal handling */ signal_reset(); signal_handler_destroy(); /* Destroy master thread */ vrrp_dispatcher_release(vrrp_data); kernel_netlink_close(); thread_destroy_master(master); master = thread_make_master(); free_global_data(global_data); free_interface_queue(); free_vrrp_buffer(); gratuitous_arp_close(); ndisc_close(); #ifdef _WITH_LVS_ if (vrrp_ipvs_needed()) { /* Clean ipvs related */ ipvs_stop(); } #endif /* Save previous conf data */ old_vrrp_data = vrrp_data; vrrp_data = NULL; /* Reload the conf */ mem_allocated = 0; vrrp_signal_init(); signal_set(SIGCHLD, thread_child_handler, master); start_vrrp(); /* free backup data */ free_vrrp_data(old_vrrp_data); UNSET_RELOAD; return 0; }
/* Daemon stop sequence */ static void stop_check(int status) { /* Destroy master thread */ signal_handler_destroy(); thread_destroy_master(master); free_checkers_queue(); free_ssl(); if (!__test_bit(DONT_RELEASE_IPVS_BIT, &debug)) clear_services(); ipvs_stop(); #ifdef _WITH_SNMP_CHECKER_ if (global_data->enable_snmp_checker) check_snmp_agent_close(); #endif /* Stop daemon */ pidfile_rm(checkers_pidfile); /* Clean data */ free_global_data(global_data); free_check_data(check_data); #ifdef _WITH_VRRP_ free_interface_queue(); #endif free_parent_mallocs_exit(); /* * Reached when terminate signal catched. * finally return to parent process. */ log_message(LOG_INFO, "Stopped"); closelog(); #ifndef _MEM_CHECK_LOG_ FREE_PTR(check_syslog_ident); #else if (check_syslog_ident) free(check_syslog_ident); #endif exit(status); }
/* Daemon stop sequence */ static void stop_vrrp(void) { /* Destroy master thread */ signal_handler_destroy(); free_vrrp_sockpool(vrrp_data); thread_destroy_master(master); /* Clear static entries */ netlink_rtlist_ipv4(vrrp_data->static_routes, IPROUTE_DEL); netlink_iplist_ipv4(-1, vrrp_data->static_addresses, IPADDRESS_DEL); if (!(debug & 8)) shutdown_vrrp_instances(); free_interface_queue(); gratuitous_arp_close(); ndisc_close(); vrrp_trackip_close(); /* Stop daemon */ pidfile_rm(vrrp_pidfile); /* Clean data */ free_global_data(data); free_vrrp_data(vrrp_data); free_vrrp_buffer(); #ifdef _WITH_LVS_ /* Clean ipvs related */ //ipvs_stop(); #endif #ifdef _DEBUG_ keepalived_free_final("VRRP Child process"); #endif /* * Reached when terminate signal catched. * finally return to parent process. */ closelog(); exit(0); }
/* Daemon stop sequence */ static void stop_keepalived(void) { /* Just cleanup memory & exit */ signal_handler_destroy(); thread_destroy_master(master); pidfile_rm(main_pidfile); if (__test_bit(DAEMON_VRRP, &daemon_mode)) pidfile_rm(vrrp_pidfile); if (__test_bit(DAEMON_CHECKERS, &daemon_mode)) pidfile_rm(checkers_pidfile); #ifdef _DEBUG_ keepalived_free_final("Parent process"); #endif }
/* Daemon stop sequence */ static void stop_keepalived(void) { log_message(LOG_INFO, "Stopping " VERSION_STRING); /* Just cleanup memory & exit */ signal_handler_destroy(); thread_destroy_master(master); pidfile_rm(main_pidfile); if (daemon_mode & 1 || !daemon_mode) pidfile_rm(vrrp_pidfile); if (daemon_mode & 2 || !daemon_mode) pidfile_rm(checkers_pidfile); #ifdef _DEBUG_ keepalived_free_final("Parent process"); #endif }
void obs_shutdown(void) { struct obs_module *module; if (!obs) return; da_free(obs->input_types); da_free(obs->filter_types); da_free(obs->encoder_types); da_free(obs->transition_types); da_free(obs->output_types); da_free(obs->service_types); da_free(obs->modal_ui_callbacks); da_free(obs->modeless_ui_callbacks); stop_video(); obs_free_data(); obs_free_video(); obs_free_graphics(); obs_free_audio(); proc_handler_destroy(obs->procs); signal_handler_destroy(obs->signals); module = obs->first_module; while (module) { struct obs_module *next = module->next; free_module(module); module = next; } obs->first_module = NULL; for (size_t i = 0; i < obs->module_paths.num; i++) free_module_path(obs->module_paths.array+i); da_free(obs->module_paths); bfree(obs->locale); bfree(obs); obs = NULL; }
static void obs_source_destroy(obs_source_t source) { size_t i; obs_source_dosignal(source, "source-destroy"); if (source->filter_parent) obs_source_filter_remove(source->filter_parent, source); for (i = 0; i < source->filters.num; i++) obs_source_release(source->filters.array[i]); for (i = 0; i < source->audio_wait_buffer.num; i++) audiobuf_free(source->audio_wait_buffer.array+i); for (i = 0; i < source->video_frames.num; i++) source_frame_destroy(source->video_frames.array[i]); gs_entercontext(obs->video.graphics); texture_destroy(source->output_texture); gs_leavecontext(); if (source->data) source->callbacks.destroy(source->data); bfree(source->audio_data.data); audio_line_destroy(source->audio_line); audio_resampler_destroy(source->resampler); proc_handler_destroy(source->procs); signal_handler_destroy(source->signals); da_free(source->video_frames); da_free(source->audio_wait_buffer); da_free(source->filters); pthread_mutex_destroy(&source->filter_mutex); pthread_mutex_destroy(&source->audio_mutex); pthread_mutex_destroy(&source->video_mutex); dstr_free(&source->settings); bfree(source->name); bfree(source); }
/* Daemon stop sequence */ static void stop_keepalived(void) { #ifndef _DEBUG_ /* Just cleanup memory & exit */ signal_handler_destroy(); thread_destroy_master(master); #ifdef _WITH_VRRP_ if (__test_bit(DAEMON_VRRP, &daemon_mode)) pidfile_rm(vrrp_pidfile); #endif #ifdef _WITH_LVS_ if (__test_bit(DAEMON_CHECKERS, &daemon_mode)) pidfile_rm(checkers_pidfile); #endif pidfile_rm(main_pidfile); #endif }
/* Reload thread */ int reload_check_thread(thread_t * thread) { /* set the reloading flag */ SET_RELOAD; log_message(LOG_INFO, "Got SIGHUP, reloading checker configuration"); /* Signals handling */ signal_reset(); signal_handler_destroy(); /* Destroy master thread */ thread_destroy_master(master); master = thread_make_master(); free_global_data(global_data); free_checkers_queue(); #ifdef _WITH_VRRP_ free_interface_queue(); #endif free_ssl(); ipvs_stop(); /* Save previous conf data */ old_check_data = check_data; check_data = NULL; /* Reload the conf */ mem_allocated = 0; check_signal_init(); signal_set(SIGCHLD, thread_child_handler, master); start_check(); /* free backup data */ free_check_data(old_check_data); UNSET_RELOAD; return 0; }
/* Daemon stop sequence */ static void stop_check(void) { /* Destroy master thread */ signal_handler_destroy(); thread_destroy_master(master); free_checkers_queue(); free_ssl(); if (!__test_bit(DONT_RELEASE_IPVS_BIT, &debug)) clear_services(); ipvs_stop(); #ifdef _WITH_SNMP_CHECKER_ if (global_data->enable_snmp_checker) check_snmp_agent_close(); #endif /* Stop daemon */ pidfile_rm(checkers_pidfile); /* Clean data */ free_global_data(global_data); free_check_data(check_data); #ifdef _WITH_VRRP_ free_interface_queue(); #endif #ifdef _MEM_CHECK_ keepalived_free_final("Healthcheck child process"); #endif /* * Reached when terminate signal catched. * finally return to parent process. */ log_message(LOG_INFO, "Stopped"); closelog(); exit(0); }
int misc_check_thread(thread * thread_obj) { checker *checker_obj; misc_checker *misc_chk; int status, ret; pid_t pid; checker_obj = THREAD_ARG(thread_obj); misc_chk = CHECKER_ARG(checker_obj); /* * Register a new checker thread & return * if checker is disabled */ if (!CHECKER_ENABLED(checker_obj)) { /* Register next timer checker */ thread_add_timer(thread_obj->master, misc_check_thread, checker_obj, checker_obj->vs->delay_loop); return 0; } /* Register next timer checker */ thread_add_timer(thread_obj->master, misc_check_thread, checker_obj, checker_obj->vs->delay_loop); /* Daemonization to not degrade our scheduling timer */ pid = fork(); /* In case of fork is error. */ if (pid < 0) { log_message(LOG_INFO, "Failed fork process"); return -1; } /* In case of this is parent process */ if (pid) { long timeout; timeout = (misc_chk->timeout) ? misc_chk->timeout : checker_obj->vs->delay_loop; thread_add_child(thread_obj->master, misc_check_child_thread, checker_obj, pid, timeout); return 0; } /* Child part */ signal_handler_destroy(); closeall(0); open("/dev/null", O_RDWR); ret = dup(0); ret = dup(0); status = system_call(misc_chk->path); if (status < 0 || !WIFEXITED(status)) status = 0; /* Script errors aren't server errors */ else status = WEXITSTATUS(status); exit(status); }
/* Register CHECK thread */ int start_check_child(void) { #ifndef _DEBUG_ pid_t pid; int ret; char *syslog_ident; /* Initialize child process */ pid = fork(); if (pid < 0) { log_message(LOG_INFO, "Healthcheck child process: fork error(%s)" , strerror(errno)); return -1; } else if (pid) { checkers_child = pid; log_message(LOG_INFO, "Starting Healthcheck child process, pid=%d" , pid); /* Start respawning thread */ thread_add_child(master, check_respawn_thread, NULL, pid, RESPAWN_TIMER); return 0; } if ((instance_name #if HAVE_DECL_CLONE_NEWNET || network_namespace #endif ) && (check_syslog_ident = make_syslog_ident(PROG_CHECK))) syslog_ident = check_syslog_ident; else syslog_ident = PROG_CHECK; /* Opening local CHECK syslog channel */ openlog(syslog_ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0) , (log_facility==LOG_DAEMON) ? LOG_LOCAL2 : log_facility); #ifdef _MEM_CHECK_ mem_log_init(PROG_CHECK, "Healthcheck child process"); #endif free_parent_mallocs_startup(true); /* Child process part, write pidfile */ if (!pidfile_write(checkers_pidfile, getpid())) { log_message(LOG_INFO, "Healthcheck child process: cannot write pidfile"); exit(KEEPALIVED_EXIT_FATAL); } /* Create the new master thread */ signal_handler_destroy(); thread_destroy_master(master); /* This destroys any residual settings from the parent */ master = thread_make_master(); /* change to / dir */ ret = chdir("/"); if (ret < 0) { log_message(LOG_INFO, "Healthcheck child process: error chdir"); } /* Set mask */ umask(0); #endif /* If last process died during a reload, we can get there and we * don't want to loop again, because we're not reloading anymore. */ UNSET_RELOAD; /* Signal handling initialization */ check_signal_init(); /* Start Healthcheck daemon */ start_check(); /* Launch the scheduling I/O multiplexer */ launch_scheduler(); /* Finish healthchecker daemon process */ stop_check(EXIT_SUCCESS); /* unreachable */ exit(EXIT_SUCCESS); }
/* Daemon stop sequence */ static void stop_vrrp(void) { /* Ensure any interfaces are in backup mode, * sending a priority 0 vrrp message */ restore_vrrp_interfaces(); #ifdef _HAVE_LIBIPTC_ iptables_fini(); #endif /* Clear static entries */ netlink_rtlist(vrrp_data->static_routes, IPROUTE_DEL); netlink_rulelist(vrrp_data->static_rules, IPRULE_DEL); netlink_iplist(vrrp_data->static_addresses, IPADDRESS_DEL); #ifdef _WITH_SNMP_ if (global_data->enable_snmp_keepalived || global_data->enable_snmp_rfc) vrrp_snmp_agent_close(); #endif /* Stop daemon */ pidfile_rm(vrrp_pidfile); #ifdef _WITH_LVS_ if (vrrp_ipvs_needed()) { /* Clean ipvs related */ ipvs_stop(); } #endif /* Clean data */ free_global_data(global_data); vrrp_dispatcher_release(vrrp_data); /* This is not nice, but it significantly increases the chances * of an IGMP leave group being sent for some reason. * Since we are about to exit, it doesn't affect anything else * running. */ sleep ( 1 ); if (!__test_bit(DONT_RELEASE_VRRP_BIT, &debug)) shutdown_vrrp_instances(); free_vrrp_data(vrrp_data); free_vrrp_buffer(); free_interface_queue(); kernel_netlink_close(); thread_destroy_master(master); gratuitous_arp_close(); ndisc_close(); signal_handler_destroy(); #ifdef _DEBUG_ keepalived_free_final("VRRP Child process"); #endif /* * Reached when terminate signal catched. * finally return to parent process. */ closelog(); exit(0); }
/* Register VRRP thread */ int start_vrrp_child(void) { #ifndef _DEBUG_ pid_t pid; int ret; /* Initialize child process */ pid = fork(); if (pid < 0) { log_message(LOG_INFO, "VRRP child process: fork error(%s)" , strerror(errno)); return -1; } else if (pid) { vrrp_child = pid; log_message(LOG_INFO, "Starting VRRP child process, pid=%d" , pid); /* Start respawning thread */ thread_add_child(master, vrrp_respawn_thread, NULL, pid, RESPAWN_TIMER); return 0; } signal_handler_destroy(); /* Opening local VRRP syslog channel */ openlog(PROG_VRRP, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0) , (log_facility==LOG_DAEMON) ? LOG_LOCAL1 : log_facility); /* Child process part, write pidfile */ if (!pidfile_write(vrrp_pidfile, getpid())) { /* Fatal error */ log_message(LOG_INFO, "VRRP child process: cannot write pidfile"); exit(0); } /* Create the new master thread */ thread_destroy_master(master); master = thread_make_master(); /* change to / dir */ ret = chdir("/"); if (ret < 0) { log_message(LOG_INFO, "VRRP child process: error chdir"); } /* Set mask */ umask(0); #endif /* If last process died during a reload, we can get there and we * don't want to loop again, because we're not reloading anymore. */ UNSET_RELOAD; /* Signal handling initialization */ vrrp_signal_init(); /* Start VRRP daemon */ start_vrrp(); /* Launch the scheduling I/O multiplexer */ launch_scheduler(); /* Finish VRRP daemon process */ stop_vrrp(); exit(0); }