int main (int argc, char **argv) { #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif /* ENABLE_NLS */ gtk_init(&argc, &argv); #if GLIB_CHECK_VERSION (2, 24, 0) g_type_init(); #else if (!g_thread_supported()) g_thread_init(NULL); #endif gphpedit_debug_init (); main_window.prefmg = preferences_manager_new(); /* Start of IPC communication */ if (get_preferences_manager_single_instance_only(main_window.prefmg) && poke_existing_instance (argc - 1, argv + 1)) return 0; main_window_create(); main_window.tempmg = templates_manager_new(); main_window.docmg = document_manager_new_full(argv, argc); gtk_main(); /* it makes sense to install sigterm handler that would call this too */ shutdown_ipc (); return 0; }
void terminate(int sig_num) { int count = 0; int child; int status; fprintf(stderr,"\nparent interrupted\n"); fprintf(stderr,"killing children: "); fflush(stdout); glob_child_dat.curr_child = -2; for (child = 0; child < max_children; child++) if (glob_child_dat.children[child] > 0) { fprintf(stderr,"%d ", glob_child_dat.children[child]); kill(glob_child_dat.children[child], SIGTERM); } fprintf(stderr,"\n"); fflush(stdout); /* wait for all children to terminate */ while ((waitpid(0, &status, WNOHANG) > 0) && (count++ < MAX_WAIT)) usleep(1) ; /* BRUTAL termination in case signals have gone missing */ while (waitpid(0, &status, WNOHANG) > 0) { for (child = 0; child < max_children; child++) if (glob_child_dat.children[child] > 0) { fprintf(stderr,"sigkill %d ", glob_child_dat.children[child]); kill(glob_child_dat.children[child], SIGKILL); } } shutdown_ipc(glob_server); syslog(LOG_INFO, "Parent interrupted - children shutdown.\n"); closelog(); exit(0); }
static void olsr_shutdown(int signo __attribute__ ((unused))) #endif { struct interface *ifn; int exit_value; OLSR_PRINTF(1, "Received signal %d - shutting down\n", (int)signo); #ifdef WIN32 OLSR_PRINTF(1, "Waiting for the scheduler to stop.\n"); olsr_win32_end_request = TRUE; while (!olsr_win32_end_flag) Sleep(100); OLSR_PRINTF(1, "Scheduler stopped.\n"); #endif /* clear all links and send empty hellos/tcs */ olsr_reset_all_links(); /* deactivate fisheye and immediate TCs */ olsr_cnf->lq_fish = 0; for (ifn = ifnet; ifn; ifn = ifn->int_next) { ifn->immediate_send_tc = false; } increase_local_ansn(); /* send first shutdown message burst */ olsr_shutdown_messages(); /* delete all routes */ olsr_delete_all_kernel_routes(); /* send second shutdown message burst */ olsr_shutdown_messages(); /* now try to cleanup the rest of the mess */ olsr_delete_all_tc_entries(); olsr_delete_all_mid_entries(); #ifdef LINUX_NETLINK_ROUTING /* trigger gateway selection */ if (olsr_cnf->smart_gw_active) { olsr_cleanup_gateways(); } /* trigger niit static route cleanup */ if (olsr_cnf->use_niit) { olsr_cleanup_niit_routes(); } /* cleanup lo:olsr interface */ if (olsr_cnf->use_src_ip_routes) { olsr_os_localhost_if(&olsr_cnf->main_addr, false); } #endif olsr_destroy_parser(); OLSR_PRINTF(1, "Closing sockets...\n"); /* front-end IPC socket */ if (olsr_cnf->ipc_connections > 0) { shutdown_ipc(); } /* OLSR sockets */ for (ifn = ifnet; ifn; ifn = ifn->int_next) { close(ifn->olsr_socket); close(ifn->send_socket); #ifdef LINUX_NETLINK_ROUTING if (DEF_RT_NONE != olsr_cnf->rt_table_defaultolsr_pri) { olsr_os_policy_rule(olsr_cnf->ip_version, olsr_cnf->rt_table_default, olsr_cnf->rt_table_defaultolsr_pri, ifn->int_name, false); } #endif } /* Closing plug-ins */ olsr_close_plugins(); /* Reset network settings */ net_os_restore_ifoptions(); /* ioctl socket */ close(olsr_cnf->ioctl_s); #ifdef LINUX_NETLINK_ROUTING if (DEF_RT_NONE != olsr_cnf->rt_table_pri) { olsr_os_policy_rule(olsr_cnf->ip_version, olsr_cnf->rt_table, olsr_cnf->rt_table_pri, NULL, false); } if (DEF_RT_NONE != olsr_cnf->rt_table_tunnel_pri) { olsr_os_policy_rule(olsr_cnf->ip_version, olsr_cnf->rt_table_tunnel, olsr_cnf->rt_table_tunnel_pri, NULL, false); } if (DEF_RT_NONE != olsr_cnf->rt_table_default_pri) { olsr_os_policy_rule(olsr_cnf->ip_version, olsr_cnf->rt_table_default, olsr_cnf->rt_table_default_pri, NULL, false); } close(olsr_cnf->rtnl_s); close (olsr_cnf->rt_monitor_socket); #endif #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __MacOSX__ || defined __NetBSD__ || defined __OpenBSD__ /* routing socket */ close(olsr_cnf->rts); #endif /* Free cookies and memory pools attached. */ OLSR_PRINTF(0, "Free all memory...\n"); olsr_delete_all_cookies(); olsr_syslog(OLSR_LOG_INFO, "%s stopped", olsrd_version); OLSR_PRINTF(1, "\n <<<< %s - terminating >>>>\n http://www.olsr.org\n", olsrd_version); exit_value = olsr_cnf->exit_value; olsrd_free_cnf(olsr_cnf); exit(exit_value); }
void shutdown(int sig) { shutdown_ipc(); exit(sig); }