- if(security_init())
- return 1;
-
- if(setup_network_connections())
- cleanup_and_exit(1);
-
- main_loop();
-
- cleanup_and_exit(1);
- return 1;
-}
-
-RETSIGTYPE
-sigterm_handler(int a)
-{
- if(debug_lvl > 0)
- syslog(LOG_NOTICE, "Got TERM signal");
- cleanup_and_exit(0);
-}
-
-RETSIGTYPE
-sigquit_handler(int a)
-{
- if(debug_lvl > 0)
- syslog(LOG_NOTICE, "Got QUIT signal");
- cleanup_and_exit(0);
-}
-
-RETSIGTYPE
-sigsegv_square(int a)
-{
- syslog(LOG_NOTICE, "Got another SEGV signal: not restarting");
- exit(0);
-}
-
-RETSIGTYPE
-sigsegv_handler(int a)
-{
- if(cp_file)
- syslog(LOG_NOTICE, "Got SEGV signal after %s line %d. Trying to re-execute.",
- cp_file, cp_line);
- else
- syslog(LOG_NOTICE, "Got SEGV signal; trying to re-execute.");
-
- signal(SIGSEGV, sigsegv_square);
-
- close_network_connections();
- remove_pid(pidfilename);
- execvp(g_argv[0], g_argv);
-}
-
-RETSIGTYPE
-sighup_handler(int a)
-{
- if(debug_lvl > 0)
- syslog(LOG_NOTICE, "Got HUP signal");
- close_network_connections();
- setup_network_connections();
- /* FIXME: read config-file and re-establish network connections */
-}
-
-RETSIGTYPE
-sigint_handler(int a)
-{
- if(debug_lvl > 0)
- syslog(LOG_NOTICE, "Got INT signal");
- cleanup_and_exit(0);
-}
-
-RETSIGTYPE
-sigusr1_handler(int a)
-{
- dump_conn_list();
-}
-
-RETSIGTYPE
-sigusr2_handler(int a)
-{
- if(debug_lvl > 1)
- syslog(LOG_NOTICE, "Forcing new keys");
- regenerate_keys();
-}
-
-RETSIGTYPE
-sighuh(int a)
-{
- if(cp_file)
- syslog(LOG_NOTICE, "Got unexpected signal (%d) after %s line %d.",
- a, cp_file, cp_line);
- else
- syslog(LOG_NOTICE, "Got unexpected signal (%d).", a);
-}
-
-void
-setup_signals(void)
-{
- int i;
-
- for(i=0;i<32;i++)
- signal(i,sighuh);
-
- if(signal(SIGTERM, SIG_IGN) != SIG_ERR)
- signal(SIGTERM, sigterm_handler);
- if(signal(SIGQUIT, SIG_IGN) != SIG_ERR)
- signal(SIGQUIT, sigquit_handler);
- if(signal(SIGSEGV, SIG_IGN) != SIG_ERR)
- signal(SIGSEGV, sigsegv_handler);
- if(signal(SIGHUP, SIG_IGN) != SIG_ERR)
- signal(SIGHUP, sighup_handler);
- signal(SIGPIPE, SIG_IGN);
- if(signal(SIGINT, SIG_IGN) != SIG_ERR)
- signal(SIGINT, sigint_handler);
- signal(SIGUSR1, sigusr1_handler);
- signal(SIGUSR2, sigusr2_handler);
- signal(SIGCHLD, parent_exit);
-}