From 34350a52700955d50895058d01b5407aea970e9b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 6 Dec 1999 12:34:45 +0000 Subject: Implemented echoing of log messages to CLI connections. Just try `echo all'. --- sysdep/unix/client-main.c | 6 ++++++ sysdep/unix/log.c | 47 +++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 30 deletions(-) (limited to 'sysdep') diff --git a/sysdep/unix/client-main.c b/sysdep/unix/client-main.c index 01a7986..4fc2433 100644 --- a/sysdep/unix/client-main.c +++ b/sysdep/unix/client-main.c @@ -14,6 +14,7 @@ #include "nest/bird.h" #include "lib/resource.h" /* For dmalloc */ #include "client/client.h" +#include "nest/cli.h" #include "unix.h" @@ -41,6 +42,11 @@ parse_args(int argc, char **argv) usage(); } +void +cli_echo(unsigned int class, byte *buf) +{ +} + int client_main(int argc, char **argv) { diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 5dd7ef7..a6e1a56 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -1,7 +1,7 @@ /* * BIRD Library -- Logging Functions * - * (c) 1998 Martin Mares + * (c) 1998--1999 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -12,6 +12,7 @@ #include #include "nest/bird.h" +#include "nest/cli.h" #include "lib/string.h" static int log_inited; @@ -42,40 +43,21 @@ static char *class_names[] = { "FATAL" }; -/* FIXME: Use better buffering */ - -static void -bvfprintf(FILE *f, char *fmt, va_list args) -{ - char buf[4096]; - int n; - - n = bvsnprintf(buf, sizeof(buf), fmt, args); - if (n >= 0) - fwrite(buf, n, sizeof(char), f); - else - fprintf(stderr, "BIRD: warning: logging buffer overflow!\n"); -} - static void -bfprintf(FILE *f, char *fmt, ...) +vlog(int class, char *msg, va_list args) { - va_list args; + char buf[1024]; + char date[32]; - va_start(args, fmt); - bvfprintf(f, fmt, args); - va_end(args); -} + if (bvsnprintf(buf, sizeof(buf)-1, msg, args) < 0) + bsprintf(buf + sizeof(buf) - 100, " ... "); -static void -vlog(int class, char *msg, va_list args) -{ if (logf) { time_t now = time(NULL); struct tm *tm = localtime(&now); - bfprintf(logf, "%02d-%02d-%04d %02d:%02d:%02d <%s> ", + bsprintf(date, "%02d-%02d-%04d %02d:%02d:%02d <%s> ", tm->tm_mday, tm->tm_mon+1, tm->tm_year+1900, @@ -83,21 +65,23 @@ vlog(int class, char *msg, va_list args) tm->tm_min, tm->tm_sec, class_names[class]); - bvfprintf(logf, msg, args); + fputs(date, logf); + fputs(buf, logf); fputc('\n', logf); fflush(logf); } #ifdef HAVE_SYSLOG else if (log_inited) - vsyslog(syslog_priorities[class], msg, args); + syslog(syslog_priorities[class], "%s", buf); #endif else { fputs("bird: ", stderr); - bvfprintf(stderr, msg, args); + fputs(buf, stderr); fputc('\n', stderr); fflush(stderr); } + cli_echo(class, buf); } void @@ -137,10 +121,13 @@ void debug(char *msg, ...) { va_list args; + char buf[1024]; va_start(args, msg); + if (bvsnprintf(buf, sizeof(buf), msg, args) < 0) + bsprintf(buf + sizeof(buf) - 100, " ... \n"); if (dbgf) - bvfprintf(dbgf, msg, args); + fputs(buf, dbgf); va_end(args); } -- cgit v1.2.3