/********************************************************************** * %FUNCTION: cmd_exit * %ARGUMENTS: * es -- Event selector * fd -- command file descriptor * %RETURNS: * Nothing * %DESCRIPTION: * Tears down tunnels and quits ***********************************************************************/ static void cmd_exit(EventSelector *es, int fd) { cmd_reply(es, fd, "OK Shutting down"); l2tp_tunnel_stop_all("Stopped by system administrator"); l2tp_cleanup(); exit(0); }
static void sighandler(int signum) { static int count = 0; count++; fprintf(stderr, "Caught signal %d times\n", count); if (count < 5) { l2tp_cleanup(); } exit(EXIT_FAILURE); }
static void sigint_handler(int sig) { static int count = 0; count++; fprintf(stderr, "In sigint handler: %d\n", count); if (count < 5) { l2tp_cleanup(); } exit(1); }
int main(int argc, char *argv[]) { EventSelector *es = Event_CreateSelector(); int i; int opt; int do_fork = 1; int debugmask = 0; while((opt = getopt(argc, argv, "d:fh")) != -1) { switch(opt) { case 'h': usage(argc, argv, EXIT_SUCCESS); break; case 'f': do_fork = 0; break; case 'd': sscanf(optarg, "%d", &debugmask); break; default: usage(argc, argv, EXIT_FAILURE); } } l2tp_random_init(); l2tp_tunnel_init(es); l2tp_peer_init(); l2tp_debug_set_bitmask(debugmask); if (l2tp_parse_config_file(es, "/etc/l2tp/l2tp.conf") < 0) { l2tp_die(); } if (!l2tp_network_init(es)) { l2tp_die(); } /* Daemonize */ if (do_fork) { i = fork(); if (i < 0) { perror("fork"); exit(EXIT_FAILURE); } else if (i != 0) { /* Parent */ exit(EXIT_SUCCESS); } setsid(); signal(SIGHUP, SIG_IGN); i = fork(); if (i < 0) { perror("fork"); exit(EXIT_FAILURE); } else if (i != 0) { exit(EXIT_SUCCESS); } chdir("/"); /* Point stdin/stdout/stderr to /dev/null */ for (i=0; i<3; i++) { close(i); } i = open("/dev/null", O_RDWR); if (i >= 0) { dup2(i, 0); dup2(i, 1); dup2(i, 2); if (i > 2) close(i); } } while(1) { i = Event_HandleEvent(es); if (i < 0) { fprintf(stderr, "Event_HandleEvent returned %d\n", i); l2tp_cleanup(); exit(EXIT_FAILURE); } } return 0; }
void l2tp_die(void) { fprintf(stderr, "FATAL: %s\n", errmsg); l2tp_cleanup(); exit(1); }
void l2tp_die(void) { d_fatal("l2tp: FATAL: %s\n", errmsg); l2tp_cleanup(); exit(1); }