. Use lseek64() instead of llseek() which is deprecated these days

. Keith Owens <kaos@ocs.com.au>
   - 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.
This commit is contained in:
Joey Schulze 2000-09-12 21:15:28 +00:00
parent 955a093c05
commit 2c81663786
5 changed files with 80 additions and 8 deletions

View File

@ -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 <kaos@ocs.com.au>
- 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.

12
klogd.8
View File

@ -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:

54
klogd.c
View File

@ -216,6 +216,18 @@
*
* Sat Aug 21 12:27:02 CEST 1999: Martin Schulze <joey@infodrom.north.de>
* Skip newline when reading in messages.
*
* Tue Sep 12 22:14:33 CEST 2000: Martin Schulze <joey@infodrom.ffis.de>
* Don't feed a buffer directly to a printf-type routine, use
* "%s" as format string instead. Thanks to Jouko Pynnönen
* <jouko@solutions.fi> for pointing this out.
*
* Tue Sep 12 22:44:57 CEST 2000: Martin Schulze <joey@infodrom.ffis.de>
* 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
* <kaos@ocs.com.au> 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;

8
ksym.c
View File

@ -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 <kaos@ocs.com.au>
* 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 )

View File

@ -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 <tom@medialab.sonera.net>.
*
* Tue Sep 12 23:11:13 CEST 2000: Martin Schulze <joey@infodrom.ffis.de>
* Changed llseek() to lseek64() in order to skip a libc warning.
*/
@ -91,7 +94,7 @@
#include <linux/module.h>
#else /* __GLIBC__ */
#include <linux/module.h>
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 <stdarg.h>
@ -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);