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>
29 #include "memory_vty.h"
40 #include "ripd/ripd.h"
43 static struct option longopts
[] =
45 { "daemon", no_argument
, NULL
, 'd'},
46 { "config_file", required_argument
, NULL
, 'f'},
47 { "pid_file", required_argument
, NULL
, 'i'},
48 { "socket", required_argument
, NULL
, 'z'},
49 { "dryrun", no_argument
, NULL
, 'C'},
50 { "retain", no_argument
, NULL
, 'r'},
55 zebra_capabilities_t _caps_p
[] =
61 struct zebra_privs_t ripd_privs
=
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 /* VTY Socket prefix */
84 char vty_sock_path
[MAXPATHLEN
] = RIP_VTYSH_PATH
;
86 /* Route retain mode flag. */
89 /* Master of threads. */
90 struct thread_master
*master
;
92 /* Process ID saved for use by init system */
93 const char *pid_file
= PATH_RIPD_PID
;
99 zlog_info ("SIGHUP received");
102 zlog_info ("ripd restarting!");
104 /* Reload config file. */
105 vty_read_config (config_file
, config_default
);
107 /* Try to return to normal operation. */
110 /* SIGINT handler. */
114 zlog_notice ("Terminating on signal");
122 /* SIGUSR1 handler. */
129 static struct quagga_signal_t ripd_signals
[] =
149 FRR_DAEMON_INFO(ripd
, RIP
,
150 .vty_port
= RIP_VTY_PORT
,
152 .proghelp
= "Implementation of the RIP routing protocol.",
154 .signals
= ripd_signals
,
155 .n_signals
= array_size(ripd_signals
),
157 .privs
= &ripd_privs
,
160 /* Main routine of ripd. */
162 main (int argc
, char **argv
)
166 struct thread thread
;
168 frr_preinit (&ripd_di
, argc
, argv
);
169 frr_opt_add ("df:i:z:rC", longopts
,
170 " -d, --daemon Runs in daemon mode\n"
171 " -f, --config_file Set configuration file name\n"
172 " -i, --pid_file Set process identifier file name\n"
173 " -z, --socket Set path of zebra socket\n"
174 " -C, --dryrun Check configuration for validity and exit\n"
175 " -r, --retain When program terminates, retain added route by ripd.\n");
177 /* Command line option parse. */
182 opt
= frr_getopt (argc
, argv
, NULL
);
195 config_file
= optarg
;
201 zclient_serv_path_set (optarg
);
215 /* Prepare master thread. */
216 master
= frr_init ();
218 /* Library initialization. */
225 /* RIP related initialization. */
228 rip_zclient_init(master
);
231 /* Get configuration file. */
232 vty_read_config (config_file
, config_default
);
234 /* Start execution only if not in dry-run mode */
238 /* Change to the daemon program. */
239 if (daemon_mode
&& daemon (0, 0) < 0)
241 zlog_err("RIPd daemon failed: %s", strerror(errno
));
245 /* Pid file create. */
246 pid_output (pid_file
);
248 /* Create VTY's socket */
249 frr_vty_serv (RIP_VTYSH_PATH
);
252 zlog_notice ("RIPd %s starting: vty@%d", FRR_VERSION
, ripd_di
.vty_port
);
254 /* Execute each thread. */
255 while (thread_fetch (master
, &thread
))
256 thread_call (&thread
);