* Corrected some code that caused klogd to dump core when receiving some

special messages from 2.1.78.  Thanks to Chu-yeon Park
    <kokids@doit.ajou.ac.kr> for informing me.
  * Fixed bug that caused klogd to die if there is no System.map
    available.
  * Added -x switch to omit EIP translation and System.map evaluation.
    Thanks to Florian La Roche <florian@knorke.saar.de>.
  * Fixed small bugs in F_FORW_UNKN meachanism.  Thanks to Torsten Neumann
    <torsten@londo.rhein-main.de> for pointing me to it.
  * Fixed problem with klogd not being able to be built on a kernel newer
    than 2.1.18.  Worked in a patch from Alessandro Suardi <asuardi@uninetcom.it>
This commit is contained in:
Joey Schulze 1998-01-10 18:02:57 +00:00
parent f1bddb54ec
commit e9b180bb9b
5 changed files with 85 additions and 24 deletions

View File

@ -26,6 +26,7 @@ klogd \- kernel log daemon.
.I fname .I fname
] ]
.RB [ " \-v " ] .RB [ " \-v " ]
.RB [ " \-x " ]
.LP .LP
.SH DESCRIPTION .SH DESCRIPTION
.B klogd .B klogd
@ -76,6 +77,9 @@ Use the specified file as the source of kernel symbol information.
.TP .TP
.B "\-v" .B "\-v"
Print version and exit. Print version and exit.
.TP
.B "\-x"
Omits EIP translation and there doesn't read the System.map.
.LP .LP
.SH OVERVIEW .SH OVERVIEW
The functionality of klogd has been typically incorporated into other The functionality of klogd has been typically incorporated into other

51
klogd.c
View File

@ -182,6 +182,15 @@
* call. The old behaveiour could result in klogd being * call. The old behaveiour could result in klogd being
* recognized as being undead, because it'll only die after a * recognized as being undead, because it'll only die after a
* message has been received. * message has been received.
*
* Fri Jan 9 11:03:48 CET 1998: Martin Schulze <joey@infodrom.north.de>
* Corrected some code that caused klogd to dump core when
* receiving messages containing '%', some of them exist in
* 2.1.78. Thanks to Chu-yeon Park <kokids@doit.ajou.ac.kr> for
* informing me.
*
* Fri Jan 9 23:38:19 CET 1998: Florian La Roche <florian@knorke.saar.de>
* Added -x switch to omit EIP translation and System.map evaluation.
*/ */
@ -230,7 +239,8 @@ static int kmsg,
static int use_syscall = 0, static int use_syscall = 0,
one_shot = 0, one_shot = 0,
NoFork = 0; /* don't fork - don't run in daemon mode */ symbol_lookup = 1,
no_fork = 0; /* don't fork - don't run in daemon mode */
static char *symfile = (char *) 0, static char *symfile = (char *) 0,
log_buffer[LOG_BUFFER_SIZE]; log_buffer[LOG_BUFFER_SIZE];
@ -370,9 +380,11 @@ static void SignalDaemon(sig)
static void ReloadSymbols() static void ReloadSymbols()
{ {
if ( reload_symbols > 1 ) if (symbol_lookup) {
InitKsyms(symfile); if ( reload_symbols > 1 )
InitMsyms(); InitKsyms(symfile);
InitMsyms();
}
reload_symbols = change_state = 0; reload_symbols = change_state = 0;
return; return;
} }
@ -497,7 +509,8 @@ extern void Syslog(int priority, char *fmt, ...)
va_end(ap); va_end(ap);
fputc('\n', output_file); fputc('\n', output_file);
fflush(output_file); fflush(output_file);
fsync(fileno(output_file)); if (!one_shot)
fsync(fileno(output_file));
return; return;
} }
@ -611,7 +624,7 @@ static void LogLine(char *ptr, int len)
fprintf(stderr, "\tLine: %s\n", line); fprintf(stderr, "\tLine: %s\n", line);
} }
Syslog( LOG_INFO, line_buff ); Syslog( LOG_INFO, "%s", line_buff );
line = line_buff; line = line_buff;
space = sizeof(line_buff)-1; space = sizeof(line_buff)-1;
parse_state = PARSING_TEXT; parse_state = PARSING_TEXT;
@ -638,7 +651,7 @@ static void LogLine(char *ptr, int len)
len -= 1; len -= 1;
*line = 0; /* force null terminator */ *line = 0; /* force null terminator */
Syslog( LOG_INFO, line_buff ); Syslog( LOG_INFO, "%s", line_buff );
line = line_buff; line = line_buff;
space = sizeof(line_buff)-1; space = sizeof(line_buff)-1;
break; break;
@ -721,7 +734,8 @@ static void LogLine(char *ptr, int len)
*(line-1) = '>'; /* put back delim */ *(line-1) = '>'; /* put back delim */
symbol = LookupSymbol(value, &sym); symbol = LookupSymbol(value, &sym);
if ( symbol == (char *) 0 ) if ( !symbol_lookup || symbol == (char *) 0 )
{ {
parse_state = PARSING_TEXT; parse_state = PARSING_TEXT;
break; break;
@ -823,7 +837,7 @@ int main(argc, argv)
*output = (char *) 0; *output = (char *) 0;
/* Parse the command-line. */ /* Parse the command-line. */
while ((ch = getopt(argc, argv, "c:df:iIk:nopsv")) != EOF) while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx")) != EOF)
switch((char)ch) switch((char)ch)
{ {
case 'c': /* Set console message level. */ case 'c': /* Set console message level. */
@ -846,7 +860,7 @@ int main(argc, argv)
symfile = optarg; symfile = optarg;
break; break;
case 'n': /* don't fork */ case 'n': /* don't fork */
NoFork++; no_fork++;
break; break;
case 'o': /* One-shot mode. */ case 'o': /* One-shot mode. */
one_shot = 1; one_shot = 1;
@ -860,6 +874,9 @@ int main(argc, argv)
case 'v': case 'v':
printf("klogd %s-%s\n", VERSION, PATCHLEVEL); printf("klogd %s-%s\n", VERSION, PATCHLEVEL);
exit (1); exit (1);
case 'x':
symbol_lookup = 0;
break;
} }
@ -888,7 +905,7 @@ int main(argc, argv)
* not disabled with the command line argument and there's no * not disabled with the command line argument and there's no
* such process running. * such process running.
*/ */
if ( (!one_shot) && (!NoFork) ) if ( (!one_shot) && (!no_fork) )
{ {
if (!check_pid(PidFile)) if (!check_pid(PidFile))
{ {
@ -964,8 +981,10 @@ int main(argc, argv)
/* Handle one-shot logging. */ /* Handle one-shot logging. */
if ( one_shot ) if ( one_shot )
{ {
InitKsyms(symfile); if (symbol_lookup) {
InitMsyms(); InitKsyms(symfile);
InitMsyms();
}
if ( (logsrc = GetKernelLogSrc()) == kernel ) if ( (logsrc = GetKernelLogSrc()) == kernel )
LogKernelLine(); LogKernelLine();
else else
@ -978,8 +997,10 @@ int main(argc, argv)
sleep(KLOGD_DELAY); sleep(KLOGD_DELAY);
#endif #endif
logsrc = GetKernelLogSrc(); logsrc = GetKernelLogSrc();
InitKsyms(symfile); if (symbol_lookup) {
InitMsyms(); InitKsyms(symfile);
InitMsyms();
}
/* The main loop. */ /* The main loop. */
while (1) while (1)

8
ksym.c
View File

@ -80,6 +80,9 @@
* Fri Jun 13 10:50:23 CST 1997: Martin Schulze * Fri Jun 13 10:50:23 CST 1997: Martin Schulze
* Changed definition of LookupSymbol to non-static because it is * Changed definition of LookupSymbol to non-static because it is
* used in klogd.c, too. * used in klogd.c, too.
*
* Fri Jan 9 23:00:08 CET 1998: Martin Schulze <joey@infodrom.north.de>
* Fixed bug that caused klogd to die if there is no System.map available.
*/ */
@ -327,7 +330,8 @@ static char * FindSymbolFile()
continue; continue;
} }
} }
if (sym_file) {
/* /*
* At this point a map file was successfully opened. We * At this point a map file was successfully opened. We
* now need to search this file and look for a version * now need to search this file and look for a version
@ -376,7 +380,7 @@ static char * FindSymbolFile()
return(symfile); return(symfile);
break; break;
} }
}
/* /*
* At this stage of the game we are at the end of the symbol * At this stage of the game we are at the end of the symbol

View File

@ -49,6 +49,12 @@
* *
* Sun Jun 15 16:23:29 MET DST 1997: Michael Alan Dorman * Sun Jun 15 16:23:29 MET DST 1997: Michael Alan Dorman
* Some more glibc patches made by <mdorman@debian.org>. * Some more glibc patches made by <mdorman@debian.org>.
*
* Sat Jan 10 15:00:18 CET 1998: Martin Schulze <joey@infodrom.north.de>
* Fixed problem with klogd not being able to be built on a kernel
* newer than 2.1.18. It was caused by modified structures
* inside the kernel that were included. I have worked in a
* patch from Alessandro Suardi <asuardi@uninetcom.it>.
*/ */
@ -68,6 +74,7 @@
#endif /* __GLIBC__ */ #endif /* __GLIBC__ */
#include <stdarg.h> #include <stdarg.h>
#include <paths.h> #include <paths.h>
#include <linux/version.h>
#include "klogd.h" #include "klogd.h"
#include "ksyms.h" #include "ksyms.h"
@ -104,6 +111,9 @@ struct Module
char *name; char *name;
struct module module; struct module module;
#if LINUX_VERSION_CODE >= 0x20112
struct module_info module_info;
#endif
}; };
static int num_modules = 0; static int num_modules = 0;
@ -535,9 +545,15 @@ extern char * LookupModuleSymbol(value, sym)
* If it is in this range we can at least return the * If it is in this range we can at least return the
* name of the module. * name of the module.
*/ */
#if LINUX_VERSION_CODE < 0x20112
if ( (void *) value >= mp->module.addr && if ( (void *) value >= mp->module.addr &&
(void *) value <= (mp->module.addr + \ (void *) value <= (mp->module.addr + \
mp->module.size * 4096) ) mp->module.size * 4096) )
#else
if ( value >= mp->module_info.addr &&
value <= (mp->module_info.addr + \
mp->module.size * 4096) )
#endif
{ {
/* /*
* A special case needs to be checked for. The above * A special case needs to be checked for. The above
@ -556,8 +572,13 @@ extern char * LookupModuleSymbol(value, sym)
if ( mp->num_syms > 0 ) if ( mp->num_syms > 0 )
{ {
last = &mp->sym_array[mp->num_syms - 1]; last = &mp->sym_array[mp->num_syms - 1];
#if LINUX_VERSION_CODE < 0x20112
sym->size = (int) mp->module.addr + \ sym->size = (int) mp->module.addr + \
(mp->module.size * 4096) - value; (mp->module.size * 4096) - value;
#else
sym->size = (int) mp->module_info.addr + \
(mp->module.size * 4096) - value;
#endif
sym->offset = value - last->value; sym->offset = value - last->value;
return(last->name); return(last->name);
} }
@ -568,7 +589,11 @@ extern char * LookupModuleSymbol(value, sym)
* faulting address in the module. * faulting address in the module.
*/ */
sym->size = mp->module.size * 4096; sym->size = mp->module.size * 4096;
#if LINUX_VERSION_CODE < 0x20112
sym->offset = (void *) value - mp->module.addr; sym->offset = (void *) value - mp->module.addr;
#else
sym->offset = value - mp->module_info.addr;
#endif
return(mp->name); return(mp->name);
} }
} }

View File

@ -208,19 +208,19 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88";
* reception on with the "-r" option. * reception on with the "-r" option.
* *
* Not defining SYSLOG_INET will result in not doing any network * Not defining SYSLOG_INET will result in not doing any network
* activity, i.e. not sending or receiving messages. I changed * activity, i.e. not sending or receiving messages. I changed
* this because the old idea is implemented with the "-r" option * this because the old idea is implemented with the "-r" option
* and the old thing didn't work anyway. * and the old thing didn't work anyway.
* *
* Thu Oct 26 13:14:06 MET 1995: Martin Schulze * Thu Oct 26 13:14:06 MET 1995: Martin Schulze
* Added another logfile type F_FORW_UNKN. The problem I ran into * Added another logfile type F_FORW_UNKN. The problem I ran into
* was a name server that runs on my machine and a forwarder of * was a name server that runs on my machine and a forwarder of
* kern.crit to another host. The hosts address can only be * kern.crit to another host. The hosts address can only be
* fetched using the nameserver. But named is started after * fetched using the nameserver. But named is started after
* syslogd, so syslogd complained. * syslogd, so syslogd complained.
* *
* This logfile type will retry to get the address of the * This logfile type will retry to get the address of the
* hostname ten times and then complain. This should be enough to * hostname ten times and then complain. This should be enough to
* get the named up and running during boot sequence. * get the named up and running during boot sequence.
* *
* Fri Oct 27 14:08:15 1995: Dr. Wettstein * Fri Oct 27 14:08:15 1995: Dr. Wettstein
@ -330,6 +330,10 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88";
* Reworked one line of the above patch as it prevented syslogd * Reworked one line of the above patch as it prevented syslogd
* from binding the socket with the result that no messages were * from binding the socket with the result that no messages were
* forwarded to other hosts. * forwarded to other hosts.
*
* Sat Jan 10 01:33:06 CET 1998: Martin Schulze <joey@infodrom.north.de>
* Fixed small bugs in F_FORW_UNKN meachanism. Thanks to Torsten
* Neumann <torsten@londo.rhein-main.de> for pointing me to it.
*/ */
@ -795,6 +799,7 @@ int main(argc, argv)
hent = gethostbyname(LocalHostName); hent = gethostbyname(LocalHostName);
if ( hent ) if ( hent )
sprintf(LocalHostName, "%s", hent->h_name); sprintf(LocalHostName, "%s", hent->h_name);
if ( (p = index(LocalHostName, '.')) ) if ( (p = index(LocalHostName, '.')) )
{ {
*p++ = '\0'; *p++ = '\0';
@ -1536,6 +1541,7 @@ void fprintlog(f, from, flags, msg)
else { else {
dprintf("%s found, resuming.\n", f->f_un.f_forw.f_hname); dprintf("%s found, resuming.\n", f->f_un.f_forw.f_hname);
bcopy(hp->h_addr, (char *) &f->f_un.f_forw.f_addr.sin_addr, hp->h_length); bcopy(hp->h_addr, (char *) &f->f_un.f_forw.f_addr.sin_addr, hp->h_length);
f->f_prevcount = 0;
f->f_type = F_FORW; f->f_type = F_FORW;
goto f_forw; goto f_forw;
} }
@ -2316,6 +2322,7 @@ void cfline(line, f)
if ( (hp = gethostbyname(p)) == NULL ) { if ( (hp = gethostbyname(p)) == NULL ) {
f->f_type = F_FORW_UNKN; f->f_type = F_FORW_UNKN;
f->f_prevcount = INET_RETRY_MAX; f->f_prevcount = INET_RETRY_MAX;
f->f_time = time ( (time_t *)0 );
} else { } else {
f->f_type = F_FORW; f->f_type = F_FORW;
} }
@ -2399,7 +2406,7 @@ int decode(name, codetab)
{ {
register struct code *c; register struct code *c;
register char *p; register char *p;
char buf[40]; char buf[80];
dprintf ("symbolic name: %s", name); dprintf ("symbolic name: %s", name);
if (isdigit(*name)) if (isdigit(*name))
@ -2407,7 +2414,7 @@ int decode(name, codetab)
dprintf ("\n"); dprintf ("\n");
return (atoi(name)); return (atoi(name));
} }
(void) strcpy(buf, name); (void) strncpy(buf, name, 79);
for (p = buf; *p; p++) for (p = buf; *p; p++)
if (isupper(*p)) if (isupper(*p))
*p = tolower(*p); *p = tolower(*p);