summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2016-11-13 09:48:56 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2017-03-08 00:15:36 +0100
commiteb05883f3ecd94be017eb7d15181a989f26541ee (patch)
treef3de680c33e3af0f95520eadf8fb0060dc1ee76c
parent*: centralize more into frr_init() (diff)
downloadfrr-eb05883f3ecd94be017eb7d15181a989f26541ee.tar.xz
frr-eb05883f3ecd94be017eb7d15181a989f26541ee.zip
*: add frr_config_fork()
Centralise read_config/daemonize/dryrun/pidfile/vty_serv into libfrr. This also makes multi-instance pid/config handling available as part of the library. It's only wired up in ospfd, but the code is in lib/. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--bgpd/bgp_main.c64
-rwxr-xr-xconfigure.ac22
-rw-r--r--isisd/isis_main.c59
-rw-r--r--ldpd/ldpd.c53
-rw-r--r--lib/libfrr.c133
-rw-r--r--lib/libfrr.h17
-rw-r--r--lib/vty.c8
-rw-r--r--lib/vty.h2
-rw-r--r--nhrpd/nhrp_main.c45
-rw-r--r--ospf6d/ospf6_main.c56
-rw-r--r--ospfd/ospf_main.c95
-rw-r--r--pimd/pim_main.c56
-rw-r--r--pimd/pim_zebra.c5
-rw-r--r--pimd/pim_zebra.h2
-rw-r--r--ripd/rip_main.c62
-rw-r--r--ripngd/ripng_main.c57
-rw-r--r--vtysh/vtysh.c71
-rw-r--r--vtysh/vtysh.h2
-rw-r--r--vtysh/vtysh_main.c6
-rw-r--r--watchfrr/watchfrr.c11
-rw-r--r--zebra/main.c59
-rw-r--r--zebra/test_main.c2
22 files changed, 220 insertions, 667 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index fec7ed44f..00c9576e0 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -62,16 +62,11 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
/* bgpd options, we use GNU getopt library. */
static const struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
{ "bgp_port", required_argument, NULL, 'p'},
{ "listenon", required_argument, NULL, 'l'},
{ "retain", no_argument, NULL, 'r'},
{ "no_kernel", no_argument, NULL, 'n'},
{ "ecmp", required_argument, NULL, 'e'},
- { "dryrun", no_argument, NULL, 'C'},
{ 0 }
};
@@ -103,18 +98,9 @@ static struct quagga_signal_t bgp_signals[] =
},
};
-/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR BGP_DEFAULT_CONFIG;
-
/* Route retain mode flag. */
static int retain_mode = 0;
-/* Manually specified configuration file name. */
-char *config_file = NULL;
-
-/* Process ID saved for use by init system */
-static const char *pid_file = PATH_BGPD_PID;
-
/* privileges */
static zebra_capabilities_t _caps_p [] =
{
@@ -137,6 +123,8 @@ struct zebra_privs_t bgpd_privs =
.cap_num_i = 0,
};
+static struct frr_daemon_info bgpd_di;
+
/* SIGHUP handler. */
void
sighup (void)
@@ -149,7 +137,7 @@ sighup (void)
zlog_info ("bgpd restarting!");
/* Reload config file. */
- vty_read_config (config_file, config_default);
+ vty_read_config (bgpd_di.config_file, config_default);
/* Try to return to normal operation. */
}
@@ -372,8 +360,6 @@ int
main (int argc, char **argv)
{
int opt;
- int daemon_mode = 0;
- int dryrun = 0;
struct thread thread;
int tmp_port;
@@ -381,17 +367,12 @@ main (int argc, char **argv)
char *bgp_address = NULL;
frr_preinit(&bgpd_di, argc, argv);
- frr_opt_add("df:i:z:p:l:rnC", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
+ frr_opt_add("p:l:rn", longopts,
" -p, --bgp_port Set bgp protocol's port number\n"
" -l, --listenon Listen on specified address (implies -n)\n"
" -r, --retain When program terminates, retain added route by bgpd.\n"
" -n, --no_kernel Do not install route to kernel.\n"
- " -e, --ecmp Specify ECMP to use.\n"
- " -C, --dryrun Check configuration for validity and exit\n");
+ " -e, --ecmp Specify ECMP to use.\n");
/* Command line argument treatment. */
while (1)
@@ -405,18 +386,6 @@ main (int argc, char **argv)
{
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
case 'p':
tmp_port = atoi (optarg);
if (tmp_port <= 0 || tmp_port > 0xffff)
@@ -441,9 +410,6 @@ main (int argc, char **argv)
case 'n':
bgp_option_set (BGP_OPT_NO_FIB);
break;
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -461,26 +427,10 @@ main (int argc, char **argv)
/* BGP related initialization. */
bgp_init ();
- /* Parse config file. */
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if(dryrun)
- return(0);
-
- /* Turn into daemon if daemon_mode is set. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("BGPd daemon failed: %s", strerror(errno));
- return (1);
- }
-
-
- /* Process ID file creation. */
- pid_output (pid_file);
+ frr_config_fork ();
/* Make bgp vty socket. */
- frr_vty_serv (BGP_VTYSH_PATH);
+ frr_vty_serv ();
/* Print banner. */
zlog_notice ("BGPd %s starting: vty@%d, bgp@%s:%d", FRR_VERSION,
diff --git a/configure.ac b/configure.ac
index 96d3d3894..e46e44a8b 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1628,30 +1628,8 @@ fi
AC_MSG_RESULT(${frr_statedir})
AC_SUBST(frr_statedir)
-AC_DEFINE_UNQUOTED(PATH_ZEBRA_PID, "$frr_statedir/zebra.pid",zebra PID)
-AC_DEFINE_UNQUOTED(PATH_RIPD_PID, "$frr_statedir/ripd.pid",ripd PID)
-AC_DEFINE_UNQUOTED(PATH_RIPNGD_PID, "$frr_statedir/ripngd.pid",ripngd PID)
-AC_DEFINE_UNQUOTED(PATH_BGPD_PID, "$frr_statedir/bgpd.pid",bgpd PID)
-AC_DEFINE_UNQUOTED(PATH_OSPFD_PID, "$frr_statedir/ospfd.pid",ospfd PID)
-AC_DEFINE_UNQUOTED(PATH_OSPF6D_PID, "$frr_statedir/ospf6d.pid",ospf6d PID)
-AC_DEFINE_UNQUOTED(PATH_LDPD_PID, "$frr_statedir/ldpd.pid",ldpd PID)
AC_DEFINE_UNQUOTED(LDPD_SOCKET, "$frr_statedir/ldpd.sock",ldpd control socket)
-AC_DEFINE_UNQUOTED(PATH_ISISD_PID, "$frr_statedir/isisd.pid",isisd PID)
-AC_DEFINE_UNQUOTED(PATH_PIMD_PID, "$frr_statedir/pimd.pid",pimd PID)
-AC_DEFINE_UNQUOTED(PATH_NHRPD_PID, "$frr_statedir/nhrpd.pid",nhrpd PID)
-AC_DEFINE_UNQUOTED(PATH_WATCHFRR_PID, "$frr_statedir/watchfrr.pid",watchfrr PID)
AC_DEFINE_UNQUOTED(ZEBRA_SERV_PATH, "$frr_statedir/zserv.api",zebra api socket)
-AC_DEFINE_UNQUOTED(ZEBRA_VTYSH_PATH, "$frr_statedir/zebra.vty",zebra vty socket)
-AC_DEFINE_UNQUOTED(RIP_VTYSH_PATH, "$frr_statedir/ripd.vty",rip vty socket)
-AC_DEFINE_UNQUOTED(RIPNG_VTYSH_PATH, "$frr_statedir/ripngd.vty",ripng vty socket)
-AC_DEFINE_UNQUOTED(BGP_VTYSH_PATH, "$frr_statedir/bgpd.vty",bgpd vty socket)
-AC_DEFINE_UNQUOTED(OSPF_VTYSH_PATH, "$frr_statedir/ospfd.vty",ospfd vty socket)
-AC_DEFINE_UNQUOTED(OSPF6_VTYSH_PATH, "$frr_statedir/ospf6d.vty",ospf6d vty socket)
-AC_DEFINE_UNQUOTED(LDP_VTYSH_PATH, "$frr_statedir/ldpd.vty",ldpd vty socket)
-AC_DEFINE_UNQUOTED(ISIS_VTYSH_PATH, "$frr_statedir/isisd.vty",isisd vty socket)
-AC_DEFINE_UNQUOTED(PIM_VTYSH_PATH, "$frr_statedir/pimd.vty",pimd vty socket)
-AC_DEFINE_UNQUOTED(NHRP_VTYSH_PATH, "$frr_statedir/nhrpd.vty",nhrpd vty socket)
-AC_DEFINE_UNQUOTED(WATCHFRR_VTYSH_PATH, "$frr_statedir/watchfrr.vty",watchfrr vty socket)
AC_DEFINE_UNQUOTED(DAEMON_VTY_DIR, "$frr_statedir",daemon vty directory)
dnl autoconf does this, but it does it too late...
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index 268e473fc..49b988b29 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -83,26 +83,12 @@ struct zebra_privs_t isisd_privs = {
/* isisd options */
struct option longopts[] = {
- {"daemon", no_argument, NULL, 'd'},
- {"config_file", required_argument, NULL, 'f'},
- {"pid_file", required_argument, NULL, 'i'},
- {"socket", required_argument, NULL, 'z'},
- {"dryrun", no_argument, NULL, 'C'},
{0}
};
-/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
-char *config_file = NULL;
-
-int daemon_mode = 0;
-
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-const char *pid_file = PATH_ISISD_PID;
-
/* for reload */
char _cwd[MAXPATHLEN];
char _progpath[MAXPATHLEN];
@@ -213,8 +199,6 @@ main (int argc, char **argv, char **envp)
{
int opt;
struct thread thread;
- char *config_file = NULL;
- int dryrun = 0;
/* for reload */
_argc = argc;
@@ -232,12 +216,7 @@ main (int argc, char **argv, char **envp)
snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
frr_preinit (&isisd_di, argc, argv);
- frr_opt_add ("df:i:z:C", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " -C, --dryrun Check configuration for validity and exit\n");
+ frr_opt_add ("", longopts, "");
/* Command line argument treatment. */
while (1)
@@ -251,21 +230,6 @@ main (int argc, char **argv, char **envp)
{
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -294,27 +258,10 @@ main (int argc, char **argv, char **envp)
isis_zebra_init(master);
- /* parse config file */
- /* this is needed three times! because we have interfaces before the areas */
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if (dryrun)
- return(0);
-
- /* demonize */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("ISISd daemon failed: %s", strerror(errno));
- return (1);
- }
-
- /* Process ID file creation. */
- if (pid_file[0] != '\0')
- pid_output (pid_file);
+ frr_config_fork ();
/* Make isis vty socket. */
- frr_vty_serv (ISIS_VTYSH_PATH);
+ frr_vty_serv ();
/* Print banner. */
zlog_notice ("Quagga-ISISd %s starting: vty@%d", FRR_VERSION, isisd_di.vty_port);
diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c
index 4fd40c7bb..f2ed70eda 100644
--- a/ldpd/ldpd.c
+++ b/ldpd/ldpd.c
@@ -90,12 +90,6 @@ static pid_t lde_pid;
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-static const char *pid_file = PATH_LDPD_PID;
-
-/* Configuration filename and directory. */
-static char config_default[] = SYSCONFDIR LDP_DEFAULT_CONFIG;
-
/* ldpd privileges */
static zebra_capabilities_t _caps_p [] =
{
@@ -124,11 +118,6 @@ char ctl_sock_path[MAXPATHLEN] = LDPD_SOCKET;
#define OPTION_CTLSOCK 1001
static struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
{ "ctl_socket", required_argument, NULL, OPTION_CTLSOCK},
{ 0 }
};
@@ -195,12 +184,9 @@ main(int argc, char *argv[])
int pipe_parent2lde[2], pipe_parent2lde_sync[2];
char *ctl_sock_custom_path = NULL;
char *ctl_sock_name;
- int daemon_mode = 0;
const char *user = NULL;
const char *group = NULL;
- char *config_file = NULL;
struct thread thread;
- int dryrun = 0;
ldpd_process = PROC_MAIN;
@@ -209,13 +195,8 @@ main(int argc, char *argv[])
saved_argv0 = (char *)"ldpd";
frr_preinit(&ldpd_di, argc, argv);
- frr_opt_add("df:i:z:CLE", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " --ctl_socket Override ctl socket path\n"
- " -C, --dryrun Check configuration for validity and exit\n");
+ frr_opt_add("LE", longopts,
+ " --ctl_socket Override ctl socket path\n");
while (1) {
int opt;
@@ -228,18 +209,6 @@ main(int argc, char *argv[])
switch (opt) {
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set(optarg);
- break;
case OPTION_CTLSOCK:
ctl_sock_name = strrchr(LDPD_SOCKET, '/');
if (ctl_sock_name)
@@ -259,9 +228,6 @@ main(int argc, char *argv[])
strlcat(ctl_sock_path, ctl_sock_name,
sizeof(ctl_sock_path));
break;
- case 'C':
- dryrun = 1;
- break;
case 'L':
lflag = 1;
break;
@@ -310,19 +276,11 @@ main(int argc, char *argv[])
/* Get configuration file. */
ldpd_conf = config_new_empty();
ldp_config_reset_main(ldpd_conf, NULL);
- vty_read_config(config_file, config_default);
- /* Start execution only if not in dry-run mode */
- if (dryrun)
- exit(0);
+ frr_config_fork();
QOBJ_REG (ldpd_conf, ldpd_conf);
- if (daemon_mode && daemon(0, 0) < 0) {
- log_warn("LDPd daemon failed");
- exit(1);
- }
-
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2ldpe) == -1)
fatal("socketpair");
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
@@ -406,11 +364,8 @@ main(int argc, char *argv[])
if (ldpd_conf->ipv6.flags & F_LDPD_AF_ENABLED)
main_imsg_send_net_sockets(AF_INET6);
- /* Process id file create. */
- pid_output(pid_file);
-
/* Create VTY socket */
- frr_vty_serv(LDP_VTYSH_PATH);
+ frr_vty_serv();
/* Print banner. */
log_notice("LDPd %s starting: vty@%d", FRR_VERSION, ldpd_di.vty_port);
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 216ba787c..ad85c6f89 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -26,6 +26,14 @@
#include "command.h"
#include "version.h"
#include "memory_vty.h"
+#include "zclient.h"
+
+const char frr_sysconfdir[] = SYSCONFDIR;
+const char frr_vtydir[] = DAEMON_VTY_DIR;
+
+char config_default[256];
+static char pidfile_default[256];
+static char vtypath_default[256];
static char comb_optstr[256];
static struct option comb_lo[64];
@@ -52,20 +60,48 @@ static void opt_extend(const struct optspec *os)
#define OPTION_VTYSOCK 1000
static const struct option lo_always[] = {
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, 'v' },
- { "vty_socket", required_argument, NULL, OPTION_VTYSOCK },
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'v' },
+ { "daemon", no_argument, NULL, 'd' },
+ { "vty_socket", required_argument, NULL, OPTION_VTYSOCK },
{ NULL }
};
static const struct optspec os_always = {
- "hv",
+ "hvdi:",
" -h, --help Display this help and exit\n"
" -v, --version Print program version\n"
+ " -d, --daemon Runs in daemon mode\n"
" --vty_socket Override vty socket path\n",
lo_always
};
+static const struct option lo_cfg_pid_dry[] = {
+ { "pid_file", required_argument, NULL, 'i' },
+ { "config_file", required_argument, NULL, 'f' },
+ { "dryrun", no_argument, NULL, 'C' },
+ { NULL }
+};
+static const struct optspec os_cfg_pid_dry = {
+ "f:i:C",
+ " -f, --config_file Set configuration file name\n"
+ " -i, --pid_file Set process identifier file name\n"
+ " -C, --dryrun Check configuration for validity and exit\n",
+ lo_cfg_pid_dry
+};
+
+
+static const struct option lo_zclient[] = {
+ { "socket", required_argument, NULL, 'z' },
+ { NULL }
+};
+static const struct optspec os_zclient = {
+ "z:",
+ " -z, --socket Set path of zebra socket\n",
+ lo_zclient
+};
+
+
static const struct option lo_vty[] = {
{ "vty_addr", required_argument, NULL, 'A'},
{ "vty_port", required_argument, NULL, 'P'},
@@ -105,10 +141,19 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv)
umask(0027);
opt_extend(&os_always);
+ if (!(di->flags & FRR_NO_CFG_PID_DRY))
+ opt_extend(&os_cfg_pid_dry);
if (!(di->flags & FRR_NO_PRIVSEP))
opt_extend(&os_user);
+ if (!(di->flags & FRR_NO_ZCLIENT))
+ opt_extend(&os_zclient);
if (!(di->flags & FRR_NO_TCPVTY))
opt_extend(&os_vty);
+
+ snprintf(config_default, sizeof(config_default), "%s/%s.conf",
+ frr_sysconfdir, di->name);
+ snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s.pid",
+ frr_vtydir, di->name);
}
void frr_opt_add(const char *optstr, const struct option *longopts,
@@ -154,6 +199,29 @@ static int frr_opt(int opt)
print_version(di->progname);
exit(0);
break;
+ case 'd':
+ di->daemon_mode = 1;
+ break;
+ case 'i':
+ if (di->flags & FRR_NO_CFG_PID_DRY)
+ return 1;
+ di->pid_file = optarg;
+ break;
+ case 'f':
+ if (di->flags & FRR_NO_CFG_PID_DRY)
+ return 1;
+ di->config_file = optarg;
+ break;
+ case 'C':
+ if (di->flags & FRR_NO_CFG_PID_DRY)
+ return 1;
+ di->dryrun = 1;
+ break;
+ case 'z':
+ if (di->flags & FRR_NO_ZCLIENT)
+ return 1;
+ zclient_serv_path_set(optarg);
+ break;
case 'A':
if (di->flags & FRR_NO_TCPVTY)
return 1;
@@ -253,18 +321,51 @@ struct thread_master *frr_init(void)
return master;
}
-void frr_vty_serv(const char *path)
+void frr_config_fork(void)
{
- if (di->vty_sock_path) {
- char newpath[MAXPATHLEN];
- const char *name;
- name = strrchr(path, '/');
- name = name ? name + 1 : path;
-
- snprintf(newpath, sizeof(newpath), "%s/%s",
- di->vty_sock_path, name);
- vty_serv_sock(di->vty_addr, di->vty_port, newpath);
- } else
- vty_serv_sock(di->vty_addr, di->vty_port, path);
+ if (di->instance) {
+ snprintf(config_default, sizeof(config_default), "%s/%s-%d.conf",
+ frr_sysconfdir, di->name, di->instance);
+ snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s-%d.pid",
+ frr_vtydir, di->name, di->instance);
+ }
+
+ vty_read_config(di->config_file, config_default);
+
+ /* Don't start execution if we are in dry-run mode */
+ if (di->dryrun)
+ exit(0);
+
+ /* Daemonize. */
+ if (di->daemon_mode && daemon (0, 0) < 0) {
+ zlog_err("Zebra daemon failed: %s", strerror(errno));
+ exit(1);
+ }
+
+ if (!di->pid_file)
+ di->pid_file = pidfile_default;
+ pid_output (di->pid_file);
+}
+
+void frr_vty_serv(void)
+{
+ /* allow explicit override of vty_path in the future
+ * (not currently set anywhere) */
+ if (!di->vty_path) {
+ const char *dir;
+ dir = di->vty_sock_path ? di->vty_sock_path : frr_vtydir;
+
+ if (di->instance)
+ snprintf(vtypath_default, sizeof(vtypath_default),
+ "%s/%s-%d.vty",
+ dir, di->name, di->instance);
+ else
+ snprintf(vtypath_default, sizeof(vtypath_default),
+ "%s/%s.vty", dir, di->name);
+
+ di->vty_path = vtypath_default;
+ }
+
+ vty_serv_sock(di->vty_addr, di->vty_port, di->vty_path);
}
diff --git a/lib/libfrr.h b/lib/libfrr.h
index 97526dde5..e7e209f60 100644
--- a/lib/libfrr.h
+++ b/lib/libfrr.h
@@ -30,17 +30,25 @@
#define FRR_NO_PRIVSEP (1 << 0)
#define FRR_NO_TCPVTY (1 << 1)
#define FRR_LIMITED_CLI (1 << 2)
+#define FRR_NO_CFG_PID_DRY (1 << 3)
+#define FRR_NO_ZCLIENT (1 << 4)
struct frr_daemon_info {
unsigned flags;
const char *progname;
+ const char *name;
zlog_proto_t log_id;
unsigned short instance;
char *vty_addr;
int vty_port;
char *vty_sock_path;
+ bool dryrun;
+ bool daemon_mode;
+ const char *config_file;
+ const char *pid_file;
+ const char *vty_path;
const char *proghelp;
void (*printhelp)(FILE *target);
@@ -63,6 +71,7 @@ struct frr_daemon_info {
*/
#define FRR_DAEMON_INFO(execname, constname, ...) \
static struct frr_daemon_info execname ##_di = { \
+ .name = # execname, \
.log_id = ZLOG_ ## constname, \
__VA_ARGS__ \
};
@@ -76,6 +85,12 @@ extern void frr_help_exit(int status);
extern struct thread_master *frr_init(void);
-extern void frr_vty_serv(const char *path);
+extern void frr_config_fork(void);
+
+extern void frr_vty_serv(void);
+
+extern char config_default[256];
+extern const char frr_sysconfdir[];
+extern const char frr_vtydir[];
#endif /* _ZEBRA_FRR_H */
diff --git a/lib/vty.c b/lib/vty.c
index 3a3265f54..1b4752a05 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2354,7 +2354,7 @@ vty_read_file (FILE *confp)
}
static FILE *
-vty_use_backup_config (char *fullpath)
+vty_use_backup_config (const char *fullpath)
{
char *fullpath_sav, *fullpath_tmp;
FILE *ret = NULL;
@@ -2413,12 +2413,12 @@ out_close_sav:
/* Read up configuration file from file_name. */
void
-vty_read_config (char *config_file,
+vty_read_config (const char *config_file,
char *config_default_dir)
{
char cwd[MAXPATHLEN];
FILE *confp = NULL;
- char *fullpath;
+ const char *fullpath;
char *tmp = NULL;
/* If -f flag specified. */
@@ -2518,7 +2518,7 @@ vty_read_config (char *config_file,
tmp_free_and_out:
if (tmp)
- XFREE (MTYPE_TMP, fullpath);
+ XFREE (MTYPE_TMP, tmp);
}
/* Small utility function which output log to the VTY. */
diff --git a/lib/vty.h b/lib/vty.h
index 72a4f6394..0ac73d95b 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -324,7 +324,7 @@ extern void vty_reset (void);
extern struct vty *vty_new (void);
extern struct vty *vty_stdio (void (*atclose)(void));
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
-extern void vty_read_config (char *, char *);
+extern void vty_read_config (const char *, char *);
extern void vty_time_print (struct vty *, int);
extern void vty_serv_sock (const char *, unsigned short, const char *);
extern void vty_close (struct vty *);
diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c
index 175b3dfbe..e1192205e 100644
--- a/nhrpd/nhrp_main.c
+++ b/nhrpd/nhrp_main.c
@@ -30,17 +30,9 @@ unsigned int debug_flags = 0;
struct thread_master *master;
struct timeval current_time;
-static const char *pid_file = PATH_NHRPD_PID;
-static char config_default[] = SYSCONFDIR NHRP_DEFAULT_CONFIG;
-static char *config_file = NULL;
-static int do_daemonise = 0;
/* nhrpd options. */
struct option longopts[] = {
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
{ 0 }
};
@@ -76,18 +68,6 @@ static void parse_arguments(int argc, char **argv)
switch (opt) {
case 0:
break;
- case 'd':
- do_daemonise = -1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set(optarg);
- break;
default:
frr_help_exit(1);
break;
@@ -117,8 +97,6 @@ static void nhrp_request_stop(void)
/* signal_terminate(); */
zprivs_terminate(&nhrpd_privs);
- debugf(NHRP_DEBUG_COMMON, "Remove pid file.");
- if (pid_file) unlink(pid_file);
debugf(NHRP_DEBUG_COMMON, "Done.");
closezlog(zlog_default);
@@ -148,11 +126,7 @@ int main(int argc, char **argv)
struct thread thread;
frr_preinit(&nhrpd_di, argc, argv);
- frr_opt_add("df:i:z:", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n");
+ frr_opt_add("", longopts, "");
parse_arguments(argc, argv);
@@ -176,23 +150,10 @@ int main(int argc, char **argv)
nhrp_config_init();
- /* Get zebra configuration file. */
- zlog_set_level(NULL, ZLOG_DEST_STDOUT, do_daemonise ? ZLOG_DISABLED : LOG_DEBUG);
- vty_read_config(config_file, config_default);
-
- if (do_daemonise && daemon(0, 0) < 0) {
- zlog_err("daemonise: %s", safe_strerror(errno));
- exit (1);
- }
-
- /* write pid file */
- if (pid_output(pid_file) < 0) {
- zlog_err("error while writing pidfile");
- exit (1);
- }
+ frr_config_fork();
/* Create VTY socket */
- frr_vty_serv(NHRP_VTYSH_PATH);
+ frr_vty_serv();
zlog_notice("nhrpd starting: vty@%d", nhrpd_di.vty_port);
/* Main loop */
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index 6edce7c30..2d5ae02fb 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -81,26 +81,12 @@ struct zebra_privs_t ospf6d_privs =
/* ospf6d options, we use GNU getopt library. */
struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
{ 0 }
};
-/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG;
-
-/* is daemon? */
-int daemon_mode = 0;
-
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-const char *pid_file = PATH_OSPF6D_PID;
-
static void __attribute__ ((noreturn))
ospf6_exit (int status)
{
@@ -205,17 +191,10 @@ int
main (int argc, char *argv[], char *envp[])
{
int opt;
- char *config_file = NULL;
struct thread thread;
- int dryrun = 0;
frr_preinit (&ospf6d_di, argc, argv);
- frr_opt_add ("df:i:z:C", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " -C, --dryrun Check configuration for validity and exit\n");
+ frr_opt_add ("", longopts, "");
/* Command line argument treatment. */
while (1)
@@ -229,21 +208,6 @@ main (int argc, char *argv[], char *envp[])
{
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -267,23 +231,9 @@ main (int argc, char *argv[], char *envp[])
/* initialize ospf6 */
ospf6_init ();
- /* parse config file */
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if (dryrun)
- return(0);
-
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("OSPF6d daemon failed: %s", strerror(errno));
- exit (1);
- }
-
- /* pid file create */
- pid_output (pid_file);
+ frr_config_fork ();
- frr_vty_serv (OSPF6_VTYSH_PATH);
+ frr_vty_serv ();
/* Print start message */
zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 779163464..ee5815832 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -76,18 +76,10 @@ struct zebra_privs_t ospfd_privs =
.cap_num_i = 0
};
-/* Configuration filename and directory. */
-char config_default[100];
-
/* OSPFd options. */
struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
{ "instance", required_argument, NULL, 'n'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
{ "apiserver", no_argument, NULL, 'a'},
{ 0 }
};
@@ -97,9 +89,6 @@ struct option longopts[] =
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-char pid_file[100];
-
#ifdef SUPPORT_OSPF_API
extern int ospf_apiserver_enable;
#endif /* SUPPORT_OSPF_API */
@@ -176,29 +165,18 @@ FRR_DAEMON_INFO(ospfd, OSPF,
int
main (int argc, char **argv)
{
- char vty_path[MAXPATHLEN];
- int daemon_mode = 0;
- char *config_file = NULL;
u_short instance = 0;
struct thread thread;
- int dryrun = 0;
#ifdef SUPPORT_OSPF_API
/* OSPF apiserver is disabled by default. */
ospf_apiserver_enable = 0;
#endif /* SUPPORT_OSPF_API */
- strcpy(pid_file, PATH_OSPFD_PID);
-
frr_preinit (&ospfd_di, argc, argv);
- frr_opt_add ("df:i:n:z:aC", longopts,
- " -d, --daemon Runs in daemon mode\n"
+ frr_opt_add ("n:a", longopts,
" -n, --instance Set the instance id\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " -a. --apiserver Enable OSPF apiserver\n"
- " -C, --dryrun Check configuration for validity and exit\n");
+ " -a. --apiserver Enable OSPF apiserver\n");
while (1)
{
@@ -218,26 +196,11 @@ main (int argc, char **argv)
break;
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- strcpy(pid_file,optarg);
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
#ifdef SUPPORT_OSPF_API
case 'a':
ospf_apiserver_enable = 1;
break;
#endif /* SUPPORT_OSPF_API */
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -292,59 +255,11 @@ main (int argc, char **argv)
exit (1);
}
- /* Get configuration file. */
- if (instance)
- sprintf(config_default, "%sospfd-%d.conf", SYSCONFDIR, instance);
- else
- sprintf(config_default, "%s%s", SYSCONFDIR, OSPF_DEFAULT_CONFIG);
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if (dryrun)
- return(0);
-
- /* Change to the daemon program. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("OSPFd daemon failed: %s", strerror(errno));
- exit (1);
- }
-
- /* Create PID file */
- if (instance)
- {
- char pidfile_temp[100];
-
- /* Override the single file with file including instance
- number in case of multi-instance */
- if (strrchr(pid_file, '/') != NULL)
- /* cut of pid_file at last / char * to get directory */
- *strrchr(pid_file, '/') = '\0';
- else
- /* pid_file contains no directory - should never happen, but deal with it anyway */
- /* throw-away all pid_file and assume it's only the filename */
- pid_file[0] = '\0';
-
- snprintf(pidfile_temp, sizeof(pidfile_temp), "%s/ospfd-%d.pid", pid_file, instance );
- strlcpy(pid_file, pidfile_temp, sizeof(pid_file));
- }
- /* Process id file create. */
- pid_output (pid_file);
-
- /* Create VTY socket */
- strlcpy(vty_path, OSPF_VTYSH_PATH, sizeof(vty_path));
- if (instance)
- {
- char *slash = strrchr(vty_path, '/');
- slash = slash ? slash + 1 : vty_path;
- snprintf(slash, vty_path + sizeof(vty_path) - slash, "ospfd-%d.vty",
- instance);
- }
-
- frr_vty_serv (vty_path);
+ frr_vty_serv ();
/* Print banner. */
- zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION, ospfd_di.vty_port, vty_path);
+ zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION,
+ ospfd_di.vty_port, ospfd_di.vty_path);
/* Fetch next active thread. */
while (thread_fetch (master, &thread))
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
index 9136b08e9..f446e33af 100644
--- a/pimd/pim_main.c
+++ b/pimd/pim_main.c
@@ -50,14 +50,7 @@
extern struct host host;
-char config_default[] = SYSCONFDIR PIMD_DEFAULT_CONFIG;
-
-/* pimd options */
struct option longopts[] = {
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
{ 0 }
};
@@ -85,8 +78,6 @@ struct zebra_privs_t pimd_privs =
.cap_num_i = 0
};
-const char *pid_file = PATH_PIMD_PID;
-
FRR_DAEMON_INFO(pimd, PIM,
.vty_port = PIMD_VTY_PORT,
@@ -99,18 +90,10 @@ FRR_DAEMON_INFO(pimd, PIM,
)
int main(int argc, char** argv, char** envp) {
- int daemon_mode = 0;
- char *config_file = NULL;
- char *zebra_sock_path = NULL;
struct thread thread;
frr_preinit(&pimd_di, argc, argv);
- frr_opt_add("df:i:z:", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- );
+ frr_opt_add("", longopts, "");
/* this while just reads the options */
while (1) {
@@ -124,18 +107,6 @@ int main(int argc, char** argv, char** envp) {
switch (opt) {
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zebra_sock_path = optarg;
- break;
default:
frr_help_exit (1);
break;
@@ -163,30 +134,11 @@ int main(int argc, char** argv, char** envp) {
/*
* Initialize zclient "update" and "lookup" sockets
*/
- pim_zebra_init(zebra_sock_path);
-
- zlog_notice("Loading configuration - begin");
-
- /* Get configuration file. */
- vty_read_config(config_file, config_default);
-
- /*
- Starting from here zlog_* functions will log according configuration
- */
-
- zlog_notice("Loading configuration - end");
-
- /* Change to the daemon program. */
- if (daemon_mode) {
- if (daemon(0, 0)) {
- zlog_warn("failed to daemonize");
- }
- }
+ pim_zebra_init();
- /* Process ID file creation. */
- pid_output(pid_file);
+ frr_config_fork();
- frr_vty_serv (PIM_VTYSH_PATH);
+ frr_vty_serv();
zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
FRR_VERSION, PIMD_VERSION, pimd_di.vty_port);
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index 70b030280..1db6616c5 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -721,13 +721,10 @@ pim_zebra_connected (struct zclient *zclient)
zclient_send_reg_requests (zclient, VRF_DEFAULT);
}
-void pim_zebra_init(char *zebra_sock_path)
+void pim_zebra_init(void)
{
int i;
- if (zebra_sock_path)
- zclient_serv_path_set(zebra_sock_path);
-
#ifdef HAVE_TCP_ZEBRA
zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT);
#else
diff --git a/pimd/pim_zebra.h b/pimd/pim_zebra.h
index 476185def..751a7be25 100644
--- a/pimd/pim_zebra.h
+++ b/pimd/pim_zebra.h
@@ -24,7 +24,7 @@
#include "pim_igmp.h"
#include "pim_ifchannel.h"
-void pim_zebra_init(char *zebra_sock_path);
+void pim_zebra_init(void);
void pim_zebra_zclient_update (struct vty *vty);
void pim_scan_individual_oil (struct channel_oil *c_oil);
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index 2cf88e676..3bbd12835 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -42,11 +42,6 @@
/* ripd options. */
static struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
{ "retain", no_argument, NULL, 'r'},
{ 0 }
};
@@ -74,23 +69,13 @@ struct zebra_privs_t ripd_privs =
.cap_num_i = 0
};
-/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR RIPD_DEFAULT_CONFIG;
-char *config_file = NULL;
-
-/* ripd program name */
-
-/* VTY Socket prefix */
-char vty_sock_path[MAXPATHLEN] = RIP_VTYSH_PATH;
-
/* Route retain mode flag. */
int retain_mode = 0;
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-const char *pid_file = PATH_RIPD_PID;
+static struct frr_daemon_info ripd_di;
/* SIGHUP handler. */
static void
@@ -102,7 +87,7 @@ sighup (void)
zlog_info ("ripd restarting!");
/* Reload config file. */
- vty_read_config (config_file, config_default);
+ vty_read_config (ripd_di.config_file, config_default);
/* Try to return to normal operation. */
}
@@ -161,17 +146,10 @@ FRR_DAEMON_INFO(ripd, RIP,
int
main (int argc, char **argv)
{
- int daemon_mode = 0;
- int dryrun = 0;
struct thread thread;
frr_preinit (&ripd_di, argc, argv);
- frr_opt_add ("df:i:z:rC", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " -C, --dryrun Check configuration for validity and exit\n"
+ frr_opt_add ("r", longopts,
" -r, --retain When program terminates, retain added route by ripd.\n");
/* Command line option parse. */
@@ -188,24 +166,9 @@ main (int argc, char **argv)
{
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
case 'r':
retain_mode = 1;
break;
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -225,25 +188,10 @@ main (int argc, char **argv)
rip_zclient_init(master);
rip_peer_init ();
- /* Get configuration file. */
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if(dryrun)
- return (0);
-
- /* Change to the daemon program. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("RIPd daemon failed: %s", strerror(errno));
- exit (1);
- }
-
- /* Pid file create. */
- pid_output (pid_file);
+ frr_config_fork ();
/* Create VTY's socket */
- frr_vty_serv (RIP_VTYSH_PATH);
+ frr_vty_serv ();
/* Print banner. */
zlog_notice ("RIPd %s starting: vty@%d", FRR_VERSION, ripd_di.vty_port);
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index 79ea91297..e63b1ea29 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -40,18 +40,9 @@
#include "ripngd/ripngd.h"
-/* Configuration filename and directory. */
-char config_default[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG;
-char *config_file = NULL;
-
/* RIPngd options. */
struct option longopts[] =
{
- { "daemon", no_argument, NULL, 'd'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
- { "socket", required_argument, NULL, 'z'},
- { "dryrun", no_argument, NULL, 'C'},
{ "retain", no_argument, NULL, 'r'},
{ 0 }
};
@@ -88,8 +79,7 @@ int retain_mode = 0;
/* Master of threads. */
struct thread_master *master;
-/* Process ID saved for use by init system */
-const char *pid_file = PATH_RIPNGD_PID;
+static struct frr_daemon_info ripngd_di;
/* SIGHUP handler. */
static void
@@ -100,7 +90,7 @@ sighup (void)
ripng_reset ();
/* Reload config file. */
- vty_read_config (config_file, config_default);
+ vty_read_config (ripngd_di.config_file, config_default);
/* Try to return to normal operation. */
}
@@ -159,17 +149,10 @@ FRR_DAEMON_INFO(ripngd, RIPNG,
int
main (int argc, char **argv)
{
- int daemon_mode = 0;
struct thread thread;
- int dryrun = 0;
frr_preinit (&ripngd_di, argc, argv);
- frr_opt_add ("df:i:z:rC", longopts,
- " -d, --daemon Runs in daemon mode\n"
- " -f, --config_file Set configuration file name\n"
- " -i, --pid_file Set process identifier file name\n"
- " -z, --socket Set path of zebra socket\n"
- " -C, --dryrun Check configuration for validity and exit\n"
+ frr_opt_add ("r", longopts,
" -r, --retain When program terminates, retain added route by ripd.\n");
while (1)
@@ -185,24 +168,9 @@ main (int argc, char **argv)
{
case 0:
break;
- case 'd':
- daemon_mode = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
- case 'i':
- pid_file = optarg;
- break;
- case 'z':
- zclient_serv_path_set (optarg);
- break;
case 'r':
retain_mode = 1;
break;
- case 'C':
- dryrun = 1;
- break;
default:
frr_help_exit (1);
break;
@@ -219,25 +187,10 @@ main (int argc, char **argv)
zebra_init(master);
ripng_peer_init ();
- /* Get configuration file. */
- vty_read_config (config_file, config_default);
-
- /* Start execution only if not in dry-run mode */
- if(dryrun)
- return(0);
-
- /* Change to the daemon program. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("RIPNGd daemon failed: %s", strerror(errno));
- exit (1);
- }
+ frr_config_fork ();
/* Create VTY socket */
- frr_vty_serv (RIPNG_VTYSH_PATH);
-
- /* Process id file create. */
- pid_output (pid_file);
+ frr_vty_serv ();
/* Print banner. */
zlog_notice ("RIPNGd %s starting: vty@%d", FRR_VERSION, ripngd_di.vty_port);
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index eb419313e..114022d19 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -43,6 +43,7 @@
#include "bgpd/bgp_vty.h"
#include "ns.h"
#include "vrf.h"
+#include "libfrr.h"
DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
@@ -58,23 +59,23 @@ struct vtysh_client
int fd;
const char *name;
int flag;
- const char *path;
+ char path[MAXPATHLEN];
struct vtysh_client *next;
};
struct vtysh_client vtysh_client[] =
{
- { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .path = LDP_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .path = NHRP_VTYSH_PATH, .next = NULL},
- { .fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .path = WATCHFRR_VTYSH_PATH, .next = NULL},
+ { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .next = NULL},
+ { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .next = NULL},
+ { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .next = NULL},
+ { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .next = NULL},
+ { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .next = NULL},
+ { .fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .next = NULL},
+ { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .next = NULL},
+ { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .next = NULL},
+ { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .next = NULL},
+ { .fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .next = NULL},
+ { .fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .next = NULL},
};
enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED;
@@ -2866,27 +2867,12 @@ vtysh_connect (struct vtysh_client *vclient)
int sock, len;
struct sockaddr_un addr;
struct stat s_stat;
- char path[MAXPATHLEN];
+ const char *path;
- if (vty_sock_path == NULL)
- strlcpy (path, vclient->path, sizeof (path));
- else {
- /* Different path for VTY Socket specified
- overriding the default path, but keep the filename */
- strlcpy (path, vty_sock_path, sizeof (path));
-
- if (strrchr (vclient->path, '/') != NULL)
- strlcat (path, strrchr (vclient->path, '/'), sizeof (path));
- else {
- /*
- * vclient->path configured as relative path during config? Should
- * really never happen for sensible config
- */
- strlcat (path, "/", sizeof (path));
- strlcat (path, vclient->path, sizeof (path));
- }
- }
- path[sizeof(path)-1] = '\0';
+ if (!vclient->path[0])
+ snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
+ vty_sock_path, vclient->name);
+ path = vclient->path;
/* Stat socket to see if we have permission to access it. */
ret = stat (path, &s_stat);
@@ -2981,24 +2967,14 @@ static void
vtysh_update_all_insances(struct vtysh_client * head_client)
{
struct vtysh_client *client;
- char *ptr;
- char vty_dir[MAXPATHLEN];
DIR *dir;
struct dirent *file;
int n = 0;
if (head_client->flag != VTYSH_OSPFD) return;
- if (vty_sock_path == NULL)
- /* ls DAEMON_VTY_DIR and look for all files ending in .vty */
- strlcpy(vty_dir, DAEMON_VTY_DIR "/", MAXPATHLEN);
- else
- {
- /* ls vty_sock_dir and look for all files ending in .vty */
- strlcpy(vty_dir, vty_sock_path, MAXPATHLEN);
- strlcat(vty_dir, "/", MAXPATHLEN);
- }
- dir = opendir(vty_dir);
+ /* ls vty_sock_dir and look for all files ending in .vty */
+ dir = opendir(vty_sock_path);
if (dir)
{
while ((file = readdir(dir)) != NULL)
@@ -3009,16 +2985,15 @@ vtysh_update_all_insances(struct vtysh_client * head_client)
{
fprintf(stderr,
"Parsing %s, client limit(%d) reached!\n",
- vty_dir, n);
+ vty_sock_path, n);
break;
}
client = (struct vtysh_client *) malloc(sizeof(struct vtysh_client));
client->fd = -1;
client->name = "ospfd";
client->flag = VTYSH_OSPFD;
- ptr = (char *) malloc(100);
- sprintf(ptr, "%s%s", vty_dir, file->d_name);
- client->path = (const char *)ptr;
+ snprintf(client->path, sizeof(client->path), "%s/%s",
+ vty_sock_path, file->d_name);
client->next = NULL;
vtysh_client_sorted_insert(head_client, client);
n++;
diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h
index 61774b7d0..07ba8367d 100644
--- a/vtysh/vtysh.h
+++ b/vtysh/vtysh.h
@@ -97,6 +97,6 @@ extern int execute_flag;
extern struct vty *vty;
-extern char * vty_sock_path;
+extern const char * vty_sock_path;
#endif /* VTYSH_H */
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 3dffa05ac..bf62850e2 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -37,6 +37,7 @@
#include "memory.h"
#include "linklist.h"
#include "memory_vty.h"
+#include "libfrr.h"
#include "vtysh/vtysh.h"
#include "vtysh/vtysh_user.h"
@@ -54,7 +55,7 @@ char history_file[MAXPATHLEN];
int execute_flag = 0;
/* VTY Socket prefix */
-char * vty_sock_path = NULL;
+const char * vty_sock_path = NULL;
/* For sigsetjmp() & siglongjmp(). */
static sigjmp_buf jmpbuf;
@@ -402,6 +403,9 @@ main (int argc, char **argv, char **env)
}
}
+ if (!vty_sock_path)
+ vty_sock_path = frr_vtydir;
+
if (markfile + writeconfig + dryrun + boot_flag > 1)
{
fprintf (stderr, "Invalid combination of arguments. Please specify at "
diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c
index a09ec5225..3bf2783ee 100644
--- a/watchfrr/watchfrr.c
+++ b/watchfrr/watchfrr.c
@@ -1022,7 +1022,8 @@ static struct quagga_signal_t watchfrr_signals[] = {
};
FRR_DAEMON_INFO(watchfrr, WATCHFRR,
- .flags = FRR_NO_PRIVSEP | FRR_NO_TCPVTY | FRR_LIMITED_CLI,
+ .flags = FRR_NO_PRIVSEP | FRR_NO_TCPVTY | FRR_LIMITED_CLI
+ | FRR_NO_CFG_PID_DRY | FRR_NO_ZCLIENT,
.printhelp = printhelp,
.copyright = "Copyright 2004 Andrew J. Schorr",
@@ -1036,7 +1037,6 @@ FRR_DAEMON_INFO(watchfrr, WATCHFRR,
int main(int argc, char **argv)
{
int opt;
- int daemon_mode = 0;
const char *pidfile = DEFAULT_PIDFILE;
const char *special = "zebra";
const char *blankstr = NULL;
@@ -1072,9 +1072,6 @@ int main(int argc, char **argv)
case 'b':
blankstr = optarg;
break;
- case 'd':
- daemon_mode = 1;
- break;
case 'e':
gs.do_ping = 0;
break;
@@ -1278,7 +1275,7 @@ int main(int argc, char **argv)
master = frr_init();
zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
- if (daemon_mode) {
+ if (watchfrr_di.daemon_mode) {
zlog_set_level(NULL, ZLOG_DEST_SYSLOG, MIN(gs.loglevel, LOG_DEBUG));
if (daemon (0, 0) < 0) {
fprintf(stderr, "Watchquagga daemon failed: %s",
@@ -1290,7 +1287,7 @@ int main(int argc, char **argv)
watchfrr_vty_init();
- frr_vty_serv(WATCHFRR_VTYSH_PATH);
+ frr_vty_serv();
{
int i;
diff --git a/zebra/main.c b/zebra/main.c
index 92fe5f4e6..3aa40fa92 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -81,16 +81,12 @@ u_int32_t nl_rcvbufsize = 4194304;
struct option longopts[] =
{
{ "batch", no_argument, NULL, 'b'},
- { "daemon", no_argument, NULL, 'd'},
{ "allow_delete", no_argument, NULL, 'a'},
{ "keep_kernel", no_argument, NULL, 'k'},
{ "fpm_format", required_argument, NULL, 'F'},
- { "config_file", required_argument, NULL, 'f'},
- { "pid_file", required_argument, NULL, 'i'},
{ "socket", required_argument, NULL, 'z'},
{ "ecmp", required_argument, NULL, 'e'},
{ "retain", no_argument, NULL, 'r'},
- { "dryrun", no_argument, NULL, 'C'},
#ifdef HAVE_NETLINK
{ "nl-bufsize", required_argument, NULL, 's'},
#endif /* HAVE_NETLINK */
@@ -119,12 +115,6 @@ struct zebra_privs_t zserv_privs =
.cap_num_i = 0
};
-/* Default configuration file path. */
-char config_default[] = SYSCONFDIR DEFAULT_CONFIG_FILE;
-
-/* Process ID saved for use by init system */
-const char *pid_file = PATH_ZEBRA_PID;
-
unsigned int multipath_num = MULTIPATH_NUM;
/* SIGHUP handler. */
@@ -213,6 +203,7 @@ struct quagga_signal_t zebra_signals[] =
FRR_DAEMON_INFO(zebra, ZEBRA,
.vty_port = ZEBRA_VTY_PORT,
+ .flags = FRR_NO_ZCLIENT,
.proghelp = "Daemon which manages kernel routing table management "
"and\nredistribution between different routing protocols.",
@@ -227,30 +218,23 @@ FRR_DAEMON_INFO(zebra, ZEBRA,
int
main (int argc, char **argv)
{
- int dryrun = 0;
- int batch_mode = 0;
- int daemon_mode = 0;
- char *config_file = NULL;
+ // int batch_mode = 0;
struct thread thread;
char *zserv_path = NULL;
char *fpm_format = NULL;
frr_preinit(&zebra_di, argc, argv);
- frr_opt_add("bdakf:F:i:z:rC"
+ frr_opt_add("bakF:z:r"
#ifdef HAVE_NETLINK
"s:"
#endif
, longopts,
"-b, --batch Runs in batch mode\n"
- "-d, --daemon Runs in daemon mode\n"
"-a, --allow_delete Allow other processes to delete Quagga Routes\n"
- "-f, --config_file Set configuration file name\n"
"-F, --fpm_format Set fpm format to 'netlink' or 'protobuf'\n"
- "-i, --pid_file Set process identifier file name\n"
"-z, --socket Set path of zebra socket\n"
"-k, --keep_kernel Don't delete old routes which installed by zebra.\n"
- "-C, --dryrun Check configuration for validity and exit\n"
"-r, --retain When program terminates, retain added route by zebra.\n"
#ifdef HAVE_NETLINK
"-s, --nl-bufsize Set netlink receive buffer size\n"
@@ -269,9 +253,7 @@ main (int argc, char **argv)
case 0:
break;
case 'b':
- batch_mode = 1;
- case 'd':
- daemon_mode = 1;
+ // batch_mode = 1;
break;
case 'a':
allow_delete = 1;
@@ -279,12 +261,6 @@ main (int argc, char **argv)
case 'k':
keep_kernel_mode = 1;
break;
- case 'C':
- dryrun = 1;
- break;
- case 'f':
- config_file = optarg;
- break;
case 'F':
fpm_format = optarg;
break;
@@ -296,9 +272,6 @@ main (int argc, char **argv)
return 1;
}
break;
- case 'i':
- pid_file = optarg;
- break;
case 'z':
zserv_path = optarg;
break;
@@ -365,29 +338,11 @@ main (int argc, char **argv)
* The notifications from kernel will show originating PID equal
* to that after daemon() completes (if ever called).
*/
- vty_read_config (config_file, config_default);
+ frr_config_fork();
- /* Don't start execution if we are in dry-run mode */
- if (dryrun)
- return(0);
-
- /* Clean up rib. */
+ /* Clean up rib -- before fork (?) */
/* rib_weed_tables (); */
- /* Exit when zebra is working in batch mode. */
- if (batch_mode)
- exit (0);
-
- /* Daemonize. */
- if (daemon_mode && daemon (0, 0) < 0)
- {
- zlog_err("Zebra daemon failed: %s", strerror(errno));
- exit (1);
- }
-
- /* Output pid of zebra. */
- pid_output (pid_file);
-
/* After we have successfully acquired the pidfile, we can be sure
* about being the only copy of zebra process, which is submitting
* changes to the FIB.
@@ -405,7 +360,7 @@ main (int argc, char **argv)
/* This must be done only after locking pidfile (bug #403). */
zebra_zserv_socket_init (zserv_path);
- frr_vty_serv (ZEBRA_VTYSH_PATH);
+ frr_vty_serv ();
/* Print banner. */
zlog_notice ("Zebra %s starting: vty@%d", FRR_VERSION, zebra_di.vty_port);
diff --git a/zebra/test_main.c b/zebra/test_main.c
index dea1df169..43149318d 100644
--- a/zebra/test_main.c
+++ b/zebra/test_main.c
@@ -85,7 +85,7 @@ zebra_capabilities_t _caps_p [] =
char config_default[] = SYSCONFDIR DEFAULT_CONFIG_FILE;
/* Process ID saved for use by init system */
-const char *pid_file = PATH_ZEBRA_PID;
+const char *pid_file = "testzebra.pid";
/* Help information display. */
static void