3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 #include "ripngd/ripngd.h"
37 /* Configuration filename and directory. */
38 char config_current
[] = RIPNG_DEFAULT_CONFIG
;
39 char config_default
[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG
;
42 struct option longopts
[] =
44 { "daemon", no_argument
, NULL
, 'd'},
45 { "config_file", required_argument
, NULL
, 'f'},
46 { "pid_file", required_argument
, NULL
, 'i'},
47 { "log_mode", no_argument
, NULL
, 'l'},
48 { "help", no_argument
, NULL
, 'h'},
49 { "vty_addr", required_argument
, NULL
, 'A'},
50 { "vty_port", required_argument
, NULL
, 'P'},
51 { "retain", no_argument
, NULL
, 'r'},
52 { "version", no_argument
, NULL
, 'v'},
56 /* RIPngd program name */
58 /* Route retain mode flag. */
61 /* Master of threads. */
62 struct thread_master
*master
;
64 /* Process ID saved for use by init system */
65 char *pid_file
= PATH_RIPNGD_PID
;
67 /* Help information display. */
69 usage (char *progname
, int status
)
72 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
75 printf ("Usage : %s [OPTION...]\n\
76 Daemon which manages RIPng.\n\n\
77 -d, --daemon Runs in daemon mode\n\
78 -f, --config_file Set configuration file name\n\
79 -i, --pid_file Set process identifier file name\n\
80 -l. --log_mode Set verbose log mode flag\n\
81 -A, --vty_addr Set vty's bind address\n\
82 -P, --vty_port Set vty's port number\n\
83 -r, --retain When program terminates, retain added route by ripngd.\n\
84 -v, --version Print program version\n\
85 -h, --help Display this help and exit\n\
87 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
96 zlog (NULL
, LOG_INFO
, "SIGHUP received");
103 zlog (NULL
, LOG_INFO
, "Terminating on signal");
111 /* SIGUSR1 handler. */
118 /* Signale wrapper. */
120 signal_set (int signo
, void (*func
)(int))
123 struct sigaction sig
;
124 struct sigaction osig
;
126 sig
.sa_handler
= func
;
127 sigemptyset (&sig
.sa_mask
);
130 sig
.sa_flags
|= SA_RESTART
;
131 #endif /* SA_RESTART */
133 ret
= sigaction (signo
, &sig
, &osig
);
138 return (osig
.sa_handler
);
141 /* Initialization of signal handles. */
145 signal_set (SIGHUP
, sighup
);
146 signal_set (SIGINT
, sigint
);
147 signal_set (SIGTERM
, sigint
);
148 signal_set (SIGPIPE
, SIG_IGN
);
149 signal_set (SIGUSR1
, sigusr1
);
152 /* RIPngd main routine. */
154 main (int argc
, char **argv
)
157 char *vty_addr
= NULL
;
160 char *config_file
= NULL
;
162 struct thread thread
;
164 /* Set umask before anything for security */
167 /* get program name */
168 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
170 zlog_default
= openzlog(progname
, ZLOG_NOLOG
, ZLOG_RIPNG
,
171 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
177 opt
= getopt_long (argc
, argv
, "dlf:hA:P:v", longopts
, 0);
193 config_file
= optarg
;
202 vty_port
= atoi (optarg
);
208 print_version (progname
);
220 master
= thread_master_create ();
232 /* Get configuration file. */
233 vty_read_config (config_file
, config_current
, config_default
);
235 /* Change to the daemon program. */
239 /* Create VTY socket */
240 vty_serv_sock (vty_addr
,
241 vty_port
? vty_port
: RIPNG_VTY_PORT
, RIPNG_VTYSH_PATH
);
243 /* Process id file create. */
244 pid_output (pid_file
);
246 /* Fetch next active thread. */
247 while (thread_fetch (master
, &thread
))
248 thread_call (&thread
);