diff --git a/CHANGES b/CHANGES index ea0347f..0aa9404 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ Version 1.4 . Skip newline when reading in klog messages + . Use lseek64() instead of llseek() which is deprecated these days + . Keith Owens + - Fixed bug that caused klogd to die if there is no sym_array available. + - When symbols are expanded, print the line twice. Once with + addresses converted to symbols, once with the raw text. Allows + external programs such as ksymoops do their own processing on the + original data. diff --git a/klogd.8 b/klogd.8 index 3065e93..0f585a6 100644 --- a/klogd.8 +++ b/klogd.8 @@ -27,6 +27,7 @@ klogd \- Kernel Log Daemon ] .RB [ " \-v " ] .RB [ " \-x " ] +.RB [ " \-2 " ] .LP .SH DESCRIPTION .B klogd @@ -80,6 +81,12 @@ Print version and exit. .TP .B "\-x" Omits EIP translation and therefore doesn't read the System.map file. +.TP +.B "\-2" +When symbols are expanded, print the line twice. Once with addresses +converted to symbols, once with the raw text. This allows external +programs such as ksymoops do their own processing on the original +data. .LP .SH OVERVIEW The functionality of klogd has been typically incorporated into other @@ -217,7 +224,10 @@ program which is included in the kernel sources. As a convenience .B klogd will attempt to resolve kernel numeric addresses to their symbolic -forms if a kernel symbol table is available at execution time. A +forms if a kernel symbol table is available at execution time. If you +require the original address of the symbol, use the +.B -2 +switch to preserve the numeric address. A symbol table may be specified by using the \fB\-k\fR switch on the command line. If a symbol file is not explicitly specified the following filenames will be tried: diff --git a/klogd.c b/klogd.c index 7678cef..b76a373 100644 --- a/klogd.c +++ b/klogd.c @@ -216,6 +216,18 @@ * * Sat Aug 21 12:27:02 CEST 1999: Martin Schulze * Skip newline when reading in messages. + * + * Tue Sep 12 22:14:33 CEST 2000: Martin Schulze + * Don't feed a buffer directly to a printf-type routine, use + * "%s" as format string instead. Thanks to Jouko Pynnönen + * for pointing this out. + * + * Tue Sep 12 22:44:57 CEST 2000: Martin Schulze + * Commandline option `-2': When symbols are expanded, print the + * line twice. Once with addresses converted to symbols, once with the + * raw text. Allows external programs such as ksymoops do their own + * processing on the original data. Thanks to Keith Owens + * for the patch. */ @@ -279,6 +291,7 @@ static FILE *output_file = (FILE *) 0; static enum LOGSRC {none, proc, kernel} logsrc; int debugging = 0; +int symbols_twice = 0; /* Function prototypes. */ @@ -641,6 +654,11 @@ static int copyin( char *line, int space, * in length to LOG_LINE_LENGTH, the symbol will not be expanded. * (This should never happen, since the kernel should never generate * messages that long. + * + * To preserve the original addresses, lines containing kernel symbols + * are output twice. Once with the symbols converted and again with the + * original text. Just in case somebody wants to run their own Oops + * analysis on the syslog, e.g. ksymoops. */ static void LogLine(char *ptr, int len) { @@ -660,6 +678,10 @@ static void LogLine(char *ptr, int len) static char *sym_start; /* points at the '<' of a symbol */ auto int delta = 0; /* number of chars copied */ + auto int symbols_expanded = 0; /* 1 if symbols were expanded */ + auto int skip_symbol_lookup = 0; /* skip symbol lookup on this pass */ + auto char *save_ptr = ptr; /* save start of input line */ + auto int save_len = len; /* save length at start of input line */ while( len > 0 ) { @@ -676,10 +698,14 @@ static void LogLine(char *ptr, int len) fprintf(stderr, "\tLine: %s\n", line); } - Syslog( LOG_INFO, line_buff ); + Syslog( LOG_INFO, "%s", line_buff ); line = line_buff; space = sizeof(line_buff)-1; parse_state = PARSING_TEXT; + symbols_expanded = 0; + skip_symbol_lookup = 0; + save_ptr = ptr; + save_len = len; } switch( parse_state ) @@ -703,9 +729,24 @@ static void LogLine(char *ptr, int len) len -= 1; *line = 0; /* force null terminator */ - Syslog( LOG_INFO, line_buff ); + Syslog( LOG_INFO, "%s", line_buff ); line = line_buff; space = sizeof(line_buff)-1; + if (symbols_twice) { + if (symbols_expanded) { + /* reprint this line without symbol lookup */ + symbols_expanded = 0; + skip_symbol_lookup = 1; + ptr = save_ptr; + len = save_len; + } + else + { + skip_symbol_lookup = 0; + save_ptr = ptr; + save_len = len; + } + } break; } if( *ptr == '[' ) /* possible kernel symbol */ @@ -713,7 +754,8 @@ static void LogLine(char *ptr, int len) *line++ = *ptr++; space -= 1; len -= 1; - parse_state = PARSING_SYMSTART; /* at < */ + if (!skip_symbol_lookup) + parse_state = PARSING_SYMSTART; /* at < */ break; } if( *ptr == '%' ) /* dangerous printf marker */ @@ -831,6 +873,7 @@ static void LogLine(char *ptr, int len) space = sym_space + delta; line = sym_start + delta; + symbols_expanded = 1; } ptr++; len--; @@ -915,9 +958,12 @@ int main(argc, argv) chdir ("/"); #endif /* Parse the command-line. */ - while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx")) != EOF) + while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2")) != EOF) switch((char)ch) { + case '2': /* Print lines with symbols twice. */ + symbols_twice = 1; + break; case 'c': /* Set console message level. */ log_level = optarg; break; diff --git a/ksym.c b/ksym.c index d1d3f99..3c74b66 100644 --- a/ksym.c +++ b/ksym.c @@ -99,6 +99,9 @@ * . extract major.minor.patch from utsname.release via sscanf() * The reason lays in possible use of kernel flavours which * modify utsname.release but no the Version_ symbol. + * + * Sun Feb 21 22:27:49 EST 1999: Keith Owens + * Fixed bug that caused klogd to die if there is no sym_array available. */ @@ -636,9 +639,12 @@ char * LookupSymbol(value, sym) { auto int lp; - auto char *last = sym_array[0].name; + auto char *last; + if (!sym_array) + return((char *) 0); + last = sym_array[0].name; sym->offset = 0; sym->size = 0; if ( value < sym_array[0].value ) diff --git a/ksym_mod.c b/ksym_mod.c index 129b1a5..344963b 100644 --- a/ksym_mod.c +++ b/ksym_mod.c @@ -75,6 +75,9 @@ * Corrected return value of AddModule if /dev/kmem can't be * loaded. This will prevent klogd from segfaulting if /dev/kmem * is not available. Patch from Topi Miettinen . + * + * Tue Sep 12 23:11:13 CEST 2000: Martin Schulze + * Changed llseek() to lseek64() in order to skip a libc warning. */ @@ -91,7 +94,7 @@ #include #else /* __GLIBC__ */ #include -extern loff_t llseek __P ((int __fd, loff_t __offset, int __whence)); +extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence)); extern int get_kernel_syms __P ((struct kernel_sym *__table)); #endif /* __GLIBC__ */ #include @@ -400,7 +403,7 @@ static int AddModule(address, symbol) Syslog(LOG_WARNING, "Error opening /dev/kmem\n"); return(0); } - if ( llseek(memfd, address, SEEK_SET) < 0 ) + if ( lseek64(memfd, address, SEEK_SET) < 0 ) { Syslog(LOG_WARNING, "Error seeking in /dev/kmem\n"); Syslog(LOG_WARNING, "Symbol %s, value %08x\n", symbol, address);