2 * libfrr overall management functions
4 * Copyright (C) 2016 David Lamparter for NetDEF, Inc.
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
33 #include "memory_vty.h"
38 #include "lib_errors.h"
40 #include "northbound_cli.h"
41 #include "northbound_db.h"
44 DEFINE_HOOK(frr_late_init
, (struct thread_master
* tm
), (tm
))
45 DEFINE_KOOH(frr_early_fini
, (), ())
46 DEFINE_KOOH(frr_fini
, (), ())
48 const char frr_sysconfdir
[] = SYSCONFDIR
;
49 const char frr_vtydir
[] = DAEMON_VTY_DIR
;
51 const char frr_dbdir
[] = DAEMON_DB_DIR
;
53 const char frr_moduledir
[] = MODULE_PATH
;
55 char frr_protoname
[256] = "NONE";
56 char frr_protonameinst
[256] = "NONE";
58 char config_default
[512];
59 char frr_zclientpath
[256];
60 static char pidfile_default
[512];
62 static char dbfile_default
[512];
64 static char vtypath_default
[256];
66 bool debug_memstats_at_exit
= false;
67 static bool nodetach_term
, nodetach_daemon
;
69 static char comb_optstr
[256];
70 static struct option comb_lo
[64];
71 static struct option
*comb_next_lo
= &comb_lo
[0];
72 static char comb_helpstr
[4096];
77 const struct option
*longopts
;
80 static void opt_extend(const struct optspec
*os
)
82 const struct option
*lo
;
84 strlcat(comb_optstr
, os
->optstr
, sizeof(comb_optstr
));
85 strlcat(comb_helpstr
, os
->helpstr
, sizeof(comb_helpstr
));
86 for (lo
= os
->longopts
; lo
->name
; lo
++)
87 memcpy(comb_next_lo
++, lo
, sizeof(*lo
));
91 #define OPTION_VTYSOCK 1000
92 #define OPTION_MODULEDIR 1002
93 #define OPTION_LOG 1003
94 #define OPTION_LOGLEVEL 1004
95 #define OPTION_TCLI 1005
96 #define OPTION_DB_FILE 1006
98 static const struct option lo_always
[] = {
99 {"help", no_argument
, NULL
, 'h'},
100 {"version", no_argument
, NULL
, 'v'},
101 {"daemon", no_argument
, NULL
, 'd'},
102 {"module", no_argument
, NULL
, 'M'},
103 {"vty_socket", required_argument
, NULL
, OPTION_VTYSOCK
},
104 {"moduledir", required_argument
, NULL
, OPTION_MODULEDIR
},
105 {"log", required_argument
, NULL
, OPTION_LOG
},
106 {"log-level", required_argument
, NULL
, OPTION_LOGLEVEL
},
107 {"tcli", no_argument
, NULL
, OPTION_TCLI
},
109 static const struct optspec os_always
= {
111 " -h, --help Display this help and exit\n"
112 " -v, --version Print program version\n"
113 " -d, --daemon Runs in daemon mode\n"
114 " -M, --module Load specified module\n"
115 " --vty_socket Override vty socket path\n"
116 " --moduledir Override modules directory\n"
117 " --log Set Logging to stdout, syslog, or file:<name>\n"
118 " --log-level Set Logging Level to use, debug, info, warn, etc\n"
119 " --tcli Use transaction-based CLI\n",
123 static const struct option lo_cfg_pid_dry
[] = {
124 {"pid_file", required_argument
, NULL
, 'i'},
125 {"config_file", required_argument
, NULL
, 'f'},
127 {"db_file", required_argument
, NULL
, OPTION_DB_FILE
},
129 {"pathspace", required_argument
, NULL
, 'N'},
130 {"dryrun", no_argument
, NULL
, 'C'},
131 {"terminal", no_argument
, NULL
, 't'},
133 static const struct optspec os_cfg_pid_dry
= {
135 " -f, --config_file Set configuration file name\n"
136 " -i, --pid_file Set process identifier file name\n"
138 " --db_file Set database file name\n"
140 " -N, --pathspace Insert prefix into config & socket paths\n"
141 " -C, --dryrun Check configuration for validity and exit\n"
142 " -t, --terminal Open terminal session on stdio\n"
143 " -d -t Daemonize after terminal session ends\n",
147 static const struct option lo_zclient
[] = {
148 {"socket", required_argument
, NULL
, 'z'},
150 static const struct optspec os_zclient
= {
151 "z:", " -z, --socket Set path of zebra socket\n", lo_zclient
};
154 static const struct option lo_vty
[] = {
155 {"vty_addr", required_argument
, NULL
, 'A'},
156 {"vty_port", required_argument
, NULL
, 'P'},
158 static const struct optspec os_vty
= {
160 " -A, --vty_addr Set vty's bind address\n"
161 " -P, --vty_port Set vty's port number\n",
165 static const struct option lo_user
[] = {{"user", required_argument
, NULL
, 'u'},
166 {"group", required_argument
, NULL
, 'g'},
168 static const struct optspec os_user
= {"u:g:",
169 " -u, --user User to run as\n"
170 " -g, --group Group to run as\n",
174 bool frr_zclient_addr(struct sockaddr_storage
*sa
, socklen_t
*sa_len
,
177 memset(sa
, 0, sizeof(*sa
));
180 path
= ZEBRA_SERV_PATH
;
182 if (!strncmp(path
, ZAPI_TCP_PATHNAME
, strlen(ZAPI_TCP_PATHNAME
))) {
183 /* note: this functionality is disabled at bottom */
185 int port
= ZEBRA_PORT
;
187 struct sockaddr_in
*sin
= NULL
;
188 struct sockaddr_in6
*sin6
= NULL
;
190 path
+= strlen(ZAPI_TCP_PATHNAME
);
210 port
= strtoul(path
, &err
, 10);
221 sin
= (struct sockaddr_in
*)sa
;
222 sin
->sin_port
= htons(port
);
223 sin
->sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
224 *sa_len
= sizeof(struct sockaddr_in
);
225 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
226 sin
->sin_len
= *sa_len
;
230 sin6
= (struct sockaddr_in6
*)sa
;
231 sin6
->sin6_port
= htons(port
);
232 inet_pton(AF_INET6
, "::1", &sin6
->sin6_addr
);
233 *sa_len
= sizeof(struct sockaddr_in6
);
235 sin6
->sin6_len
= *sa_len
;
241 /* force-disable this path, because tcp-zebra is a
242 * SECURITY ISSUE. there are no checks at all against
243 * untrusted users on the local system connecting on TCP
244 * and injecting bogus routing data into the entire routing
247 * The functionality is only left here because it may be
248 * useful during development, in order to be able to get
249 * tcpdump or wireshark watching ZAPI as TCP. If you want
250 * to do that, flip the #if 1 above to #if 0. */
251 memset(sa
, 0, sizeof(*sa
));
255 /* "sun" is a #define on solaris */
256 struct sockaddr_un
*suna
= (struct sockaddr_un
*)sa
;
258 suna
->sun_family
= AF_UNIX
;
259 strlcpy(suna
->sun_path
, path
, sizeof(suna
->sun_path
));
260 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
261 *sa_len
= suna
->sun_len
= SUN_LEN(suna
);
263 *sa_len
= sizeof(suna
->sun_family
) + strlen(suna
->sun_path
);
264 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
266 /* this is left here for future reference; Linux abstract
267 * socket namespace support can be enabled by replacing
268 * above #if 0 with #ifdef GNU_LINUX.
270 * THIS IS A SECURITY ISSUE, the abstract socket namespace
271 * does not have user/group permission control on sockets.
272 * we'd need to implement SCM_CREDENTIALS support first to
273 * check that only proper users can connect to abstract
274 * sockets. (same problem as tcp-zebra, except there is a
275 * fix with SCM_CREDENTIALS. tcp-zebra has no such fix.)
277 if (suna
->sun_path
[0] == '@')
278 suna
->sun_path
[0] = '\0';
284 static struct frr_daemon_info
*di
= NULL
;
286 void frr_preinit(struct frr_daemon_info
*daemon
, int argc
, char **argv
)
290 /* basename(), opencoded. */
291 char *p
= strrchr(argv
[0], '/');
292 di
->progname
= p
? p
+ 1 : argv
[0];
296 opt_extend(&os_always
);
297 if (!(di
->flags
& FRR_NO_CFG_PID_DRY
))
298 opt_extend(&os_cfg_pid_dry
);
299 if (!(di
->flags
& FRR_NO_PRIVSEP
))
300 opt_extend(&os_user
);
301 if (!(di
->flags
& FRR_NO_ZCLIENT
))
302 opt_extend(&os_zclient
);
303 if (!(di
->flags
& FRR_NO_TCPVTY
))
305 if (di
->flags
& FRR_DETACH_LATER
)
306 nodetach_daemon
= true;
308 snprintf(config_default
, sizeof(config_default
), "%s/%s.conf",
309 frr_sysconfdir
, di
->name
);
310 snprintf(pidfile_default
, sizeof(pidfile_default
), "%s/%s.pid",
311 frr_vtydir
, di
->name
);
313 snprintf(dbfile_default
, sizeof(dbfile_default
), "%s/%s.db",
314 frr_dbdir
, di
->name
);
317 strlcpy(frr_protoname
, di
->logname
, sizeof(frr_protoname
));
318 strlcpy(frr_protonameinst
, di
->logname
, sizeof(frr_protonameinst
));
320 strlcpy(frr_zclientpath
, ZEBRA_SERV_PATH
, sizeof(frr_zclientpath
));
322 di
->cli_mode
= FRR_CLI_CLASSIC
;
325 void frr_opt_add(const char *optstr
, const struct option
*longopts
,
328 const struct optspec main_opts
= {optstr
, helpstr
, longopts
};
329 opt_extend(&main_opts
);
332 void frr_help_exit(int status
)
334 FILE *target
= status
? stderr
: stdout
;
337 fprintf(stderr
, "Invalid options.\n\n");
340 di
->printhelp(target
);
342 fprintf(target
, "Usage: %s [OPTION...]\n\n%s%s%s\n\n%s",
343 di
->progname
, di
->proghelp
, di
->copyright
? "\n\n" : "",
344 di
->copyright
? di
->copyright
: "", comb_helpstr
);
345 fprintf(target
, "\nReport bugs to %s\n", FRR_BUG_ADDRESS
);
349 struct option_chain
{
350 struct option_chain
*next
;
354 static struct option_chain
*modules
= NULL
, **modnext
= &modules
;
355 static int errors
= 0;
357 static int frr_opt(int opt
)
359 static int vty_port_set
= 0;
360 static int vty_addr_set
= 0;
361 struct option_chain
*oc
;
369 print_version(di
->progname
);
376 oc
= XMALLOC(MTYPE_TMP
, sizeof(*oc
));
383 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
385 di
->pid_file
= optarg
;
388 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
390 di
->config_file
= optarg
;
393 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
397 "-N/--pathspace option specified more than once!\n");
401 if (strchr(optarg
, '/') || strchr(optarg
, '.')) {
403 "slashes or dots are not permitted in the --pathspace option.\n");
407 di
->pathspace
= optarg
;
411 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
413 di
->db_file
= optarg
;
417 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
422 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
427 if (di
->flags
& FRR_NO_ZCLIENT
)
429 strlcpy(frr_zclientpath
, optarg
, sizeof(frr_zclientpath
));
432 if (di
->flags
& FRR_NO_TCPVTY
)
436 "-A option specified more than once!\n");
441 di
->vty_addr
= optarg
;
444 if (di
->flags
& FRR_NO_TCPVTY
)
448 "-P option specified more than once!\n");
453 di
->vty_port
= strtoul(optarg
, &err
, 0);
454 if (*err
|| !*optarg
) {
456 "invalid port number \"%s\" for -P option\n",
463 if (di
->vty_sock_path
) {
465 "--vty_socket option specified more than once!\n");
469 di
->vty_sock_path
= optarg
;
471 case OPTION_MODULEDIR
:
472 if (di
->module_path
) {
474 "----moduledir option specified more than once!\n");
478 di
->module_path
= optarg
;
481 di
->cli_mode
= FRR_CLI_TRANSACTIONAL
;
484 if (di
->flags
& FRR_NO_PRIVSEP
)
486 di
->privs
->user
= optarg
;
489 if (di
->flags
& FRR_NO_PRIVSEP
)
491 di
->privs
->group
= optarg
;
494 di
->early_logging
= optarg
;
496 case OPTION_LOGLEVEL
:
497 di
->early_loglevel
= optarg
;
505 int frr_getopt(int argc
, char *const argv
[], int *longindex
)
510 comb_next_lo
->name
= NULL
;
513 opt
= getopt_long(argc
, argv
, comb_optstr
, comb_lo
, &lidx
);
518 if (opt
== -1 && errors
)
525 static void frr_mkdir(const char *path
, bool strip
)
530 struct zprivs_ids_t ids
;
533 char *slash
= strrchr(path
, '/');
538 if (plen
> sizeof(buf
) - 1)
540 memcpy(buf
, path
, plen
);
545 /* o+rx (..5) is needed for the frrvty group to work properly;
546 * without it, users in the frrvty group can't access the vty sockets.
549 ret
= mkdir(path
, 0755);
553 /* if EEXIST, return without touching the permissions,
554 * so user-set custom permissions are left in place
559 flog_err(EC_LIB_SYSTEM_CALL
, "failed to mkdir \"%s\": %s", path
,
564 zprivs_get_ids(&ids
);
565 if (chown(path
, ids
.uid_normal
, ids
.gid_normal
))
566 flog_err(EC_LIB_SYSTEM_CALL
, "failed to chown \"%s\": %s", path
,
570 static struct thread_master
*master
;
571 struct thread_master
*frr_init(void)
573 struct option_chain
*oc
;
574 struct frrmod_runtime
*module
;
576 char p_instance
[16] = "", p_pathspace
[256] = "";
578 dir
= di
->module_path
? di
->module_path
: frr_moduledir
;
583 snprintf(frr_protonameinst
, sizeof(frr_protonameinst
), "%s[%u]",
584 di
->logname
, di
->instance
);
585 snprintf(p_instance
, sizeof(p_instance
), "-%d", di
->instance
);
588 snprintf(p_pathspace
, sizeof(p_pathspace
), "%s/",
591 snprintf(config_default
, sizeof(config_default
), "%s%s%s%s.conf",
592 frr_sysconfdir
, p_pathspace
, di
->name
, p_instance
);
593 snprintf(pidfile_default
, sizeof(pidfile_default
), "%s/%s%s%s.pid",
594 frr_vtydir
, p_pathspace
, di
->name
, p_instance
);
596 snprintf(dbfile_default
, sizeof(dbfile_default
), "%s/%s%s%s.db",
597 frr_dbdir
, p_pathspace
, di
->name
, p_instance
);
600 zprivs_preinit(di
->privs
);
602 openzlog(di
->progname
, di
->logname
, di
->instance
,
603 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
605 command_setup_early_logging(di
->early_logging
, di
->early_loglevel
);
607 if (!frr_zclient_addr(&zclient_addr
, &zclient_addr_len
,
609 fprintf(stderr
, "Invalid zserv socket path: %s\n",
614 /* don't mkdir these as root... */
615 if (!(di
->flags
& FRR_NO_PRIVSEP
)) {
616 if (!di
->pid_file
|| !di
->vty_path
)
617 frr_mkdir(frr_vtydir
, false);
619 frr_mkdir(di
->pid_file
, true);
621 frr_mkdir(di
->vty_path
, true);
624 frrmod_init(di
->module
);
626 modules
= (oc
= modules
)->next
;
627 module
= frrmod_load(oc
->arg
, dir
, moderr
, sizeof(moderr
));
629 fprintf(stderr
, "%s\n", moderr
);
632 XFREE(MTYPE_TMP
, oc
);
635 zprivs_init(di
->privs
);
637 master
= thread_master_create(NULL
);
638 signal_init(master
, di
->n_signals
, di
->signals
);
642 di
->db_file
= dbfile_default
;
643 db_init(di
->db_file
);
646 if (di
->flags
& FRR_LIMITED_CLI
)
661 nb_init(master
, di
->yang_modules
, di
->n_yang_modules
);
662 if (nb_db_init() != NB_OK
)
663 flog_warn(EC_LIB_NB_DATABASE
,
664 "%s: failed to initialize northbound database",
670 const char *frr_get_progname(void)
672 return di
? di
->progname
: NULL
;
675 enum frr_cli_mode
frr_get_cli_mode(void)
677 return di
? di
->cli_mode
: FRR_CLI_CLASSIC
;
680 static int rcvd_signal
= 0;
682 static void rcv_signal(int signum
)
684 rcvd_signal
= signum
;
685 /* poll() is interrupted by the signal; handled below */
688 static void frr_daemon_wait(int fd
)
690 struct pollfd pfd
[1];
694 sigset_t sigs
, prevsigs
;
697 sigaddset(&sigs
, SIGTSTP
);
698 sigaddset(&sigs
, SIGQUIT
);
699 sigaddset(&sigs
, SIGINT
);
700 sigprocmask(SIG_BLOCK
, &sigs
, &prevsigs
);
702 struct sigaction sa
= {
703 .sa_handler
= rcv_signal
, .sa_flags
= SA_RESETHAND
,
705 sigemptyset(&sa
.sa_mask
);
706 sigaction(SIGTSTP
, &sa
, NULL
);
707 sigaction(SIGQUIT
, &sa
, NULL
);
708 sigaction(SIGINT
, &sa
, NULL
);
715 pfd
[0].events
= POLLIN
;
719 #if defined(HAVE_PPOLL)
720 ret
= ppoll(pfd
, 1, NULL
, &prevsigs
);
721 #elif defined(HAVE_POLLTS)
722 ret
= pollts(pfd
, 1, NULL
, &prevsigs
);
724 /* racy -- only used on FreeBSD 9 */
726 sigprocmask(SIG_SETMASK
, &prevsigs
, &tmpsigs
);
727 ret
= poll(pfd
, 1, -1);
728 sigprocmask(SIG_SETMASK
, &tmpsigs
, NULL
);
730 if (ret
< 0 && errno
!= EINTR
&& errno
!= EAGAIN
) {
734 switch (rcvd_signal
) {
738 nrecv
= recv(fd
, buf
, sizeof(buf
), 0);
740 && (errno
== EINTR
|| errno
== EAGAIN
));
743 sigaction(SIGTSTP
, &sa
, NULL
);
755 exitpid
= waitpid(-1, &exitstat
, WNOHANG
);
757 /* child successfully went to main loop & closed socket */
760 /* child failed one way or another ... */
761 if (WIFEXITED(exitstat
) && WEXITSTATUS(exitstat
) == 0)
762 /* can happen in --terminal case if exit is fast enough */
764 else if (WIFEXITED(exitstat
))
765 fprintf(stderr
, "%s failed to start, exited %d\n", di
->name
,
766 WEXITSTATUS(exitstat
));
767 else if (WIFSIGNALED(exitstat
))
768 fprintf(stderr
, "%s crashed in startup, signal %d\n", di
->name
,
771 fprintf(stderr
, "%s failed to start, unknown problem\n",
776 static int daemon_ctl_sock
= -1;
778 static void frr_daemonize(void)
783 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, fds
)) {
784 perror("socketpair() for daemon control");
803 daemon_ctl_sock
= fds
[1];
808 frr_daemon_wait(fds
[0]);
812 * Why is this a thread?
814 * The read in of config for integrated config happens *after*
815 * thread execution starts( because it is passed in via a vtysh -b -n )
816 * While if you are not using integrated config we want the ability
817 * to read the config in after thread execution starts, so that
818 * we can match this behavior.
820 static int frr_config_read_in(struct thread
*t
)
822 if (!vty_read_config(NULL
, di
->config_file
, config_default
) &&
823 di
->backup_config_file
) {
824 char *orig
= XSTRDUP(MTYPE_TMP
, host_config_get());
826 zlog_info("Attempting to read backup config file: %s specified",
827 di
->backup_config_file
);
828 vty_read_config(NULL
, di
->backup_config_file
, config_default
);
830 host_config_set(orig
);
831 XFREE(MTYPE_TMP
, orig
);
835 * Update the shared candidate after reading the startup configuration.
837 pthread_rwlock_rdlock(&running_config
->lock
);
839 nb_config_replace(vty_shared_candidate_config
, running_config
,
842 pthread_rwlock_unlock(&running_config
->lock
);
847 void frr_config_fork(void)
849 hook_call(frr_late_init
, master
);
851 if (!(di
->flags
& FRR_NO_CFG_PID_DRY
)) {
852 /* Don't start execution if we are in dry-run mode */
854 frr_config_read_in(NULL
);
858 thread_add_event(master
, frr_config_read_in
, NULL
, 0,
862 if (di
->daemon_mode
|| di
->terminal
)
866 di
->pid_file
= pidfile_default
;
867 pid_output(di
->pid_file
);
870 static void frr_vty_serv(void)
872 /* allow explicit override of vty_path in the future
873 * (not currently set anywhere) */
878 snprintf(defvtydir
, sizeof(defvtydir
), "%s%s%s", frr_vtydir
,
879 di
->pathspace
? "/" : "",
880 di
->pathspace
? di
->pathspace
: "");
882 dir
= di
->vty_sock_path
? di
->vty_sock_path
: defvtydir
;
885 snprintf(vtypath_default
, sizeof(vtypath_default
),
886 "%s/%s-%d.vty", dir
, di
->name
, di
->instance
);
888 snprintf(vtypath_default
, sizeof(vtypath_default
),
889 "%s/%s.vty", dir
, di
->name
);
891 di
->vty_path
= vtypath_default
;
894 vty_serv_sock(di
->vty_addr
, di
->vty_port
, di
->vty_path
);
897 static void frr_check_detach(void)
899 if (nodetach_term
|| nodetach_daemon
)
902 if (daemon_ctl_sock
!= -1)
903 close(daemon_ctl_sock
);
904 daemon_ctl_sock
= -1;
907 static void frr_terminal_close(int isexit
)
911 nodetach_term
= false;
914 if (!di
->daemon_mode
|| isexit
) {
915 printf("\n%s exiting\n", di
->name
);
920 printf("\n%s daemonizing\n", di
->name
);
924 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
926 flog_err_sys(EC_LIB_SYSTEM_CALL
,
927 "%s: failed to open /dev/null: %s", __func__
,
928 safe_strerror(errno
));
937 static struct thread
*daemon_ctl_thread
= NULL
;
939 static int frr_daemon_ctl(struct thread
*t
)
944 nr
= recv(daemon_ctl_sock
, buf
, sizeof(buf
), 0);
945 if (nr
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
951 case 'S': /* SIGTSTP */
953 if (send(daemon_ctl_sock
, "s", 1, 0) < 0)
954 zlog_err("%s send(\"s\") error (SIGTSTP propagation)",
955 (di
&& di
->name
? di
->name
: ""));
957 case 'R': /* SIGTCNT [implicit] */
960 case 'I': /* SIGINT */
961 di
->daemon_mode
= false;
964 case 'Q': /* SIGQUIT */
965 di
->daemon_mode
= true;
971 thread_add_read(master
, frr_daemon_ctl
, NULL
, daemon_ctl_sock
,
976 void frr_detach(void)
978 nodetach_daemon
= false;
982 void frr_run(struct thread_master
*master
)
984 char instanceinfo
[64] = "";
989 snprintf(instanceinfo
, sizeof(instanceinfo
), "instance %u ",
992 zlog_notice("%s %s starting: %svty@%d%s", di
->name
, FRR_VERSION
,
993 instanceinfo
, di
->vty_port
, di
->startinfo
);
996 nodetach_term
= true;
998 vty_stdio(frr_terminal_close
);
999 if (daemon_ctl_sock
!= -1) {
1000 set_nonblocking(daemon_ctl_sock
);
1001 thread_add_read(master
, frr_daemon_ctl
, NULL
,
1002 daemon_ctl_sock
, &daemon_ctl_thread
);
1004 } else if (di
->daemon_mode
) {
1005 int nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
1007 flog_err_sys(EC_LIB_SYSTEM_CALL
,
1008 "%s: failed to open /dev/null: %s",
1009 __func__
, safe_strerror(errno
));
1020 /* end fixed stderr startup logging */
1021 zlog_startup_stderr
= false;
1023 struct thread thread
;
1024 while (thread_fetch(master
, &thread
))
1025 thread_call(&thread
);
1028 void frr_early_fini(void)
1030 hook_call(frr_early_fini
);
1039 hook_call(frr_fini
);
1041 /* memory_init -> nothing needed */
1050 zprivs_terminate(di
->privs
);
1051 /* signal_init -> nothing needed */
1052 thread_master_free(master
);
1055 /* frrmod_init -> nothing needed / hooks */
1057 if (!debug_memstats_at_exit
)
1060 have_leftovers
= log_memstats(stderr
, di
->name
);
1062 /* in case we decide at runtime that we want exit-memstats for
1063 * a daemon, but it has no stderr because it's daemonized
1064 * (only do this if we actually have something to print though)
1066 if (!have_leftovers
)
1069 snprintf(filename
, sizeof(filename
), "/tmp/frr-memstats-%s-%llu-%llu",
1070 di
->name
, (unsigned long long)getpid(),
1071 (unsigned long long)time(NULL
));
1073 fp
= fopen(filename
, "w");
1075 log_memstats(fp
, di
->name
);
1081 static const char interp
[]
1082 __attribute__((section(".interp"), used
)) = INTERP
;
1085 * executable entry point for libfrr.so
1087 * note that libc initialization is skipped for this so the set of functions
1088 * that can be called is rather limited
1090 extern void _libfrr_version(void)
1091 __attribute__((visibility("hidden"), noreturn
));
1092 void _libfrr_version(void)
1094 const char banner
[] =
1095 FRR_FULL_NAME
" " FRR_VERSION
".\n"
1096 FRR_COPYRIGHT GIT_INFO
"\n"
1097 "configured with:\n " FRR_CONFIG_ARGS
"\n";
1098 write(1, banner
, sizeof(banner
) - 1);