2 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include <lib/version.h>
36 #include "ripd/ripd.h"
39 static struct option longopts
[] =
41 { "daemon", no_argument
, NULL
, 'd'},
42 { "config_file", required_argument
, NULL
, 'f'},
43 { "pid_file", required_argument
, NULL
, 'i'},
44 { "help", no_argument
, NULL
, 'h'},
45 { "vty_addr", required_argument
, NULL
, 'A'},
46 { "vty_port", required_argument
, NULL
, 'P'},
47 { "retain", no_argument
, NULL
, 'r'},
48 { "user", required_argument
, NULL
, 'u'},
49 { "group", required_argument
, NULL
, 'g'},
50 { "version", no_argument
, NULL
, 'v'},
55 zebra_capabilities_t _caps_p
[] =
61 struct zebra_privs_t ripd_privs
=
63 #if defined(QUAGGA_USER)
66 #if defined QUAGGA_GROUP
67 .group
= QUAGGA_GROUP
,
70 .vty_group
= VTY_GROUP
,
77 /* Configuration file and directory. */
78 char config_default
[] = SYSCONFDIR RIPD_DEFAULT_CONFIG
;
79 char *config_file
= NULL
;
81 /* ripd program name */
83 /* Route retain mode flag. */
86 /* RIP VTY bind address. */
87 char *vty_addr
= NULL
;
89 /* RIP VTY connection port. */
90 int vty_port
= RIP_VTY_PORT
;
92 /* Master of threads. */
93 struct thread_master
*master
;
95 /* Process ID saved for use by init system */
96 const char *pid_file
= PATH_RIPD_PID
;
98 /* Help information display. */
100 usage (char *progname
, int status
)
103 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
106 printf ("Usage : %s [OPTION...]\n\
107 Daemon which manages RIP version 1 and 2.\n\n\
108 -d, --daemon Runs in daemon mode\n\
109 -f, --config_file Set configuration file name\n\
110 -i, --pid_file Set process identifier file name\n\
111 -A, --vty_addr Set vty's bind address\n\
112 -P, --vty_port Set vty's port number\n\
113 -r, --retain When program terminates, retain added route by ripd.\n\
114 -u, --user User to run as\n\
115 -g, --group Group to run as\n\
116 -v, --version Print program version\n\
117 -h, --help Display this help and exit\n\
119 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
125 /* SIGHUP handler. */
129 zlog_info ("SIGHUP received");
132 zlog_info ("ripd restarting!");
134 /* Reload config file. */
135 vty_read_config (config_file
, config_default
);
137 /* Create VTY's socket */
138 vty_serv_sock (vty_addr
, vty_port
, RIP_VTYSH_PATH
);
140 /* Try to return to normal operation. */
143 /* SIGINT handler. */
147 zlog_notice ("Terminating on signal");
155 /* SIGUSR1 handler. */
162 struct quagga_signal_t ripd_signals
[] =
182 /* Main routine of ripd. */
184 main (int argc
, char **argv
)
189 struct thread thread
;
191 /* Set umask before anything for security */
194 /* Get program name. */
195 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
197 /* First of all we need logging init. */
198 zlog_default
= openzlog (progname
, ZLOG_RIP
,
199 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
201 /* Command line option parse. */
206 opt
= getopt_long (argc
, argv
, "df:i:hA:P:u:g:rv", longopts
, 0);
219 config_file
= optarg
;
228 /* Deal with atoi() returning 0 on failure, and ripd not
229 listening on rip port... */
230 if (strcmp(optarg
, "0") == 0)
235 vty_port
= atoi (optarg
);
236 vty_port
= (vty_port
? vty_port
: RIP_VTY_PORT
);
242 ripd_privs
.user
= optarg
;
245 ripd_privs
.group
= optarg
;
248 print_version (progname
);
260 /* Prepare master thread. */
261 master
= thread_master_create ();
263 /* Library initialization. */
264 zprivs_init (&ripd_privs
);
265 signal_init (master
, Q_SIGC(ripd_signals
), ripd_signals
);
271 /* RIP related initialization. */
277 /* Sort all installed commands. */
280 /* Get configuration file. */
281 vty_read_config (config_file
, config_default
);
283 /* Change to the daemon program. */
287 /* Pid file create. */
288 pid_output (pid_file
);
290 /* Create VTY's socket */
291 vty_serv_sock (vty_addr
, vty_port
, RIP_VTYSH_PATH
);
294 zlog_notice ("RIPd %s starting: vty@%d", QUAGGA_VERSION
, vty_port
);
296 /* Execute each thread. */
297 while (thread_fetch (master
, &thread
))
298 thread_call (&thread
);