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"
42 DEFINE_HOOK(frr_late_init
, (struct thread_master
* tm
), (tm
))
43 DEFINE_KOOH(frr_early_fini
, (), ())
44 DEFINE_KOOH(frr_fini
, (), ())
46 const char frr_sysconfdir
[] = SYSCONFDIR
;
47 const char frr_vtydir
[] = DAEMON_VTY_DIR
;
49 const char frr_dbdir
[] = DAEMON_DB_DIR
;
51 const char frr_moduledir
[] = MODULE_PATH
;
53 char frr_protoname
[256] = "NONE";
54 char frr_protonameinst
[256] = "NONE";
56 char config_default
[512];
57 char frr_zclientpath
[256];
58 static char pidfile_default
[512];
60 static char dbfile_default
[512];
62 static char vtypath_default
[256];
64 bool debug_memstats_at_exit
= 0;
65 static bool nodetach_term
, nodetach_daemon
;
67 static char comb_optstr
[256];
68 static struct option comb_lo
[64];
69 static struct option
*comb_next_lo
= &comb_lo
[0];
70 static char comb_helpstr
[4096];
75 const struct option
*longopts
;
78 static void opt_extend(const struct optspec
*os
)
80 const struct option
*lo
;
82 strcat(comb_optstr
, os
->optstr
);
83 strcat(comb_helpstr
, os
->helpstr
);
84 for (lo
= os
->longopts
; lo
->name
; lo
++)
85 memcpy(comb_next_lo
++, lo
, sizeof(*lo
));
89 #define OPTION_VTYSOCK 1000
90 #define OPTION_MODULEDIR 1002
91 #define OPTION_LOG 1003
92 #define OPTION_LOGLEVEL 1004
93 #define OPTION_TCLI 1005
94 #define OPTION_DB_FILE 1006
96 static const struct option lo_always
[] = {
97 {"help", no_argument
, NULL
, 'h'},
98 {"version", no_argument
, NULL
, 'v'},
99 {"daemon", no_argument
, NULL
, 'd'},
100 {"module", no_argument
, NULL
, 'M'},
101 {"vty_socket", required_argument
, NULL
, OPTION_VTYSOCK
},
102 {"moduledir", required_argument
, NULL
, OPTION_MODULEDIR
},
103 {"log", required_argument
, NULL
, OPTION_LOG
},
104 {"log-level", required_argument
, NULL
, OPTION_LOGLEVEL
},
105 {"tcli", no_argument
, NULL
, OPTION_TCLI
},
107 static const struct optspec os_always
= {
109 " -h, --help Display this help and exit\n"
110 " -v, --version Print program version\n"
111 " -d, --daemon Runs in daemon mode\n"
112 " -M, --module Load specified module\n"
113 " --vty_socket Override vty socket path\n"
114 " --moduledir Override modules directory\n"
115 " --log Set Logging to stdout, syslog, or file:<name>\n"
116 " --log-level Set Logging Level to use, debug, info, warn, etc\n"
117 " --tcli Use transaction-based CLI\n",
121 static const struct option lo_cfg_pid_dry
[] = {
122 {"pid_file", required_argument
, NULL
, 'i'},
123 {"config_file", required_argument
, NULL
, 'f'},
125 {"db_file", required_argument
, NULL
, OPTION_DB_FILE
},
127 {"pathspace", required_argument
, NULL
, 'N'},
128 {"dryrun", no_argument
, NULL
, 'C'},
129 {"terminal", no_argument
, NULL
, 't'},
131 static const struct optspec os_cfg_pid_dry
= {
133 " -f, --config_file Set configuration file name\n"
134 " -i, --pid_file Set process identifier file name\n"
136 " --db_file Set database file name\n"
138 " -N, --pathspace Insert prefix into config & socket paths\n"
139 " -C, --dryrun Check configuration for validity and exit\n"
140 " -t, --terminal Open terminal session on stdio\n"
141 " -d -t Daemonize after terminal session ends\n",
145 static const struct option lo_zclient
[] = {
146 {"socket", required_argument
, NULL
, 'z'},
148 static const struct optspec os_zclient
= {
149 "z:", " -z, --socket Set path of zebra socket\n", lo_zclient
};
152 static const struct option lo_vty
[] = {
153 {"vty_addr", required_argument
, NULL
, 'A'},
154 {"vty_port", required_argument
, NULL
, 'P'},
156 static const struct optspec os_vty
= {
158 " -A, --vty_addr Set vty's bind address\n"
159 " -P, --vty_port Set vty's port number\n",
163 static const struct option lo_user
[] = {{"user", required_argument
, NULL
, 'u'},
164 {"group", required_argument
, NULL
, 'g'},
166 static const struct optspec os_user
= {"u:g:",
167 " -u, --user User to run as\n"
168 " -g, --group Group to run as\n",
172 bool frr_zclient_addr(struct sockaddr_storage
*sa
, socklen_t
*sa_len
,
175 memset(sa
, 0, sizeof(*sa
));
178 path
= ZEBRA_SERV_PATH
;
180 if (!strncmp(path
, ZAPI_TCP_PATHNAME
, strlen(ZAPI_TCP_PATHNAME
))) {
181 /* note: this functionality is disabled at bottom */
183 int port
= ZEBRA_PORT
;
185 struct sockaddr_in
*sin
= NULL
;
186 struct sockaddr_in6
*sin6
= NULL
;
188 path
+= strlen(ZAPI_TCP_PATHNAME
);
208 port
= strtoul(path
, &err
, 10);
219 sin
= (struct sockaddr_in
*)sa
;
220 sin
->sin_port
= htons(port
);
221 sin
->sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
222 *sa_len
= sizeof(struct sockaddr_in
);
223 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
224 sin
->sin_len
= *sa_len
;
228 sin6
= (struct sockaddr_in6
*)sa
;
229 sin6
->sin6_port
= htons(port
);
230 inet_pton(AF_INET6
, "::1", &sin6
->sin6_addr
);
231 *sa_len
= sizeof(struct sockaddr_in6
);
233 sin6
->sin6_len
= *sa_len
;
239 /* force-disable this path, because tcp-zebra is a
240 * SECURITY ISSUE. there are no checks at all against
241 * untrusted users on the local system connecting on TCP
242 * and injecting bogus routing data into the entire routing
245 * The functionality is only left here because it may be
246 * useful during development, in order to be able to get
247 * tcpdump or wireshark watching ZAPI as TCP. If you want
248 * to do that, flip the #if 1 above to #if 0. */
249 memset(sa
, 0, sizeof(*sa
));
253 /* "sun" is a #define on solaris */
254 struct sockaddr_un
*suna
= (struct sockaddr_un
*)sa
;
256 suna
->sun_family
= AF_UNIX
;
257 strlcpy(suna
->sun_path
, path
, sizeof(suna
->sun_path
));
258 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
259 *sa_len
= suna
->sun_len
= SUN_LEN(suna
);
261 *sa_len
= sizeof(suna
->sun_family
) + strlen(suna
->sun_path
);
262 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
264 /* this is left here for future reference; Linux abstract
265 * socket namespace support can be enabled by replacing
266 * above #if 0 with #ifdef GNU_LINUX.
268 * THIS IS A SECURITY ISSUE, the abstract socket namespace
269 * does not have user/group permission control on sockets.
270 * we'd need to implement SCM_CREDENTIALS support first to
271 * check that only proper users can connect to abstract
272 * sockets. (same problem as tcp-zebra, except there is a
273 * fix with SCM_CREDENTIALS. tcp-zebra has no such fix.)
275 if (suna
->sun_path
[0] == '@')
276 suna
->sun_path
[0] = '\0';
282 static struct frr_daemon_info
*di
= NULL
;
284 void frr_preinit(struct frr_daemon_info
*daemon
, int argc
, char **argv
)
288 /* basename(), opencoded. */
289 char *p
= strrchr(argv
[0], '/');
290 di
->progname
= p
? p
+ 1 : argv
[0];
294 opt_extend(&os_always
);
295 if (!(di
->flags
& FRR_NO_CFG_PID_DRY
))
296 opt_extend(&os_cfg_pid_dry
);
297 if (!(di
->flags
& FRR_NO_PRIVSEP
))
298 opt_extend(&os_user
);
299 if (!(di
->flags
& FRR_NO_ZCLIENT
))
300 opt_extend(&os_zclient
);
301 if (!(di
->flags
& FRR_NO_TCPVTY
))
303 if (di
->flags
& FRR_DETACH_LATER
)
304 nodetach_daemon
= true;
306 snprintf(config_default
, sizeof(config_default
), "%s/%s.conf",
307 frr_sysconfdir
, di
->name
);
308 snprintf(pidfile_default
, sizeof(pidfile_default
), "%s/%s.pid",
309 frr_vtydir
, di
->name
);
311 snprintf(dbfile_default
, sizeof(dbfile_default
), "%s/%s.db",
312 frr_dbdir
, di
->name
);
315 strlcpy(frr_protoname
, di
->logname
, sizeof(frr_protoname
));
316 strlcpy(frr_protonameinst
, di
->logname
, sizeof(frr_protonameinst
));
318 strlcpy(frr_zclientpath
, ZEBRA_SERV_PATH
, sizeof(frr_zclientpath
));
320 di
->cli_mode
= FRR_CLI_CLASSIC
;
323 void frr_opt_add(const char *optstr
, const struct option
*longopts
,
326 const struct optspec main_opts
= {optstr
, helpstr
, longopts
};
327 opt_extend(&main_opts
);
330 void frr_help_exit(int status
)
332 FILE *target
= status
? stderr
: stdout
;
335 fprintf(stderr
, "Invalid options.\n\n");
338 di
->printhelp(target
);
340 fprintf(target
, "Usage: %s [OPTION...]\n\n%s%s%s\n\n%s",
341 di
->progname
, di
->proghelp
, di
->copyright
? "\n\n" : "",
342 di
->copyright
? di
->copyright
: "", comb_helpstr
);
343 fprintf(target
, "\nReport bugs to %s\n", FRR_BUG_ADDRESS
);
347 struct option_chain
{
348 struct option_chain
*next
;
352 static struct option_chain
*modules
= NULL
, **modnext
= &modules
;
353 static int errors
= 0;
355 static int frr_opt(int opt
)
357 static int vty_port_set
= 0;
358 static int vty_addr_set
= 0;
359 struct option_chain
*oc
;
367 print_version(di
->progname
);
374 oc
= XMALLOC(MTYPE_TMP
, sizeof(*oc
));
381 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
383 di
->pid_file
= optarg
;
386 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
388 di
->config_file
= optarg
;
391 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
395 "-N/--pathspace option specified more than once!\n");
399 if (strchr(optarg
, '/') || strchr(optarg
, '.')) {
401 "slashes or dots are not permitted in the --pathspace option.\n");
405 di
->pathspace
= optarg
;
409 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
411 di
->db_file
= optarg
;
415 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
420 if (di
->flags
& FRR_NO_CFG_PID_DRY
)
425 if (di
->flags
& FRR_NO_ZCLIENT
)
427 strlcpy(frr_zclientpath
, optarg
, sizeof(frr_zclientpath
));
430 if (di
->flags
& FRR_NO_TCPVTY
)
434 "-A option specified more than once!\n");
439 di
->vty_addr
= optarg
;
442 if (di
->flags
& FRR_NO_TCPVTY
)
446 "-P option specified more than once!\n");
451 di
->vty_port
= strtoul(optarg
, &err
, 0);
452 if (*err
|| !*optarg
) {
454 "invalid port number \"%s\" for -P option\n",
461 if (di
->vty_sock_path
) {
463 "--vty_socket option specified more than once!\n");
467 di
->vty_sock_path
= optarg
;
469 case OPTION_MODULEDIR
:
470 if (di
->module_path
) {
472 "----moduledir option specified more than once!\n");
476 di
->module_path
= optarg
;
479 di
->cli_mode
= FRR_CLI_TRANSACTIONAL
;
482 if (di
->flags
& FRR_NO_PRIVSEP
)
484 di
->privs
->user
= optarg
;
487 if (di
->flags
& FRR_NO_PRIVSEP
)
489 di
->privs
->group
= optarg
;
492 di
->early_logging
= optarg
;
494 case OPTION_LOGLEVEL
:
495 di
->early_loglevel
= optarg
;
503 int frr_getopt(int argc
, char *const argv
[], int *longindex
)
508 comb_next_lo
->name
= NULL
;
511 opt
= getopt_long(argc
, argv
, comb_optstr
, comb_lo
, &lidx
);
516 if (opt
== -1 && errors
)
523 static void frr_mkdir(const char *path
, bool strip
)
528 struct zprivs_ids_t ids
;
531 char *slash
= strrchr(path
, '/');
536 if (plen
> sizeof(buf
) - 1)
538 memcpy(buf
, path
, plen
);
543 /* o+rx (..5) is needed for the frrvty group to work properly;
544 * without it, users in the frrvty group can't access the vty sockets.
547 ret
= mkdir(path
, 0755);
551 /* if EEXIST, return without touching the permissions,
552 * so user-set custom permissions are left in place
557 flog_err(EC_LIB_SYSTEM_CALL
, "failed to mkdir \"%s\": %s", path
,
562 zprivs_get_ids(&ids
);
563 if (chown(path
, ids
.uid_normal
, ids
.gid_normal
))
564 flog_err(EC_LIB_SYSTEM_CALL
, "failed to chown \"%s\": %s", path
,
568 static struct thread_master
*master
;
569 struct thread_master
*frr_init(void)
571 struct option_chain
*oc
;
572 struct frrmod_runtime
*module
;
574 char p_instance
[16] = "", p_pathspace
[256] = "";
576 dir
= di
->module_path
? di
->module_path
: frr_moduledir
;
581 snprintf(frr_protonameinst
, sizeof(frr_protonameinst
), "%s[%u]",
582 di
->logname
, di
->instance
);
583 snprintf(p_instance
, sizeof(p_instance
), "-%d", di
->instance
);
586 snprintf(p_pathspace
, sizeof(p_pathspace
), "%s/",
589 snprintf(config_default
, sizeof(config_default
), "%s%s%s%s.conf",
590 frr_sysconfdir
, p_pathspace
, di
->name
, p_instance
);
591 snprintf(pidfile_default
, sizeof(pidfile_default
), "%s/%s%s%s.pid",
592 frr_vtydir
, p_pathspace
, di
->name
, p_instance
);
594 snprintf(dbfile_default
, sizeof(dbfile_default
), "%s/%s%s%s.db",
595 frr_dbdir
, p_pathspace
, di
->name
, p_instance
);
598 zprivs_preinit(di
->privs
);
600 openzlog(di
->progname
, di
->logname
, di
->instance
,
601 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
603 command_setup_early_logging(di
->early_logging
, di
->early_loglevel
);
605 if (!frr_zclient_addr(&zclient_addr
, &zclient_addr_len
,
607 fprintf(stderr
, "Invalid zserv socket path: %s\n",
612 /* don't mkdir these as root... */
613 if (!(di
->flags
& FRR_NO_PRIVSEP
)) {
614 if (!di
->pid_file
|| !di
->vty_path
)
615 frr_mkdir(frr_vtydir
, false);
617 frr_mkdir(di
->pid_file
, true);
619 frr_mkdir(di
->vty_path
, true);
622 frrmod_init(di
->module
);
624 modules
= (oc
= modules
)->next
;
625 module
= frrmod_load(oc
->arg
, dir
, moderr
, sizeof(moderr
));
627 fprintf(stderr
, "%s\n", moderr
);
630 XFREE(MTYPE_TMP
, oc
);
633 zprivs_init(di
->privs
);
635 master
= thread_master_create(NULL
);
636 signal_init(master
, di
->n_signals
, di
->signals
);
640 di
->db_file
= dbfile_default
;
641 db_init(di
->db_file
);
644 if (di
->flags
& FRR_LIMITED_CLI
)
656 nb_init(master
, di
->yang_modules
, di
->n_yang_modules
);
661 const char *frr_get_progname(void)
663 return di
? di
->progname
: NULL
;
666 enum frr_cli_mode
frr_get_cli_mode(void)
668 return di
? di
->cli_mode
: FRR_CLI_CLASSIC
;
671 static int rcvd_signal
= 0;
673 static void rcv_signal(int signum
)
675 rcvd_signal
= signum
;
676 /* poll() is interrupted by the signal; handled below */
679 static void frr_daemon_wait(int fd
)
681 struct pollfd pfd
[1];
685 sigset_t sigs
, prevsigs
;
688 sigaddset(&sigs
, SIGTSTP
);
689 sigaddset(&sigs
, SIGQUIT
);
690 sigaddset(&sigs
, SIGINT
);
691 sigprocmask(SIG_BLOCK
, &sigs
, &prevsigs
);
693 struct sigaction sa
= {
694 .sa_handler
= rcv_signal
, .sa_flags
= SA_RESETHAND
,
696 sigemptyset(&sa
.sa_mask
);
697 sigaction(SIGTSTP
, &sa
, NULL
);
698 sigaction(SIGQUIT
, &sa
, NULL
);
699 sigaction(SIGINT
, &sa
, NULL
);
706 pfd
[0].events
= POLLIN
;
710 #if defined(HAVE_PPOLL)
711 ret
= ppoll(pfd
, 1, NULL
, &prevsigs
);
712 #elif defined(HAVE_POLLTS)
713 ret
= pollts(pfd
, 1, NULL
, &prevsigs
);
715 /* racy -- only used on FreeBSD 9 */
717 sigprocmask(SIG_SETMASK
, &prevsigs
, &tmpsigs
);
718 ret
= poll(pfd
, 1, -1);
719 sigprocmask(SIG_SETMASK
, &tmpsigs
, NULL
);
721 if (ret
< 0 && errno
!= EINTR
&& errno
!= EAGAIN
) {
725 switch (rcvd_signal
) {
729 nrecv
= recv(fd
, buf
, sizeof(buf
), 0);
731 && (errno
== EINTR
|| errno
== EAGAIN
));
734 sigaction(SIGTSTP
, &sa
, NULL
);
746 exitpid
= waitpid(-1, &exitstat
, WNOHANG
);
748 /* child successfully went to main loop & closed socket */
751 /* child failed one way or another ... */
752 if (WIFEXITED(exitstat
) && WEXITSTATUS(exitstat
) == 0)
753 /* can happen in --terminal case if exit is fast enough */
755 else if (WIFEXITED(exitstat
))
756 fprintf(stderr
, "%s failed to start, exited %d\n", di
->name
,
757 WEXITSTATUS(exitstat
));
758 else if (WIFSIGNALED(exitstat
))
759 fprintf(stderr
, "%s crashed in startup, signal %d\n", di
->name
,
762 fprintf(stderr
, "%s failed to start, unknown problem\n",
767 static int daemon_ctl_sock
= -1;
769 static void frr_daemonize(void)
774 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, fds
)) {
775 perror("socketpair() for daemon control");
794 daemon_ctl_sock
= fds
[1];
799 frr_daemon_wait(fds
[0]);
803 * Why is this a thread?
805 * The read in of config for integrated config happens *after*
806 * thread execution starts( because it is passed in via a vtysh -b -n )
807 * While if you are not using integrated config we want the ability
808 * to read the config in after thread execution starts, so that
809 * we can match this behavior.
811 static int frr_config_read_in(struct thread
*t
)
813 if (!vty_read_config(NULL
, di
->config_file
, config_default
) &&
814 di
->backup_config_file
) {
815 char *orig
= XSTRDUP(MTYPE_TMP
, host_config_get());
817 zlog_info("Attempting to read backup config file: %s specified",
818 di
->backup_config_file
);
819 vty_read_config(NULL
, di
->backup_config_file
, config_default
);
821 host_config_set(orig
);
822 XFREE(MTYPE_TMP
, orig
);
826 * Update the shared candidate after reading the startup configuration.
828 nb_config_replace(vty_shared_candidate_config
, running_config
, true);
833 void frr_config_fork(void)
835 hook_call(frr_late_init
, master
);
837 if (!(di
->flags
& FRR_NO_CFG_PID_DRY
)) {
838 /* Don't start execution if we are in dry-run mode */
840 frr_config_read_in(NULL
);
844 thread_add_event(master
, frr_config_read_in
, NULL
, 0,
848 if (di
->daemon_mode
|| di
->terminal
)
852 di
->pid_file
= pidfile_default
;
853 pid_output(di
->pid_file
);
856 static void frr_vty_serv(void)
858 /* allow explicit override of vty_path in the future
859 * (not currently set anywhere) */
864 snprintf(defvtydir
, sizeof(defvtydir
), "%s%s%s", frr_vtydir
,
865 di
->pathspace
? "/" : "",
866 di
->pathspace
? di
->pathspace
: "");
868 dir
= di
->vty_sock_path
? di
->vty_sock_path
: defvtydir
;
871 snprintf(vtypath_default
, sizeof(vtypath_default
),
872 "%s/%s-%d.vty", dir
, di
->name
, di
->instance
);
874 snprintf(vtypath_default
, sizeof(vtypath_default
),
875 "%s/%s.vty", dir
, di
->name
);
877 di
->vty_path
= vtypath_default
;
880 vty_serv_sock(di
->vty_addr
, di
->vty_port
, di
->vty_path
);
883 static void frr_check_detach(void)
885 if (nodetach_term
|| nodetach_daemon
)
888 if (daemon_ctl_sock
!= -1)
889 close(daemon_ctl_sock
);
890 daemon_ctl_sock
= -1;
893 static void frr_terminal_close(int isexit
)
897 nodetach_term
= false;
900 if (!di
->daemon_mode
|| isexit
) {
901 printf("\n%s exiting\n", di
->name
);
906 printf("\n%s daemonizing\n", di
->name
);
910 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
912 flog_err_sys(EC_LIB_SYSTEM_CALL
,
913 "%s: failed to open /dev/null: %s", __func__
,
914 safe_strerror(errno
));
923 static struct thread
*daemon_ctl_thread
= NULL
;
925 static int frr_daemon_ctl(struct thread
*t
)
930 nr
= recv(daemon_ctl_sock
, buf
, sizeof(buf
), 0);
931 if (nr
< 0 && (errno
== EINTR
|| errno
== EAGAIN
))
937 case 'S': /* SIGTSTP */
939 if (send(daemon_ctl_sock
, "s", 1, 0) < 0)
940 zlog_err("%s send(\"s\") error (SIGTSTP propagation)",
941 (di
&& di
->name
? di
->name
: ""));
943 case 'R': /* SIGTCNT [implicit] */
946 case 'I': /* SIGINT */
947 di
->daemon_mode
= false;
950 case 'Q': /* SIGQUIT */
951 di
->daemon_mode
= true;
957 thread_add_read(master
, frr_daemon_ctl
, NULL
, daemon_ctl_sock
,
962 void frr_detach(void)
964 nodetach_daemon
= false;
968 void frr_run(struct thread_master
*master
)
970 char instanceinfo
[64] = "";
975 snprintf(instanceinfo
, sizeof(instanceinfo
), "instance %u ",
978 zlog_notice("%s %s starting: %svty@%d%s", di
->name
, FRR_VERSION
,
979 instanceinfo
, di
->vty_port
, di
->startinfo
);
982 nodetach_term
= true;
984 vty_stdio(frr_terminal_close
);
985 if (daemon_ctl_sock
!= -1) {
986 set_nonblocking(daemon_ctl_sock
);
987 thread_add_read(master
, frr_daemon_ctl
, NULL
,
988 daemon_ctl_sock
, &daemon_ctl_thread
);
990 } else if (di
->daemon_mode
) {
991 int nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
993 flog_err_sys(EC_LIB_SYSTEM_CALL
,
994 "%s: failed to open /dev/null: %s",
995 __func__
, safe_strerror(errno
));
1006 /* end fixed stderr startup logging */
1007 zlog_startup_stderr
= false;
1009 struct thread thread
;
1010 while (thread_fetch(master
, &thread
))
1011 thread_call(&thread
);
1014 void frr_early_fini(void)
1016 hook_call(frr_early_fini
);
1025 hook_call(frr_fini
);
1027 /* memory_init -> nothing needed */
1036 zprivs_terminate(di
->privs
);
1037 /* signal_init -> nothing needed */
1038 thread_master_free(master
);
1041 /* frrmod_init -> nothing needed / hooks */
1043 if (!debug_memstats_at_exit
)
1046 have_leftovers
= log_memstats(stderr
, di
->name
);
1048 /* in case we decide at runtime that we want exit-memstats for
1049 * a daemon, but it has no stderr because it's daemonized
1050 * (only do this if we actually have something to print though)
1052 if (!have_leftovers
)
1055 snprintf(filename
, sizeof(filename
), "/tmp/frr-memstats-%s-%llu-%llu",
1056 di
->name
, (unsigned long long)getpid(),
1057 (unsigned long long)time(NULL
));
1059 fp
= fopen(filename
, "w");
1061 log_memstats(fp
, di
->name
);
1067 static const char interp
[]
1068 __attribute__((section(".interp"), used
)) = INTERP
;
1071 * executable entry point for libfrr.so
1073 * note that libc initialization is skipped for this so the set of functions
1074 * that can be called is rather limited
1076 extern void _libfrr_version(void)
1077 __attribute__((visibility("hidden"), noreturn
));
1078 void _libfrr_version(void)
1080 const char banner
[] =
1081 FRR_FULL_NAME
" " FRR_VERSION
".\n"
1082 FRR_COPYRIGHT GIT_INFO
"\n"
1083 "configured with:\n " FRR_CONFIG_ARGS
"\n";
1084 write(1, banner
, sizeof(banner
) - 1);