]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add `monitor:<fd>` command line log target
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 5 Mar 2022 18:43:44 +0000 (19:43 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 7 Mar 2022 17:03:16 +0000 (18:03 +0100)
This provides direct raw log output with full metadata directly at
startup regardless of configuration details.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/log_vty.c
lib/zlog_live.c
lib/zlog_live.h

index 682c9ea372b36ed14187dba1ba1c3b3a7b84b770..ef33a39d4a634394aa191fbb9646ddb67deafa9a 100644 (file)
@@ -427,6 +427,22 @@ void command_setup_early_logging(const char *dest, const char *level)
                set_log_file(&zt_file_cmdline, NULL, sep, nlevel);
                return;
        }
+       if (strcmp(type, "monitor") == 0 && sep) {
+               struct zlog_live_cfg cfg = {};
+               unsigned long fd;
+               char *endp;
+
+               sep++;
+               fd = strtoul(sep, &endp, 10);
+               if (!*sep || *endp) {
+                       fprintf(stderr, "invalid monitor fd \"%s\"\n", sep);
+                       exit(1);
+               }
+
+               zlog_live_open_fd(&cfg, nlevel, fd);
+               zlog_live_disown(&cfg);
+               return;
+       }
 
        fprintf(stderr, "invalid log target \"%s\" (\"%s\")\n", type, dest);
        exit(1);
index fd2291a86f84f3fc38938ec208a01484aef8d936..d871e20db10662e52632f0b34cc21b72b6b88e5b 100644 (file)
@@ -182,8 +182,6 @@ static void zlog_live_sigsafe(struct zlog_target *zt, const char *text,
 void zlog_live_open(struct zlog_live_cfg *cfg, int prio_min, int *other_fd)
 {
        int sockets[2];
-       struct zlt_live *zte;
-       struct zlog_target *zt;
 
        if (cfg->target)
                zlog_live_close(cfg);
@@ -208,13 +206,23 @@ void zlog_live_open(struct zlog_live_cfg *cfg, int prio_min, int *other_fd)
                shutdown(sockets[0], SHUT_RD);
 
        *other_fd = sockets[1];
+       zlog_live_open_fd(cfg, prio_min, sockets[0]);
+}
+
+void zlog_live_open_fd(struct zlog_live_cfg *cfg, int prio_min, int fd)
+{
+       struct zlt_live *zte;
+       struct zlog_target *zt;
+
+       if (cfg->target)
+               zlog_live_close(cfg);
 
        zt = zlog_target_clone(MTYPE_LOG_LIVE, NULL, sizeof(*zte));
        zte = container_of(zt, struct zlt_live, zt);
        cfg->target = zte;
 
-       set_nonblocking(sockets[0]);
-       zte->fd = sockets[0];
+       set_nonblocking(fd);
+       zte->fd = fd;
        zte->zt.prio_min = prio_min;
        zte->zt.logfn = zlog_live;
        zte->zt.logfn_sigsafe = zlog_live_sigsafe;
index 5e80f016fdfb7aa274ab784db780465415386d73..ab8aae452f4bad1525ae05337e4894d0668e985b 100644 (file)
@@ -68,6 +68,7 @@ struct zlog_live_cfg {
 
 extern void zlog_live_open(struct zlog_live_cfg *cfg, int prio_min,
                           int *other_fd);
+extern void zlog_live_open_fd(struct zlog_live_cfg *cfg, int prio_min, int fd);
 
 static inline bool zlog_live_is_null(struct zlog_live_cfg *cfg)
 {