summaryrefslogtreecommitdiff
path: root/lib/libfrr.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2021-02-15 15:20:18 -0500
committerGitHub <noreply@github.com>2021-02-15 15:20:18 -0500
commita6d1b6a04311bb2f49b9e05cd678ca48bf99ef8c (patch)
tree7a11daffe0704c337da265c90d2070534afee201 /lib/libfrr.c
parent54c7adbf49e7466e46c91a749fdf0aa31882d937 (diff)
parente0a5979d58c39b6a173052867f4f44e9b85bd1c3 (diff)
Merge pull request #8075 from opensourcerouting/assorted-20210212
lib: bunch of random small fixes
Diffstat (limited to 'lib/libfrr.c')
-rw-r--r--lib/libfrr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c
index b83883779c..51b97369c9 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -71,6 +71,7 @@ static char vtypath_default[512];
bool debug_memstats_at_exit = false;
static bool nodetach_term, nodetach_daemon;
+static uint64_t startup_fds;
static char comb_optstr[256];
static struct option comb_lo[64];
@@ -341,6 +342,28 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv)
strlcpy(frr_protonameinst, di->logname, sizeof(frr_protonameinst));
di->cli_mode = FRR_CLI_CLASSIC;
+
+ /* we may be starting with extra FDs open for whatever purpose,
+ * e.g. logging, some module, etc. Recording them here allows later
+ * checking whether an fd is valid for such extension purposes,
+ * without this we could end up e.g. logging to a BGP session fd.
+ */
+ startup_fds = 0;
+ for (int i = 0; i < 64; i++) {
+ struct stat st;
+
+ if (fstat(i, &st))
+ continue;
+ if (S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode))
+ continue;
+
+ startup_fds |= UINT64_C(0x1) << (uint64_t)i;
+ }
+}
+
+bool frr_is_startup_fd(int fd)
+{
+ return !!(startup_fds & (UINT64_C(0x1) << (uint64_t)fd));
}
void frr_opt_add(const char *optstr, const struct option *longopts,