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

35
klogd.c
View File

@ -182,6 +182,15 @@
* call. The old behaveiour could result in klogd being
* recognized as being undead, because it'll only die after a
* 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,
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,
log_buffer[LOG_BUFFER_SIZE];
@ -370,9 +380,11 @@ static void SignalDaemon(sig)
static void ReloadSymbols()
{
if (symbol_lookup) {
if ( reload_symbols > 1 )
InitKsyms(symfile);
InitMsyms();
}
reload_symbols = change_state = 0;
return;
}
@ -497,6 +509,7 @@ extern void Syslog(int priority, char *fmt, ...)
va_end(ap);
fputc('\n', output_file);
fflush(output_file);
if (!one_shot)
fsync(fileno(output_file));
return;
}
@ -611,7 +624,7 @@ 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;
@ -638,7 +651,7 @@ 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;
break;
@ -721,7 +734,8 @@ static void LogLine(char *ptr, int len)
*(line-1) = '>'; /* put back delim */
symbol = LookupSymbol(value, &sym);
if ( symbol == (char *) 0 )
if ( !symbol_lookup || symbol == (char *) 0 )
{
parse_state = PARSING_TEXT;
break;
@ -823,7 +837,7 @@ int main(argc, argv)
*output = (char *) 0;
/* 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)
{
case 'c': /* Set console message level. */
@ -846,7 +860,7 @@ int main(argc, argv)
symfile = optarg;
break;
case 'n': /* don't fork */
NoFork++;
no_fork++;
break;
case 'o': /* One-shot mode. */
one_shot = 1;
@ -860,6 +874,9 @@ int main(argc, argv)
case 'v':
printf("klogd %s-%s\n", VERSION, PATCHLEVEL);
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
* such process running.
*/
if ( (!one_shot) && (!NoFork) )
if ( (!one_shot) && (!no_fork) )
{
if (!check_pid(PidFile))
{
@ -964,8 +981,10 @@ int main(argc, argv)
/* Handle one-shot logging. */
if ( one_shot )
{
if (symbol_lookup) {
InitKsyms(symfile);
InitMsyms();
}
if ( (logsrc = GetKernelLogSrc()) == kernel )
LogKernelLine();
else
@ -978,8 +997,10 @@ int main(argc, argv)
sleep(KLOGD_DELAY);
#endif
logsrc = GetKernelLogSrc();
if (symbol_lookup) {
InitKsyms(symfile);
InitMsyms();
}
/* The main loop. */
while (1)

6
ksym.c
View File

@ -80,6 +80,9 @@
* Fri Jun 13 10:50:23 CST 1997: Martin Schulze
* Changed definition of LookupSymbol to non-static because it is
* 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.
*/
@ -328,6 +331,7 @@ static char * FindSymbolFile()
}
}
if (sym_file) {
/*
* At this point a map file was successfully opened. We
* now need to search this file and look for a version
@ -376,7 +380,7 @@ static char * FindSymbolFile()
return(symfile);
break;
}
}
/*
* 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
* 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__ */
#include <stdarg.h>
#include <paths.h>
#include <linux/version.h>
#include "klogd.h"
#include "ksyms.h"
@ -104,6 +111,9 @@ struct Module
char *name;
struct module module;
#if LINUX_VERSION_CODE >= 0x20112
struct module_info module_info;
#endif
};
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
* name of the module.
*/
#if LINUX_VERSION_CODE < 0x20112
if ( (void *) value >= mp->module.addr &&
(void *) value <= (mp->module.addr + \
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
@ -556,8 +572,13 @@ extern char * LookupModuleSymbol(value, sym)
if ( mp->num_syms > 0 )
{
last = &mp->sym_array[mp->num_syms - 1];
#if LINUX_VERSION_CODE < 0x20112
sym->size = (int) mp->module.addr + \
(mp->module.size * 4096) - value;
#else
sym->size = (int) mp->module_info.addr + \
(mp->module.size * 4096) - value;
#endif
sym->offset = value - last->value;
return(last->name);
}
@ -568,7 +589,11 @@ extern char * LookupModuleSymbol(value, sym)
* faulting address in the module.
*/
sym->size = mp->module.size * 4096;
#if LINUX_VERSION_CODE < 0x20112
sym->offset = (void *) value - mp->module.addr;
#else
sym->offset = value - mp->module_info.addr;
#endif
return(mp->name);
}
}

View File

@ -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
* from binding the socket with the result that no messages were
* 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);
if ( hent )
sprintf(LocalHostName, "%s", hent->h_name);
if ( (p = index(LocalHostName, '.')) )
{
*p++ = '\0';
@ -1536,6 +1541,7 @@ void fprintlog(f, from, flags, msg)
else {
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);
f->f_prevcount = 0;
f->f_type = F_FORW;
goto f_forw;
}
@ -2316,6 +2322,7 @@ void cfline(line, f)
if ( (hp = gethostbyname(p)) == NULL ) {
f->f_type = F_FORW_UNKN;
f->f_prevcount = INET_RETRY_MAX;
f->f_time = time ( (time_t *)0 );
} else {
f->f_type = F_FORW;
}
@ -2399,7 +2406,7 @@ int decode(name, codetab)
{
register struct code *c;
register char *p;
char buf[40];
char buf[80];
dprintf ("symbolic name: %s", name);
if (isdigit(*name))
@ -2407,7 +2414,7 @@ int decode(name, codetab)
dprintf ("\n");
return (atoi(name));
}
(void) strcpy(buf, name);
(void) strncpy(buf, name, 79);
for (p = buf; *p; p++)
if (isupper(*p))
*p = tolower(*p);