--- embedaddon/quagga/lib/log.c 2013/07/21 23:54:39 1.1.1.3 +++ embedaddon/quagga/lib/log.c 2016/11/02 10:09:11 1.1.1.4 @@ -51,6 +51,7 @@ const char *zlog_proto_names[] = "BABEL", "OSPF6", "ISIS", + "PIM", "MASC", NULL, }; @@ -69,7 +70,7 @@ const char *zlog_priority[] = }; - + /* For time string format. */ size_t @@ -145,11 +146,12 @@ time_print(FILE *fp, struct timestamp_control *ctl) fprintf(fp, "%s ", ctl->buf); } - + /* va_list version of zlog. */ static void vzlog (struct zlog *zl, int priority, const char *format, va_list args) { + int original_errno = errno; struct timestamp_control tsctl; tsctl.already_rendered = 0; @@ -168,6 +170,7 @@ vzlog (struct zlog *zl, int priority, const char *form fflush (stderr); /* In this case we return at here. */ + errno = original_errno; return; } tsctl.precision = zl->timestamp_precision; @@ -215,6 +218,8 @@ vzlog (struct zlog *zl, int priority, const char *form if (priority <= zl->maxlvl[ZLOG_DEST_MONITOR]) vty_log ((zl->record_priority ? zlog_priority[priority] : NULL), zlog_proto_names[zl->protocol], format, &tsctl, args); + + errno = original_errno; } static char * @@ -425,6 +430,40 @@ zlog_signal(int signo, const char *action NULL #endif ); + + s = buf; + if (!thread_current) + s = str_append (LOC, "no thread information available\n"); + else + { + s = str_append (LOC, "in thread "); + s = str_append (LOC, thread_current->funcname); + s = str_append (LOC, " scheduled from "); + s = str_append (LOC, thread_current->schedfrom); + s = str_append (LOC, ":"); + s = num_append (LOC, thread_current->schedfrom_line); + s = str_append (LOC, "\n"); + } + +#define DUMP(FD) write(FD, buf, s-buf); + /* If no file logging configured, try to write to fallback log file. */ + if (logfile_fd >= 0) + DUMP(logfile_fd) + if (!zlog_default) + DUMP(STDERR_FILENO) + else + { + if (PRI <= zlog_default->maxlvl[ZLOG_DEST_STDOUT]) + DUMP(STDOUT_FILENO) + /* Remove trailing '\n' for monitor and syslog */ + *--s = '\0'; + if (PRI <= zlog_default->maxlvl[ZLOG_DEST_MONITOR]) + vty_log_fixed(buf,s-buf); + if (PRI <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG]) + syslog_sigsafe(PRI|zlog_default->facility,msgstart,s-msgstart); + } +#undef DUMP + #undef PRI #undef LOC } @@ -443,8 +482,8 @@ zlog_backtrace_sigsafe(int priority, void *program_cou #define LOC s,buf+sizeof(buf)-s #ifdef HAVE_GLIBC_BACKTRACE - if (((size = backtrace(array,array_size(array)) <= 0) || - ((size_t)size > array_size(array)))) + size = backtrace(array, array_size(array)); + if (size <= 0 || (size_t)size > array_size(array)) return; #define DUMP(FD) { \ @@ -526,8 +565,8 @@ zlog_backtrace(int priority) int size, i; char **strings; - if (((size = backtrace(array,array_size(array))) <= 0) || - ((size_t)size > array_size(array))) + size = backtrace(array, array_size(array)); + if (size <= 0 || (size_t)size > array_size(array)) { zlog_err("Cannot get backtrace, returned invalid # of frames %d " "(valid range is between 1 and %lu)", @@ -604,6 +643,16 @@ PLOG_FUNC(plog_debug, LOG_DEBUG) #undef PLOG_FUNC +void zlog_thread_info (int log_level) +{ + if (thread_current) + zlog(NULL, log_level, "Current thread function %s, scheduled from " + "file %s, line %u", thread_current->funcname, + thread_current->schedfrom, thread_current->schedfrom_line); + else + zlog(NULL, log_level, "Current thread not known/applicable"); +} + void _zlog_assert_failed (const char *assertion, const char *file, unsigned int line, const char *function) @@ -616,10 +665,11 @@ _zlog_assert_failed (const char *assertion, const char zlog(NULL, LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s", assertion,file,line,(function ? function : "?")); zlog_backtrace(LOG_CRIT); + zlog_thread_info(LOG_CRIT); abort(); } - + /* Open log stream */ struct zlog * openzlog (const char *progname, zlog_proto_t protocol, @@ -756,7 +806,7 @@ zlog_rotate (struct zlog *zl) return 1; } - + /* Message lookup function. */ const char * lookup (const struct message *mes, int key) @@ -954,4 +1004,46 @@ proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_BABEL; } return -1; +} + +void +zlog_hexdump (void *mem, unsigned int len) { + unsigned long i = 0; + unsigned int j = 0; + unsigned int columns = 8; + char buf[(len * 4) + ((len/4) * 20) + 30]; + char *s = buf; + + for (i = 0; i < len + ((len % columns) ? (columns - len % columns) : 0); i++) + { + /* print offset */ + if (i % columns == 0) + s += sprintf(s, "0x%016lx: ", (unsigned long)mem + i); + + /* print hex data */ + if (i < len) + s += sprintf(s, "%02x ", 0xFF & ((char*)mem)[i]); + + /* end of block, just aligning for ASCII dump */ + else + s += sprintf(s, " "); + + /* print ASCII dump */ + if (i % columns == (columns - 1)) + { + for (j = i - (columns - 1); j <= i; j++) + { + if (j >= len) /* end of block, not really printing */ + s += sprintf(s, " "); + + else if(isprint((int)((char*)mem)[j])) /* printable char */ + s += sprintf(s, "%c", 0xFF & ((char*)mem)[j]); + + else /* other char */ + s += sprintf(s, "."); + } + s += sprintf(s, "\n"); + } + } + zlog_debug("\n%s", buf); }