summaryrefslogtreecommitdiff
path: root/lib/libfrr.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-05-06 06:40:17 +0200
committerDavid Lamparter <equinox@diac24.net>2020-04-01 06:53:26 +0200
commit0bdeb5e58d8fdf8b0f30461a388768112b0e080c (patch)
tree8a5889d3b10b0b89a6fbf403f3bc7a3a040fce3e /lib/libfrr.c
parent6f00dd6658acd0dc04f6c65e28452c2de93c99d5 (diff)
lib: rewrite zlog lock-free & TLS-buffered
This is a full rewrite of the "back end" logging code. It now uses a lock-free list to iterate over logging targets, and the targets themselves are as lock-free as possible. (syslog() may have a hidden internal mutex in the C library; the file/fd targets use a single write() call which should ensure atomicity kernel-side.) Note that some functionality is lost in this patch: - Solaris printstack() backtraces are ditched (unlikely to come back) - the `log-filter` machinery is gone (re-added in followup commit) - `terminal monitor` is temporarily stubbed out. The old code had a race condition with VTYs going away. It'll likely come back rewritten and with vtysh support. - The `zebra_ext_log` hook is gone. Instead, it's now much easier to add a "proper" logging target. v2: TLS buffer to get some actual performance Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/libfrr.c')
-rw-r--r--lib/libfrr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 3622890e46..084ab93a4e 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -33,7 +33,6 @@
#include "lib_vty.h"
#include "log_vty.h"
#include "zclient.h"
-#include "log_int.h"
#include "module.h"
#include "network.h"
#include "lib_errors.h"
@@ -630,6 +629,7 @@ struct thread_master *frr_init(void)
{
struct option_chain *oc;
struct frrmod_runtime *module;
+ struct zprivs_ids_t ids;
char moderr[256];
char p_instance[16] = "", p_pathspace[256] = "";
const char *dir;
@@ -657,9 +657,11 @@ struct thread_master *frr_init(void)
#endif
zprivs_preinit(di->privs);
+ zprivs_get_ids(&ids);
- openzlog(di->progname, di->logname, di->instance,
- LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
+ zlog_init(di->progname, di->logname, di->instance,
+ ids.uid_normal, ids.gid_normal);
+ zlog_tls_buffer_init();
command_setup_early_logging(di->early_logging, di->early_loglevel);
@@ -709,7 +711,6 @@ struct thread_master *frr_init(void)
vty_init(master, di->log_always);
lib_cmd_init();
- log_filter_cmd_init();
frr_pthread_init();
@@ -1086,7 +1087,7 @@ void frr_run(struct thread_master *master)
}
/* end fixed stderr startup logging */
- zlog_startup_stderr = false;
+ zlog_startup_end();
struct thread thread;
while (thread_fetch(master, &thread))
@@ -1119,7 +1120,8 @@ void frr_fini(void)
/* signal_init -> nothing needed */
thread_master_free(master);
master = NULL;
- closezlog();
+ zlog_tls_buffer_fini();
+ zlog_fini();
/* frrmod_init -> nothing needed / hooks */
rcu_shutdown();