Reindent to Linux KNF
Most of the code base seemed to follow Linux style, loosely. This patch brings it all together. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
53c4dd817d
commit
f1f1ee3563
393
src/klogd.c
393
src/klogd.c
@ -255,22 +255,21 @@
|
|||||||
* Remove special treatment of the percent sign.
|
* Remove special treatment of the percent sign.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Includes. */
|
/* Includes. */
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef SYSV
|
#ifdef SYSV
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/msgbuf.h>
|
#include <sys/msgbuf.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <paths.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "klogd.h"
|
#include "klogd.h"
|
||||||
#include "ksyms.h"
|
#include "ksyms.h"
|
||||||
|
#include <paths.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
#include "pidfile.h"
|
#include "pidfile.h"
|
||||||
#endif
|
#endif
|
||||||
@ -292,29 +291,28 @@ static char *PidFile = "/etc/klogd.pid";
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int kmsg,
|
static int kmsg;
|
||||||
change_state = 0,
|
static int change_state = 0;
|
||||||
terminate = 0,
|
static int terminate = 0;
|
||||||
caught_TSTP = 0,
|
static int caught_TSTP = 0;
|
||||||
reload_symbols = 0,
|
static int reload_symbols = 0;
|
||||||
console_log_level = -1;
|
static int console_log_level = -1;
|
||||||
|
|
||||||
static int use_syscall = 0,
|
static int use_syscall = 0;
|
||||||
one_shot = 0,
|
static int one_shot = 0;
|
||||||
symbol_lookup = 1,
|
static int symbol_lookup = 1;
|
||||||
no_fork = 0; /* don't fork - don't run in daemon mode */
|
static int no_fork = 0; /* don't fork - don't run in daemon mode */
|
||||||
|
|
||||||
static char *symfile = (char *) 0,
|
static char *symfile = NULL;
|
||||||
log_buffer[LOG_BUFFER_SIZE];
|
static char log_buffer[LOG_BUFFER_SIZE];
|
||||||
|
|
||||||
static FILE *output_file = (FILE *) 0;
|
static FILE *output_file = NULL;
|
||||||
|
|
||||||
static enum LOGSRC { none, proc, kernel } logsrc;
|
static enum LOGSRC { none, proc, kernel } logsrc;
|
||||||
|
|
||||||
int debugging = 0;
|
int debugging = 0;
|
||||||
int symbols_twice = 0;
|
int symbols_twice = 0;
|
||||||
|
|
||||||
|
|
||||||
/* Function prototypes. */
|
/* Function prototypes. */
|
||||||
extern int ksyslog(int type, char *buf, int len);
|
extern int ksyslog(int type, char *buf, int len);
|
||||||
static void CloseLogSrc(void);
|
static void CloseLogSrc(void);
|
||||||
@ -332,101 +330,72 @@ static void LogKernelLine(void);
|
|||||||
static void LogProcLine(void);
|
static void LogProcLine(void);
|
||||||
extern int main(int argc, char *argv[]);
|
extern int main(int argc, char *argv[]);
|
||||||
|
|
||||||
|
static void CloseLogSrc(void)
|
||||||
static void CloseLogSrc()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Shutdown the log sources. */
|
/* Shutdown the log sources. */
|
||||||
switch ( logsrc )
|
switch (logsrc) {
|
||||||
{
|
|
||||||
case kernel:
|
case kernel:
|
||||||
ksyslog(0, 0, 0);
|
ksyslog(0, 0, 0);
|
||||||
Syslog(LOG_INFO, "Kernel logging (ksyslog) stopped.");
|
Syslog(LOG_INFO, "Kernel logging (ksyslog) stopped.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case proc:
|
case proc:
|
||||||
close(kmsg);
|
close(kmsg);
|
||||||
Syslog(LOG_INFO, "Kernel logging (proc) stopped.");
|
Syslog(LOG_INFO, "Kernel logging (proc) stopped.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case none:
|
case none:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_file != (FILE *)0)
|
if (output_file != (FILE *)0)
|
||||||
fflush(output_file);
|
fflush(output_file);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Signal handler to terminate the parent process.
|
* Signal handler to terminate the parent process.
|
||||||
*/
|
*/
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
void doexit(sig)
|
void doexit(int signo)
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void restart(sig)
|
void restart(int signo)
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
signal(SIGCONT, restart);
|
signal(SIGCONT, restart);
|
||||||
change_state = 1;
|
change_state = 1;
|
||||||
caught_TSTP = 0;
|
caught_TSTP = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop_logging(int signo)
|
||||||
void stop_logging(sig)
|
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
signal(SIGTSTP, stop_logging);
|
signal(SIGTSTP, stop_logging);
|
||||||
change_state = 1;
|
change_state = 1;
|
||||||
caught_TSTP = 1;
|
caught_TSTP = 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop_daemon(int signo)
|
||||||
void stop_daemon(sig)
|
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Terminate();
|
Terminate();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reload_daemon(int signo)
|
||||||
void reload_daemon(sig)
|
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
change_state = 1;
|
change_state = 1;
|
||||||
reload_symbols = 1;
|
reload_symbols = 1;
|
||||||
|
|
||||||
|
if (signo == SIGUSR2) {
|
||||||
if ( sig == SIGUSR2 )
|
|
||||||
{
|
|
||||||
++reload_symbols;
|
++reload_symbols;
|
||||||
signal(SIGUSR2, reload_daemon);
|
signal(SIGUSR2, reload_daemon);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
signal(SIGUSR1, reload_daemon);
|
signal(SIGUSR1, reload_daemon);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Terminate(void)
|
||||||
static void Terminate()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
CloseLogSrc();
|
CloseLogSrc();
|
||||||
Syslog(LOG_INFO, "Kernel log daemon terminating.");
|
Syslog(LOG_INFO, "Kernel log daemon terminating.");
|
||||||
@ -440,24 +409,18 @@ static void Terminate()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SignalDaemon(sig)
|
static void SignalDaemon(int signo)
|
||||||
|
|
||||||
int sig;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
auto int pid = check_pid(PidFile);
|
int pid = check_pid(PidFile);
|
||||||
|
|
||||||
kill(pid, sig);
|
kill(pid, signo);
|
||||||
#else
|
#else
|
||||||
kill(getpid(), sig);
|
kill(getpid(), signo);
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ReloadSymbols(void)
|
||||||
static void ReloadSymbols()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (symbol_lookup) {
|
if (symbol_lookup) {
|
||||||
if (reload_symbols > 1)
|
if (reload_symbols > 1)
|
||||||
@ -465,12 +428,9 @@ static void ReloadSymbols()
|
|||||||
InitMsyms();
|
InitMsyms();
|
||||||
}
|
}
|
||||||
reload_symbols = change_state = 0;
|
reload_symbols = change_state = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ChangeLogging(void)
|
static void ChangeLogging(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Terminate kernel logging. */
|
/* Terminate kernel logging. */
|
||||||
if (terminate == 1)
|
if (terminate == 1)
|
||||||
@ -481,15 +441,13 @@ static void ChangeLogging(void)
|
|||||||
PACKAGE_VERSION);
|
PACKAGE_VERSION);
|
||||||
|
|
||||||
/* Reload symbols. */
|
/* Reload symbols. */
|
||||||
if ( reload_symbols > 0 )
|
if (reload_symbols > 0) {
|
||||||
{
|
|
||||||
ReloadSymbols();
|
ReloadSymbols();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop kernel logging. */
|
/* Stop kernel logging. */
|
||||||
if ( caught_TSTP == 1 )
|
if (caught_TSTP == 1) {
|
||||||
{
|
|
||||||
CloseLogSrc();
|
CloseLogSrc();
|
||||||
logsrc = none;
|
logsrc = none;
|
||||||
change_state = 0;
|
change_state = 0;
|
||||||
@ -504,8 +462,7 @@ static void ChangeLogging(void)
|
|||||||
* kernel log state as to what is causing us to restart. Somewhat
|
* kernel log state as to what is causing us to restart. Somewhat
|
||||||
* groady but it keeps us from creating another static variable.
|
* groady but it keeps us from creating another static variable.
|
||||||
*/
|
*/
|
||||||
if ( logsrc != none )
|
if (logsrc != none) {
|
||||||
{
|
|
||||||
Syslog(LOG_INFO, "Kernel logging re-started after SIGSTOP.");
|
Syslog(LOG_INFO, "Kernel logging re-started after SIGSTOP.");
|
||||||
change_state = 0;
|
change_state = 0;
|
||||||
return;
|
return;
|
||||||
@ -514,21 +471,15 @@ static void ChangeLogging(void)
|
|||||||
/* Restart logging. */
|
/* Restart logging. */
|
||||||
logsrc = GetKernelLogSrc();
|
logsrc = GetKernelLogSrc();
|
||||||
change_state = 0;
|
change_state = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static enum LOGSRC GetKernelLogSrc(void)
|
static enum LOGSRC GetKernelLogSrc(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
auto struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
|
|
||||||
/* Set level of kernel console messaging.. */
|
/* Set level of kernel console messaging.. */
|
||||||
if ( (console_log_level != -1)
|
if ((console_log_level != -1) && (ksyslog(8, NULL, console_log_level) < 0) &&
|
||||||
&& (ksyslog(8, NULL, console_log_level) < 0) && \
|
(errno == EINVAL)) {
|
||||||
(errno == EINVAL) )
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* An invalid arguement error probably indicates that
|
* An invalid arguement error probably indicates that
|
||||||
* a pre-0.14 kernel is being run. At this point we
|
* a pre-0.14 kernel is being run. At this point we
|
||||||
@ -544,20 +495,20 @@ static enum LOGSRC GetKernelLogSrc(void)
|
|||||||
* file system is available to get kernel messages from.
|
* file system is available to get kernel messages from.
|
||||||
*/
|
*/
|
||||||
if (use_syscall ||
|
if (use_syscall ||
|
||||||
((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) )
|
((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT))) {
|
||||||
{
|
|
||||||
/* Initialize kernel logging. */
|
/* Initialize kernel logging. */
|
||||||
ksyslog(1, NULL, 0);
|
ksyslog(1, NULL, 0);
|
||||||
Syslog(LOG_INFO, "klogd v%s, log source = ksyslog "
|
Syslog(LOG_INFO, "klogd v%s, log source = ksyslog "
|
||||||
"started.", PACKAGE_VERSION);
|
"started.",
|
||||||
|
PACKAGE_VERSION);
|
||||||
return (kernel);
|
return (kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
if ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 )
|
if ((kmsg = open(_PATH_KLOG, O_RDONLY)) < 0) {
|
||||||
{
|
fprintf(stderr, "klogd: Cannot open proc file system, "
|
||||||
fprintf(stderr, "klogd: Cannot open proc file system, " \
|
"%d - %s.\n",
|
||||||
"%d - %s.\n", errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
ksyslog(7, NULL, 0);
|
ksyslog(7, NULL, 0);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -570,23 +521,20 @@ static enum LOGSRC GetKernelLogSrc(void)
|
|||||||
return (proc);
|
return (proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void Syslog(int priority, char *fmt, ...)
|
extern void Syslog(int priority, char *fmt, ...)
|
||||||
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *argl;
|
char *argl;
|
||||||
|
|
||||||
if ( debugging )
|
if (debugging) {
|
||||||
{
|
|
||||||
fputs("Logging line:\n", stderr);
|
fputs("Logging line:\n", stderr);
|
||||||
fprintf(stderr, "\tLine: %s\n", fmt);
|
fprintf(stderr, "\tLine: %s\n", fmt);
|
||||||
fprintf(stderr, "\tPriority: %d\n", priority);
|
fprintf(stderr, "\tPriority: %d\n", priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle output to a file. */
|
/* Handle output to a file. */
|
||||||
if ( output_file != (FILE *) 0 )
|
if (output_file != (FILE *)0) {
|
||||||
{
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(output_file, fmt, ap);
|
vfprintf(output_file, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -598,14 +546,11 @@ extern void Syslog(int priority, char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Output using syslog. */
|
/* Output using syslog. */
|
||||||
if (!strcmp(fmt, "%s"))
|
if (!strcmp(fmt, "%s")) {
|
||||||
{
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
argl = va_arg(ap, char *);
|
argl = va_arg(ap, char *);
|
||||||
if (argl[0] == '<' && argl[1] && argl[2] == '>')
|
if (argl[0] == '<' && argl[1] && argl[2] == '>') {
|
||||||
{
|
switch (argl[1]) {
|
||||||
switch ( argl[1] )
|
|
||||||
{
|
|
||||||
case '0':
|
case '0':
|
||||||
priority = LOG_EMERG;
|
priority = LOG_EMERG;
|
||||||
break;
|
break;
|
||||||
@ -647,11 +592,8 @@ extern void Syslog(int priority, char *fmt, ...)
|
|||||||
#ifdef TESTING
|
#ifdef TESTING
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy characters from ptr to line until a char in the delim
|
* Copy characters from ptr to line until a char in the delim
|
||||||
* string is encountered or until min( space, len ) chars have
|
* string is encountered or until min( space, len ) chars have
|
||||||
@ -663,12 +605,13 @@ static int copyin( char *line, int space,
|
|||||||
const char *ptr, int len,
|
const char *ptr, int len,
|
||||||
const char *delim)
|
const char *delim)
|
||||||
{
|
{
|
||||||
auto int i;
|
int i;
|
||||||
auto int count;
|
int count;
|
||||||
|
|
||||||
count = len < space ? len : space;
|
count = len < space ? len : space;
|
||||||
|
|
||||||
for(i=0; i<count && !strchr(delim, *ptr); i++ ) { *line++ = *ptr++; }
|
for (i = 0; i < count && !strchr(delim, *ptr); i++)
|
||||||
|
*line++ = *ptr++;
|
||||||
|
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
@ -709,23 +652,20 @@ static void LogLine(char *ptr, int len)
|
|||||||
|
|
||||||
static char *sym_start; /* points at the '<' of a symbol */
|
static char *sym_start; /* points at the '<' of a symbol */
|
||||||
|
|
||||||
auto int delta = 0; /* number of chars copied */
|
int delta = 0; /* number of chars copied */
|
||||||
auto int symbols_expanded = 0; /* 1 if symbols were expanded */
|
int symbols_expanded = 0; /* 1 if symbols were expanded */
|
||||||
auto int skip_symbol_lookup = 0; /* skip symbol lookup on this pass */
|
int skip_symbol_lookup = 0; /* skip symbol lookup on this pass */
|
||||||
auto char *save_ptr = ptr; /* save start of input line */
|
char *save_ptr = ptr; /* save start of input line */
|
||||||
auto int save_len = len; /* save length at start of input line */
|
int save_len = len; /* save length at start of input line */
|
||||||
|
|
||||||
while( len > 0 )
|
while (len > 0) {
|
||||||
{
|
if (space == 0) { /* line buffer is full */
|
||||||
if( space == 0 ) /* line buffer is full */
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
** Line too long. Start a new line.
|
** Line too long. Start a new line.
|
||||||
*/
|
*/
|
||||||
*line = 0; /* force null terminator */
|
*line = 0; /* force null terminator */
|
||||||
|
|
||||||
if ( debugging )
|
if (debugging) {
|
||||||
{
|
|
||||||
fputs("Line buffer full:\n", stderr);
|
fputs("Line buffer full:\n", stderr);
|
||||||
fprintf(stderr, "\tLine: %s\n", line);
|
fprintf(stderr, "\tLine: %s\n", line);
|
||||||
}
|
}
|
||||||
@ -740,8 +680,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
save_len = len;
|
save_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( parse_state )
|
switch (parse_state) {
|
||||||
{
|
|
||||||
case PARSING_TEXT:
|
case PARSING_TEXT:
|
||||||
delta = copyin(line, space, ptr, len, "\n[");
|
delta = copyin(line, space, ptr, len, "\n[");
|
||||||
line += delta;
|
line += delta;
|
||||||
@ -750,12 +689,9 @@ static void LogLine(char *ptr, int len)
|
|||||||
len -= delta;
|
len -= delta;
|
||||||
|
|
||||||
if (space == 0 || len == 0)
|
if (space == 0 || len == 0)
|
||||||
{
|
|
||||||
break; /* full line_buff or end of input buffer */
|
break; /* full line_buff or end of input buffer */
|
||||||
}
|
|
||||||
|
|
||||||
if( *ptr == '\0' ) /* zero byte */
|
if (*ptr == '\0') { /* zero byte */
|
||||||
{
|
|
||||||
ptr++; /* skip zero byte */
|
ptr++; /* skip zero byte */
|
||||||
space -= 1;
|
space -= 1;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
@ -763,8 +699,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *ptr == '\n' ) /* newline */
|
if (*ptr == '\n') { /* newline */
|
||||||
{
|
|
||||||
ptr++; /* skip newline */
|
ptr++; /* skip newline */
|
||||||
space -= 1;
|
space -= 1;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
@ -780,9 +715,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
skip_symbol_lookup = 1;
|
skip_symbol_lookup = 1;
|
||||||
ptr = save_ptr;
|
ptr = save_ptr;
|
||||||
len = save_len;
|
len = save_len;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
skip_symbol_lookup = 0;
|
skip_symbol_lookup = 0;
|
||||||
save_ptr = ptr;
|
save_ptr = ptr;
|
||||||
save_len = len;
|
save_len = len;
|
||||||
@ -790,8 +723,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( *ptr == '[' ) /* possible kernel symbol */
|
if (*ptr == '[') { /* possible kernel symbol */
|
||||||
{
|
|
||||||
*line++ = *ptr++;
|
*line++ = *ptr++;
|
||||||
space -= 1;
|
space -= 1;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
@ -802,8 +734,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PARSING_SYMSTART:
|
case PARSING_SYMSTART:
|
||||||
if( *ptr != '<' )
|
if (*ptr != '<') {
|
||||||
{
|
|
||||||
parse_state = PARSING_TEXT; /* not a symbol */
|
parse_state = PARSING_TEXT; /* not a symbol */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -813,7 +744,6 @@ static void LogLine(char *ptr, int len)
|
|||||||
** be a valid symbol, this char will be replaced later.
|
** be a valid symbol, this char will be replaced later.
|
||||||
** If not, we'll just leave it there.
|
** If not, we'll just leave it there.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sym_start = line; /* this will point at the '<' */
|
sym_start = line; /* this will point at the '<' */
|
||||||
|
|
||||||
*line++ = *ptr++;
|
*line++ = *ptr++;
|
||||||
@ -829,11 +759,9 @@ static void LogLine(char *ptr, int len)
|
|||||||
space -= delta;
|
space -= delta;
|
||||||
len -= delta;
|
len -= delta;
|
||||||
if (space == 0 || len == 0)
|
if (space == 0 || len == 0)
|
||||||
{
|
|
||||||
break; /* full line_buff or end of input buffer */
|
break; /* full line_buff or end of input buffer */
|
||||||
}
|
|
||||||
if( *ptr != '>' )
|
if (*ptr != '>') {
|
||||||
{
|
|
||||||
parse_state = PARSING_TEXT;
|
parse_state = PARSING_TEXT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -843,12 +771,10 @@ static void LogLine(char *ptr, int len)
|
|||||||
len -= 1;
|
len -= 1;
|
||||||
|
|
||||||
parse_state = PARSING_SYMEND;
|
parse_state = PARSING_SYMEND;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PARSING_SYMEND:
|
case PARSING_SYMEND:
|
||||||
if( *ptr != ']' )
|
if (*ptr != ']') {
|
||||||
{
|
|
||||||
parse_state = PARSING_TEXT; /* not a symbol */
|
parse_state = PARSING_TEXT; /* not a symbol */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -858,19 +784,17 @@ static void LogLine(char *ptr, int len)
|
|||||||
** symbol text.
|
** symbol text.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
auto int sym_space;
|
|
||||||
|
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
auto struct symbol sym;
|
struct symbol sym;
|
||||||
auto char *symbol;
|
char *symbol;
|
||||||
|
int sym_space;
|
||||||
|
|
||||||
*(line - 1) = 0; /* null terminate the address string */
|
*(line - 1) = 0; /* null terminate the address string */
|
||||||
value = strtoul(sym_start + 1, (char **)0, 16);
|
value = strtoul(sym_start + 1, (char **)0, 16);
|
||||||
*(line - 1) = '>'; /* put back delim */
|
*(line - 1) = '>'; /* put back delim */
|
||||||
|
|
||||||
symbol = LookupSymbol(value, &sym);
|
symbol = LookupSymbol(value, &sym);
|
||||||
if ( !symbol_lookup || symbol == (char *) 0 )
|
if (!symbol_lookup || symbol == (char *)0) {
|
||||||
{
|
|
||||||
parse_state = PARSING_TEXT;
|
parse_state = PARSING_TEXT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -879,8 +803,7 @@ static void LogLine(char *ptr, int len)
|
|||||||
** verify there is room in the line buffer
|
** verify there is room in the line buffer
|
||||||
*/
|
*/
|
||||||
sym_space = space + (line - sym_start);
|
sym_space = space + (line - sym_start);
|
||||||
if( sym_space < strlen(symbol) + 30 ) /*(30 should be overkill)*/
|
if (sym_space < strlen(symbol) + 30) { /*(30 should be overkill)*/
|
||||||
{
|
|
||||||
parse_state = PARSING_TEXT; /* not enough space */
|
parse_state = PARSING_TEXT; /* not enough space */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -899,18 +822,14 @@ static void LogLine(char *ptr, int len)
|
|||||||
|
|
||||||
default: /* Can't get here! */
|
default: /* Can't get here! */
|
||||||
parse_state = PARSING_TEXT;
|
parse_state = PARSING_TEXT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LogKernelLine(void)
|
static void LogKernelLine(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int rdcnt;
|
int rdcnt;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Zero-fill the log buffer. This should cure a multitude of
|
* Zero-fill the log buffer. This should cure a multitude of
|
||||||
@ -919,23 +838,21 @@ static void LogKernelLine(void)
|
|||||||
* messages into this fresh buffer.
|
* messages into this fresh buffer.
|
||||||
*/
|
*/
|
||||||
memset(log_buffer, '\0', sizeof(log_buffer));
|
memset(log_buffer, '\0', sizeof(log_buffer));
|
||||||
if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer)-1)) < 0 )
|
if ((rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer) - 1)) < 0) {
|
||||||
{
|
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
return;
|
return;
|
||||||
fprintf(stderr, "klogd: Error return from sys_sycall: " \
|
fprintf(stderr,
|
||||||
"%d - %s\n", errno, strerror(errno));
|
"klogd: Error return from sys_sycall: %d - %s\n",
|
||||||
}
|
errno, strerror(errno));
|
||||||
else
|
|
||||||
LogLine(log_buffer, rdcnt);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogLine(log_buffer, rdcnt);
|
||||||
|
}
|
||||||
|
|
||||||
static void LogProcLine(void)
|
static void LogProcLine(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int rdcnt;
|
int rdcnt;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Zero-fill the log buffer. This should cure a multitude of
|
* Zero-fill the log buffer. This should cure a multitude of
|
||||||
@ -944,19 +861,16 @@ static void LogProcLine(void)
|
|||||||
* from the message pseudo-file into this fresh buffer.
|
* from the message pseudo-file into this fresh buffer.
|
||||||
*/
|
*/
|
||||||
memset(log_buffer, '\0', sizeof(log_buffer));
|
memset(log_buffer, '\0', sizeof(log_buffer));
|
||||||
if ( (rdcnt = read(kmsg, log_buffer, sizeof(log_buffer)-1)) < 0 )
|
if ((rdcnt = read(kmsg, log_buffer, sizeof(log_buffer) - 1)) < 0) {
|
||||||
{
|
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
return;
|
return;
|
||||||
Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", \
|
Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
}
|
|
||||||
else
|
|
||||||
LogLine(log_buffer, rdcnt);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogLine(log_buffer, rdcnt);
|
||||||
|
}
|
||||||
|
|
||||||
int usage(int code)
|
int usage(int code)
|
||||||
{
|
{
|
||||||
@ -980,95 +894,101 @@ int usage(int code)
|
|||||||
" -v Show program version and exit\n"
|
" -v Show program version and exit\n"
|
||||||
" -x Omit EIP translation, i.e. do not read System.map file\n"
|
" -x Omit EIP translation, i.e. do not read System.map file\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Bug report address: %s\n", PACKAGE_BUGREPORT);
|
"Bug report address: %s\n",
|
||||||
|
PACKAGE_BUGREPORT);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
int main(argc, argv)
|
|
||||||
|
|
||||||
int argc;
|
|
||||||
|
|
||||||
char *argv[];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int ch,
|
char *log_level = NULL;
|
||||||
use_output = 0;
|
char *output = NULL;
|
||||||
|
int use_output = 0;
|
||||||
auto char *log_level = (char *) 0,
|
int ch;
|
||||||
*output = (char *) 0;
|
|
||||||
|
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
pid_t ppid = getpid();
|
pid_t ppid = getpid();
|
||||||
|
|
||||||
chdir("/");
|
chdir("/");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Parse the command-line. */
|
/* Parse the command-line. */
|
||||||
while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF)
|
while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF) {
|
||||||
switch((char)ch)
|
switch (ch) {
|
||||||
{
|
|
||||||
case '2': /* Print lines with symbols twice. */
|
case '2': /* Print lines with symbols twice. */
|
||||||
symbols_twice = 1;
|
symbols_twice = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* Set console message level. */
|
case 'c': /* Set console message level. */
|
||||||
log_level = optarg;
|
log_level = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd': /* Activity debug mode. */
|
case 'd': /* Activity debug mode. */
|
||||||
debugging = 1;
|
debugging = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f': /* Define an output file. */
|
case 'f': /* Define an output file. */
|
||||||
output = optarg;
|
output = optarg;
|
||||||
use_output++;
|
use_output++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i': /* Reload module symbols. */
|
case 'i': /* Reload module symbols. */
|
||||||
SignalDaemon(SIGUSR1);
|
SignalDaemon(SIGUSR1);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
SignalDaemon(SIGUSR2);
|
SignalDaemon(SIGUSR2);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
case 'k': /* Kernel symbol file. */
|
case 'k': /* Kernel symbol file. */
|
||||||
symfile = optarg;
|
symfile = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n': /* don't fork */
|
case 'n': /* don't fork */
|
||||||
no_fork++;
|
no_fork++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o': /* One-shot mode. */
|
case 'o': /* One-shot mode. */
|
||||||
one_shot = 1;
|
one_shot = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
SetParanoiaLevel(1); /* Load symbols on oops. */
|
SetParanoiaLevel(1); /* Load symbols on oops. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': /* Use syscall interface. */
|
case 's': /* Use syscall interface. */
|
||||||
use_syscall = 1;
|
use_syscall = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("klogd v%s\n", VERSION);
|
printf("klogd v%s\n", VERSION);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
symbol_lookup = 0;
|
symbol_lookup = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
usage(0);
|
usage(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(1);
|
usage(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set console logging level. */
|
/* Set console logging level. */
|
||||||
if ( log_level != (char *) 0 )
|
if (log_level != (char *)0) {
|
||||||
{
|
if ((strlen(log_level) > 1) ||
|
||||||
if ( (strlen(log_level) > 1) || \
|
(strchr("12345678", *log_level) == (char *)0)) {
|
||||||
(strchr("12345678", *log_level) == (char *) 0) )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "klogd: Invalid console logging "
|
fprintf(stderr, "klogd: Invalid console logging "
|
||||||
"level <%s> specified.\n", log_level);
|
"level <%s> specified.\n",
|
||||||
|
log_level);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
console_log_level = *log_level - '0';
|
console_log_level = *log_level - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
/*
|
/*
|
||||||
* The following code allows klogd to auto-background itself.
|
* The following code allows klogd to auto-background itself.
|
||||||
@ -1081,21 +1001,17 @@ 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) && (!no_fork) )
|
if ((!one_shot) && (!no_fork)) {
|
||||||
{
|
if (!check_pid(PidFile)) {
|
||||||
if (!check_pid(PidFile))
|
|
||||||
{
|
|
||||||
signal(SIGTERM, doexit);
|
signal(SIGTERM, doexit);
|
||||||
if ( fork() == 0 )
|
if (fork() == 0) {
|
||||||
{
|
|
||||||
auto int fl;
|
|
||||||
int num_fds = getdtablesize();
|
int num_fds = getdtablesize();
|
||||||
|
int fl;
|
||||||
|
|
||||||
signal(SIGTERM, SIG_DFL);
|
signal(SIGTERM, SIG_DFL);
|
||||||
|
|
||||||
/* This is the child closing its file descriptors. */
|
/* This is the child closing its file descriptors. */
|
||||||
for (fl= 0; fl <= num_fds; ++fl)
|
for (fl = 0; fl <= num_fds; ++fl) {
|
||||||
{
|
|
||||||
if (fileno(stdout) == fl && use_output)
|
if (fileno(stdout) == fl && use_output)
|
||||||
if (strcmp(output, "-") == 0)
|
if (strcmp(output, "-") == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -1103,9 +1019,7 @@ int main(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Parent process
|
* Parent process
|
||||||
*/
|
*/
|
||||||
@ -1115,23 +1029,17 @@ int main(argc, argv)
|
|||||||
*/
|
*/
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fputs("klogd: Already running.\n", stderr);
|
fputs("klogd: Already running.\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* tuck my process id away */
|
/* tuck my process id away */
|
||||||
if (!check_pid(PidFile))
|
if (!check_pid(PidFile)) {
|
||||||
{
|
|
||||||
if (!write_pid(PidFile))
|
if (!write_pid(PidFile))
|
||||||
Terminate();
|
Terminate();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fputs("klogd: Already running.\n", stderr);
|
fputs("klogd: Already running.\n", stderr);
|
||||||
Terminate();
|
Terminate();
|
||||||
}
|
}
|
||||||
@ -1149,26 +1057,21 @@ int main(argc, argv)
|
|||||||
signal(SIGUSR1, reload_daemon);
|
signal(SIGUSR1, reload_daemon);
|
||||||
signal(SIGUSR2, reload_daemon);
|
signal(SIGUSR2, reload_daemon);
|
||||||
|
|
||||||
|
|
||||||
/* Open outputs. */
|
/* Open outputs. */
|
||||||
if ( use_output )
|
if (use_output) {
|
||||||
{
|
|
||||||
if (strcmp(output, "-") == 0)
|
if (strcmp(output, "-") == 0)
|
||||||
output_file = stdout;
|
output_file = stdout;
|
||||||
else if ( (output_file = fopen(output, "w")) == (FILE *) 0 )
|
else if ((output_file = fopen(output, "w")) == (FILE *)0) {
|
||||||
{
|
fprintf(stderr, "klogd: Cannot open output file "
|
||||||
fprintf(stderr, "klogd: Cannot open output file " \
|
"%s - %s\n",
|
||||||
"%s - %s\n", output, strerror(errno));
|
output, strerror(errno));
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
openlog("kernel", 0, LOG_KERN);
|
openlog("kernel", 0, LOG_KERN);
|
||||||
|
|
||||||
|
|
||||||
/* Handle one-shot logging. */
|
/* Handle one-shot logging. */
|
||||||
if ( one_shot )
|
if (one_shot) {
|
||||||
{
|
|
||||||
if (symbol_lookup) {
|
if (symbol_lookup) {
|
||||||
InitKsyms(symfile);
|
InitKsyms(symfile);
|
||||||
InitMsyms();
|
InitMsyms();
|
||||||
@ -1196,18 +1099,19 @@ int main(argc, argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The main loop. */
|
/* The main loop. */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
if (change_state)
|
if (change_state)
|
||||||
ChangeLogging();
|
ChangeLogging();
|
||||||
switch ( logsrc )
|
|
||||||
{
|
switch (logsrc) {
|
||||||
case kernel:
|
case kernel:
|
||||||
LogKernelLine();
|
LogKernelLine();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case proc:
|
case proc:
|
||||||
LogProcLine();
|
LogProcLine();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case none:
|
case none:
|
||||||
pause();
|
pause();
|
||||||
break;
|
break;
|
||||||
@ -1216,9 +1120,8 @@ int main(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local variables:
|
* Local Variables:
|
||||||
* c-indent-level: 8
|
* indent-tabs-mode: t
|
||||||
* c-basic-offset: 8
|
* c-file-style: "linux"
|
||||||
* tab-width: 8
|
|
||||||
* End:
|
* End:
|
||||||
*/
|
*/
|
||||||
|
36
src/klogd.h
36
src/klogd.h
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
klogd.h - main header file for Linux kernel log daemon.
|
* klogd.h - main header file for Linux kernel log daemon.
|
||||||
Copyright (c) 1995 Dr. G.W. Wettstein <greg@wind.rmcc.com>
|
* Copyright (c) 1995 Dr. G.W. Wettstein <greg@wind.rmcc.com>
|
||||||
|
*
|
||||||
This file is part of the sysklogd package, a kernel and system log daemon.
|
* This file is part of the sysklogd package, a kernel and system log daemon.
|
||||||
|
*
|
||||||
This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
310
src/ksym.c
310
src/ksym.c
@ -125,18 +125,16 @@
|
|||||||
* the first hit.
|
* the first hit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Includes. */
|
/* Includes. */
|
||||||
#include <stdlib.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <sys/utsname.h>
|
|
||||||
#include "klogd.h"
|
#include "klogd.h"
|
||||||
#include "ksyms.h"
|
#include "ksyms.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#define VERBOSE_DEBUGGING 0
|
#define VERBOSE_DEBUGGING 0
|
||||||
|
|
||||||
|
|
||||||
int num_syms = 0;
|
int num_syms = 0;
|
||||||
static int i_am_paranoid = 0;
|
static int i_am_paranoid = 0;
|
||||||
static char vstring[12];
|
static char vstring[12];
|
||||||
@ -153,14 +151,12 @@ static char *system_maps[] =
|
|||||||
(char *)0
|
(char *)0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if defined(TEST)
|
#if defined(TEST)
|
||||||
int debugging;
|
int debugging;
|
||||||
#else
|
#else
|
||||||
extern int debugging;
|
extern int debugging;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Function prototypes. */
|
/* Function prototypes. */
|
||||||
static char *FindSymbolFile(void);
|
static char *FindSymbolFile(void);
|
||||||
static int AddSymbol(unsigned long, char *);
|
static int AddSymbol(unsigned long, char *);
|
||||||
@ -168,7 +164,6 @@ static void FreeSymbols(void);
|
|||||||
static int CheckVersion(char *);
|
static int CheckVersion(char *);
|
||||||
static int CheckMapVersion(char *);
|
static int CheckMapVersion(char *);
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: InitKsyms
|
* Function: InitKsyms
|
||||||
*
|
*
|
||||||
@ -186,34 +181,23 @@ static int CheckMapVersion(char *);
|
|||||||
* A boolean style context is returned. The return value will
|
* A boolean style context is returned. The return value will
|
||||||
* be true if initialization was successful. False if not.
|
* be true if initialization was successful. False if not.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
int InitKsyms(char *mapfile)
|
||||||
extern int InitKsyms(mapfile)
|
|
||||||
|
|
||||||
char *mapfile;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto char type,
|
unsigned long int address;
|
||||||
sym[512];
|
FILE *sym_file;
|
||||||
|
char sym[512];
|
||||||
auto int version = 0;
|
char type;
|
||||||
|
int version = 0;
|
||||||
auto unsigned long int address;
|
|
||||||
|
|
||||||
auto FILE *sym_file;
|
|
||||||
|
|
||||||
|
|
||||||
/* Check and make sure that we are starting with a clean slate. */
|
/* Check and make sure that we are starting with a clean slate. */
|
||||||
if (num_syms > 0)
|
if (num_syms > 0)
|
||||||
FreeSymbols();
|
FreeSymbols();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for and open the file containing the kernel symbols.
|
* Search for and open the file containing the kernel symbols.
|
||||||
*/
|
*/
|
||||||
if ( mapfile == (char *) 0 )
|
if (mapfile == NULL) {
|
||||||
{
|
if ((mapfile = FindSymbolFile()) == NULL) {
|
||||||
if ( (mapfile = FindSymbolFile()) == (char *) 0 )
|
|
||||||
{
|
|
||||||
Syslog(LOG_WARNING, "Cannot find a map file.");
|
Syslog(LOG_WARNING, "Cannot find a map file.");
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fputs("Cannot find a map file.\n", stderr);
|
fputs("Cannot find a map file.\n", stderr);
|
||||||
@ -221,8 +205,7 @@ extern int InitKsyms(mapfile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 )
|
if ((sym_file = fopen(mapfile, "r")) == NULL) {
|
||||||
{
|
|
||||||
Syslog(LOG_WARNING, "Cannot open map file: %s.", mapfile);
|
Syslog(LOG_WARNING, "Cannot open map file: %s.", mapfile);
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Cannot open map file: %s.\n", mapfile);
|
fprintf(stderr, "Cannot open map file: %s.\n", mapfile);
|
||||||
@ -237,11 +220,8 @@ extern int InitKsyms(mapfile)
|
|||||||
* e-mail me a diff containing a parser with suitable political
|
* e-mail me a diff containing a parser with suitable political
|
||||||
* correctness -- GW.
|
* correctness -- GW.
|
||||||
*/
|
*/
|
||||||
while ( !feof(sym_file) )
|
while (!feof(sym_file)) {
|
||||||
{
|
if (fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym) != 3) {
|
||||||
if ( fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym)
|
|
||||||
!= 3 )
|
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Error in symbol table input (#1).");
|
Syslog(LOG_ERR, "Error in symbol table input (#1).");
|
||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
return (0);
|
return (0);
|
||||||
@ -250,8 +230,7 @@ extern int InitKsyms(mapfile)
|
|||||||
fprintf(stderr, "Address: %lx, Type: %c, Symbol: %s\n",
|
fprintf(stderr, "Address: %lx, Type: %c, Symbol: %s\n",
|
||||||
address, type, sym);
|
address, type, sym);
|
||||||
|
|
||||||
if ( AddSymbol(address, sym) == 0 )
|
if (AddSymbol(address, sym) == 0) {
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
|
Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
|
||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
return (0);
|
return (0);
|
||||||
@ -261,17 +240,15 @@ extern int InitKsyms(mapfile)
|
|||||||
version = CheckVersion(sym);
|
version = CheckVersion(sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
|
Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
|
||||||
switch ( version )
|
switch (version) {
|
||||||
{
|
|
||||||
case -1:
|
case -1:
|
||||||
Syslog(LOG_WARNING, "Symbols do not match kernel version.");
|
Syslog(LOG_WARNING, "Symbols do not match kernel version.");
|
||||||
num_syms = 0;
|
num_syms = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
Syslog(LOG_WARNING, "Cannot verify that symbols match " \
|
Syslog(LOG_WARNING, "Cannot verify that symbols match "
|
||||||
"kernel version.");
|
"kernel version.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -284,7 +261,6 @@ extern int InitKsyms(mapfile)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: FindSymbolFile
|
* Function: FindSymbolFile
|
||||||
*
|
*
|
||||||
@ -317,20 +293,15 @@ extern int InitKsyms(mapfile)
|
|||||||
* caller which points to the name of the file containing
|
* caller which points to the name of the file containing
|
||||||
* the symbol table to be used.
|
* the symbol table to be used.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static char *FindSymbolFile(void)
|
||||||
static char * FindSymbolFile()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto char *file = (char *) 0,
|
|
||||||
**mf = system_maps;
|
|
||||||
|
|
||||||
auto struct utsname utsname;
|
|
||||||
static char symfile[100];
|
static char symfile[100];
|
||||||
|
struct utsname utsname;
|
||||||
|
FILE *sym_file = NULL;
|
||||||
|
char **mf = system_maps;
|
||||||
|
char *file = NULL;
|
||||||
|
|
||||||
auto FILE *sym_file = (FILE *) 0;
|
if (uname(&utsname) < 0) {
|
||||||
|
|
||||||
if ( uname(&utsname) < 0 )
|
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -338,8 +309,7 @@ static char * FindSymbolFile()
|
|||||||
if (debugging)
|
if (debugging)
|
||||||
fputs("Searching for symbol map.\n", stderr);
|
fputs("Searching for symbol map.\n", stderr);
|
||||||
|
|
||||||
for (mf = system_maps; *mf != (char *) 0 && file == (char *) 0; ++mf)
|
for (mf = system_maps; *mf != (char *)0 && file == (char *)0; ++mf) {
|
||||||
{
|
|
||||||
|
|
||||||
sprintf(symfile, "%s-%s", *mf, utsname.release);
|
sprintf(symfile, "%s-%s", *mf, utsname.release);
|
||||||
if (debugging)
|
if (debugging)
|
||||||
@ -359,7 +329,6 @@ static char * FindSymbolFile()
|
|||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -371,7 +340,6 @@ static char * FindSymbolFile()
|
|||||||
return (file);
|
return (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: CheckVersion
|
* Function: CheckVersion
|
||||||
*
|
*
|
||||||
@ -408,25 +376,17 @@ static char * FindSymbolFile()
|
|||||||
* 1:-> The executing kernel is of the same version
|
* 1:-> The executing kernel is of the same version
|
||||||
* as the version string.
|
* as the version string.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static int CheckVersion(char *version)
|
||||||
static int CheckVersion(version)
|
|
||||||
|
|
||||||
char *version;
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int vnum,
|
|
||||||
major,
|
|
||||||
minor,
|
|
||||||
patch;
|
|
||||||
|
|
||||||
#ifndef TESTING
|
|
||||||
int kvnum;
|
|
||||||
auto struct utsname utsname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char *prefix = { "Version_" };
|
static char *prefix = { "Version_" };
|
||||||
|
int vnum;
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int patch;
|
||||||
|
#ifndef TESTING
|
||||||
|
struct utsname utsname;
|
||||||
|
int kvnum;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Early return if there is no hope. */
|
/* Early return if there is no hope. */
|
||||||
if (strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ ||
|
if (strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ ||
|
||||||
@ -436,7 +396,6 @@ static int CheckVersion(version)
|
|||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since the symbol looks like a kernel version we can start
|
* Since the symbol looks like a kernel version we can start
|
||||||
* things out by decoding the version string into its component
|
* things out by decoding the version string into its component
|
||||||
@ -447,9 +406,11 @@ static int CheckVersion(version)
|
|||||||
minor = (vnum >> 8) & 0x000000FF;
|
minor = (vnum >> 8) & 0x000000FF;
|
||||||
major = (vnum >> 16) & 0x000000FF;
|
major = (vnum >> 16) & 0x000000FF;
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Version string = %s, Major = %d, " \
|
fprintf(stderr, "Version string = %s, Major = %d, "
|
||||||
"Minor = %d, Patch = %d.\n", version +
|
"Minor = %d, Patch = %d.\n",
|
||||||
strlen(prefix), major, minor, \
|
version +
|
||||||
|
strlen(prefix),
|
||||||
|
major, minor,
|
||||||
patch);
|
patch);
|
||||||
sprintf(vstring, "%d.%d.%d", major, minor, patch);
|
sprintf(vstring, "%d.%d.%d", major, minor, patch);
|
||||||
|
|
||||||
@ -461,17 +422,15 @@ static int CheckVersion(version)
|
|||||||
* values to determine if our system map matches the kernel
|
* values to determine if our system map matches the kernel
|
||||||
* version level.
|
* version level.
|
||||||
*/
|
*/
|
||||||
if ( uname(&utsname) < 0 )
|
if (uname(&utsname) < 0) {
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
Syslog(LOG_ERR, "Cannot get kernel version information.");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Comparing kernel %s with symbol table %s.\n",\
|
fprintf(stderr, "Comparing kernel %s with symbol table %s.\n",
|
||||||
utsname.release, vstring);
|
utsname.release, vstring);
|
||||||
|
|
||||||
if ( sscanf (utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3 )
|
if (sscanf(utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3) {
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Kernel send bogus release string `%s'.",
|
Syslog(LOG_ERR, "Kernel send bogus release string `%s'.",
|
||||||
utsname.release);
|
utsname.release);
|
||||||
return (0);
|
return (0);
|
||||||
@ -489,7 +448,6 @@ static int CheckVersion(version)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: CheckMapVersion
|
* Function: CheckMapVersion
|
||||||
*
|
*
|
||||||
@ -514,18 +472,13 @@ static int CheckVersion(version)
|
|||||||
* 1:-> The executing kernel is of the same version
|
* 1:-> The executing kernel is of the same version
|
||||||
* as the version of the map file.
|
* as the version of the map file.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static int CheckMapVersion(char *fname)
|
||||||
static int CheckMapVersion(fname)
|
|
||||||
|
|
||||||
char *fname;
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int version;
|
unsigned long int address;
|
||||||
FILE *sym_file;
|
FILE *sym_file;
|
||||||
auto unsigned long int address;
|
char sym[512];
|
||||||
auto char type,
|
char type;
|
||||||
sym[512];
|
int version;
|
||||||
|
|
||||||
if ((sym_file = fopen(fname, "r")) != (FILE *)0) {
|
if ((sym_file = fopen(fname, "r")) != (FILE *)0) {
|
||||||
/*
|
/*
|
||||||
@ -536,38 +489,36 @@ static int CheckMapVersion(fname)
|
|||||||
Syslog(LOG_INFO, "Inspecting %s", fname);
|
Syslog(LOG_INFO, "Inspecting %s", fname);
|
||||||
|
|
||||||
version = 0;
|
version = 0;
|
||||||
while ( !feof(sym_file) && (version == 0) )
|
while (!feof(sym_file) && (version == 0)) {
|
||||||
{
|
if (fscanf(sym_file, "%lx %c %511s\n", &address,
|
||||||
if ( fscanf(sym_file, "%lx %c %511s\n", &address, \
|
&type, sym) != 3) {
|
||||||
&type, sym) != 3 )
|
|
||||||
{
|
|
||||||
Syslog(LOG_ERR, "Error in symbol table input (#2).");
|
Syslog(LOG_ERR, "Error in symbol table input (#2).");
|
||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (VERBOSE_DEBUGGING && debugging)
|
if (VERBOSE_DEBUGGING && debugging)
|
||||||
fprintf(stderr, "Address: %lx, Type: %c, " \
|
fprintf(stderr, "Address: %lx, Type: %c, "
|
||||||
"Symbol: %s\n", address, type, sym);
|
"Symbol: %s\n",
|
||||||
|
address, type, sym);
|
||||||
|
|
||||||
version = CheckVersion(sym);
|
version = CheckVersion(sym);
|
||||||
}
|
}
|
||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
|
|
||||||
switch ( version )
|
switch (version) {
|
||||||
{
|
|
||||||
case -1:
|
case -1:
|
||||||
Syslog(LOG_ERR, "Symbol table has incorrect " \
|
Syslog(LOG_ERR, "Symbol table has incorrect "
|
||||||
"version number.\n");
|
"version number.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "No version information " \
|
fprintf(stderr, "No version information "
|
||||||
"found.\n");
|
"found.\n");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Found table with " \
|
fprintf(stderr, "Found table with "
|
||||||
"matching version number.\n");
|
"matching version number.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -578,7 +529,6 @@ static int CheckMapVersion(fname)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: AddSymbol
|
* Function: AddSymbol
|
||||||
*
|
*
|
||||||
@ -592,24 +542,16 @@ static int CheckMapVersion(fname)
|
|||||||
* A boolean value is assumed. True if the addition is
|
* A boolean value is assumed. True if the addition is
|
||||||
* successful. False if not.
|
* successful. False if not.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static int AddSymbol(unsigned long address, char *symbol)
|
||||||
static int AddSymbol(address, symbol)
|
|
||||||
|
|
||||||
unsigned long address;
|
|
||||||
|
|
||||||
char *symbol;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Allocate the the symbol table entry. */
|
/* Allocate the the symbol table entry. */
|
||||||
sym_array = (struct sym_table *) realloc(sym_array, (num_syms+1) * \
|
sym_array = realloc(sym_array, (num_syms + 1) * sizeof(struct sym_table));
|
||||||
sizeof(struct sym_table));
|
if (sym_array == NULL)
|
||||||
if ( sym_array == (struct sym_table *) 0 )
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/* Then the space for the symbol. */
|
/* Then the space for the symbol. */
|
||||||
sym_array[num_syms].name = (char *) malloc(strlen(symbol)*sizeof(char)\
|
sym_array[num_syms].name = malloc(strlen(symbol) * sizeof(char) + 1);
|
||||||
+ 1);
|
if (sym_array[num_syms].name == NULL)
|
||||||
if ( sym_array[num_syms].name == (char *) 0 )
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
sym_array[num_syms].value = address;
|
sym_array[num_syms].value = address;
|
||||||
@ -618,7 +560,6 @@ static int AddSymbol(address, symbol)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: LookupSymbol
|
* Function: LookupSymbol
|
||||||
*
|
*
|
||||||
@ -638,20 +579,12 @@ static int AddSymbol(address, symbol)
|
|||||||
* If a match is found the pointer to the symbolic name most
|
* If a match is found the pointer to the symbolic name most
|
||||||
* closely matching the address is returned.
|
* closely matching the address is returned.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
char *LookupSymbol(unsigned long value, struct symbol *sym)
|
||||||
char * LookupSymbol(value, sym)
|
|
||||||
|
|
||||||
unsigned long value;
|
|
||||||
|
|
||||||
struct symbol *sym;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int lp;
|
|
||||||
|
|
||||||
auto char *last;
|
|
||||||
auto char *name;
|
|
||||||
|
|
||||||
struct symbol ksym, msym;
|
struct symbol ksym, msym;
|
||||||
|
char *last;
|
||||||
|
char *name;
|
||||||
|
int lp;
|
||||||
|
|
||||||
if (!sym_array)
|
if (!sym_array)
|
||||||
return ((char *)0);
|
return ((char *)0);
|
||||||
@ -662,12 +595,10 @@ char * LookupSymbol(value, sym)
|
|||||||
if (value < sym_array[0].value)
|
if (value < sym_array[0].value)
|
||||||
return ((char *)0);
|
return ((char *)0);
|
||||||
|
|
||||||
for(lp = 0; lp <= num_syms; ++lp)
|
for (lp = 0; lp <= num_syms; ++lp) {
|
||||||
{
|
if (sym_array[lp].value > value) {
|
||||||
if ( sym_array[lp].value > value )
|
|
||||||
{
|
|
||||||
ksym.offset = value - sym_array[lp - 1].value;
|
ksym.offset = value - sym_array[lp - 1].value;
|
||||||
ksym.size = sym_array[lp].value - \
|
ksym.size = sym_array[lp].value -
|
||||||
sym_array[lp - 1].value;
|
sym_array[lp - 1].value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -676,30 +607,24 @@ char * LookupSymbol(value, sym)
|
|||||||
|
|
||||||
name = LookupModuleSymbol(value, &msym);
|
name = LookupModuleSymbol(value, &msym);
|
||||||
|
|
||||||
if ( ksym.offset == 0 && msym.offset == 0 )
|
if (ksym.offset == 0 && msym.offset == 0) {
|
||||||
{
|
return NULL;
|
||||||
return((char *) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ksym.offset == 0 || msym.offset < 0 ||
|
if (ksym.offset == 0 || msym.offset < 0 ||
|
||||||
(ksym.offset > 0 && ksym.offset < msym.offset) )
|
(ksym.offset > 0 && ksym.offset < msym.offset)) {
|
||||||
{
|
|
||||||
sym->offset = ksym.offset;
|
sym->offset = ksym.offset;
|
||||||
sym->size = ksym.size;
|
sym->size = ksym.size;
|
||||||
return (last);
|
return (last);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sym->offset = msym.offset;
|
sym->offset = msym.offset;
|
||||||
sym->size = msym.size;
|
sym->size = msym.size;
|
||||||
return (name);
|
return (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
return((char *) 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: FreeSymbols
|
* Function: FreeSymbols
|
||||||
*
|
*
|
||||||
@ -713,10 +638,9 @@ char * LookupSymbol(value, sym)
|
|||||||
* Return: void
|
* Return: void
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static void FreeSymbols()
|
static void FreeSymbols(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int lp;
|
int lp;
|
||||||
|
|
||||||
/* Free each piece of memory allocated for symbol names. */
|
/* Free each piece of memory allocated for symbol names. */
|
||||||
for (lp = 0; lp < num_syms; ++lp)
|
for (lp = 0; lp < num_syms; ++lp)
|
||||||
@ -726,11 +650,8 @@ static void FreeSymbols()
|
|||||||
free(sym_array);
|
free(sym_array);
|
||||||
sym_array = (struct sym_table *)0;
|
sym_array = (struct sym_table *)0;
|
||||||
num_syms = 0;
|
num_syms = 0;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: LogExpanded
|
* Function: LogExpanded
|
||||||
*
|
*
|
||||||
@ -749,23 +670,16 @@ static void FreeSymbols()
|
|||||||
* Return: void
|
* Return: void
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
extern char * ExpandKadds(line, el)
|
char *ExpandKadds(char *line, char *el)
|
||||||
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
char *el;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto char dlm,
|
unsigned long int value;
|
||||||
*kp,
|
struct symbol sym;
|
||||||
*sl = line,
|
char *symbol;
|
||||||
*elp = el,
|
char *elp = el;
|
||||||
*symbol;
|
char *sl = line;
|
||||||
|
char *kp;
|
||||||
char num[15];
|
char num[15];
|
||||||
auto unsigned long int value;
|
char dlm;
|
||||||
|
|
||||||
auto struct symbol sym;
|
|
||||||
|
|
||||||
sym.offset = 0;
|
sym.offset = 0;
|
||||||
sym.size = 0;
|
sym.size = 0;
|
||||||
@ -791,27 +705,23 @@ extern char * ExpandKadds(line, el)
|
|||||||
(strstr(line, "Oops:") != (char *)0) && !InitMsyms())
|
(strstr(line, "Oops:") != (char *)0) && !InitMsyms())
|
||||||
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
|
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Early return if there do not appear to be any kernel
|
* Early return if there do not appear to be any kernel
|
||||||
* messages in this line.
|
* messages in this line.
|
||||||
*/
|
*/
|
||||||
if ((num_syms == 0) ||
|
if ((num_syms == 0) ||
|
||||||
(kp = strstr(line, "[<")) == (char *) 0 )
|
(kp = strstr(line, "[<")) == (char *)0) {
|
||||||
{
|
|
||||||
strcpy(el, line);
|
strcpy(el, line);
|
||||||
return (el);
|
return (el);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop through and expand all kernel messages. */
|
/* Loop through and expand all kernel messages. */
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
while (sl < kp + 1)
|
while (sl < kp + 1)
|
||||||
*elp++ = *sl++;
|
*elp++ = *sl++;
|
||||||
|
|
||||||
/* Now poised at a kernel delimiter. */
|
/* Now poised at a kernel delimiter. */
|
||||||
if ( (kp = strstr(sl, ">]")) == (char *) 0 )
|
if ((kp = strstr(sl, ">]")) == (char *)0) {
|
||||||
{
|
|
||||||
strcpy(el, sl);
|
strcpy(el, sl);
|
||||||
return (el);
|
return (el);
|
||||||
}
|
}
|
||||||
@ -825,14 +735,13 @@ extern char * ExpandKadds(line, el)
|
|||||||
strcat(elp, symbol);
|
strcat(elp, symbol);
|
||||||
elp += strlen(symbol);
|
elp += strlen(symbol);
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n", \
|
fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n",
|
||||||
sl+1, value, \
|
sl + 1, value,
|
||||||
(sym.size==0) ? symbol+1 : symbol, \
|
(sym.size == 0) ? symbol + 1 : symbol,
|
||||||
sym.offset, sym.size);
|
sym.offset, sym.size);
|
||||||
|
|
||||||
value = 2;
|
value = 2;
|
||||||
if ( sym.size != 0 )
|
if (sym.size != 0) {
|
||||||
{
|
|
||||||
--value;
|
--value;
|
||||||
++kp;
|
++kp;
|
||||||
elp += sprintf(elp, "+0x%x/0x%02x", sym.offset, sym.size);
|
elp += sprintf(elp, "+0x%x/0x%02x", sym.offset, sym.size);
|
||||||
@ -842,15 +751,13 @@ extern char * ExpandKadds(line, el)
|
|||||||
sl = kp + value;
|
sl = kp + value;
|
||||||
if ((kp = strstr(sl, "[<")) == (char *)0)
|
if ((kp = strstr(sl, "[<")) == (char *)0)
|
||||||
strcat(elp, sl);
|
strcat(elp, sl);
|
||||||
}
|
} while (kp != (char *)0);
|
||||||
while ( kp != (char *) 0);
|
|
||||||
|
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Expanded line: %s\n", el);
|
fprintf(stderr, "Expanded line: %s\n", el);
|
||||||
return (el);
|
return (el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: SetParanoiaLevel
|
* Function: SetParanoiaLevel
|
||||||
*
|
*
|
||||||
@ -864,17 +771,12 @@ extern char * ExpandKadds(line, el)
|
|||||||
* present when resolving kernel exceptions.
|
* present when resolving kernel exceptions.
|
||||||
* Return: void
|
* Return: void
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
void SetParanoiaLevel(int level)
|
||||||
extern void SetParanoiaLevel(level)
|
|
||||||
|
|
||||||
int level;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
i_am_paranoid = level;
|
i_am_paranoid = level;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setting the -DTEST define enables the following code fragment to
|
* Setting the -DTEST define enables the following code fragment to
|
||||||
* be compiled. This produces a small standalone program which will
|
* be compiled. This produces a small standalone program which will
|
||||||
@ -885,37 +787,30 @@ extern void SetParanoiaLevel(level)
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
extern int main(int, char **);
|
int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
extern int main(int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
auto char line[1024], eline[2048];
|
char line[1024], eline[2048];
|
||||||
|
|
||||||
debugging = 1;
|
debugging = 1;
|
||||||
|
|
||||||
|
if (!InitKsyms((char *)0)) {
|
||||||
if ( !InitKsyms((char *) 0) )
|
|
||||||
{
|
|
||||||
fputs("ksym: Error loading system map.\n", stderr);
|
fputs("ksym: Error loading system map.\n", stderr);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( !feof(stdin) )
|
while (!feof(stdin)) {
|
||||||
{
|
|
||||||
fgets(line, sizeof(line), stdin);
|
fgets(line, sizeof(line), stdin);
|
||||||
if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; /* Trash NL char */
|
if (line[strlen(line) - 1] == '\n')
|
||||||
|
line[strlen(line) - 1] = '\0'; /* Trash NL char */
|
||||||
memset(eline, '\0', sizeof(eline));
|
memset(eline, '\0', sizeof(eline));
|
||||||
ExpandKadds(line, eline);
|
ExpandKadds(line, eline);
|
||||||
fprintf(stdout, "%s\n", eline);
|
fprintf(stdout, "%s\n", eline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void Syslog(int priority, char *fmt, ...)
|
void Syslog(int priority, char *fmt, ...)
|
||||||
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -930,9 +825,8 @@ extern void Syslog(int priority, char *fmt, ...)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local variables:
|
* Local Variables:
|
||||||
* c-indent-level: 8
|
* indent-tabs-mode: t
|
||||||
* c-basic-offset: 8
|
* c-file-style: "linux"
|
||||||
* tab-width: 8
|
|
||||||
* End:
|
* End:
|
||||||
*/
|
*/
|
||||||
|
220
src/ksym_mod.c
220
src/ksym_mod.c
@ -103,26 +103,25 @@
|
|||||||
* the first hit.
|
* the first hit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Includes. */
|
/* Includes. */
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef SYSV
|
#ifdef SYSV
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/msgbuf.h>
|
#include <sys/msgbuf.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h>
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include <stdarg.h>
|
|
||||||
#include <paths.h>
|
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "klogd.h"
|
#include "klogd.h"
|
||||||
#include "ksyms.h"
|
#include "ksyms.h"
|
||||||
@ -140,7 +139,6 @@ static int debugging = 1;
|
|||||||
extern int debugging;
|
extern int debugging;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Function prototypes. */
|
/* Function prototypes. */
|
||||||
static void FreeModules(void);
|
static void FreeModules(void);
|
||||||
static int AddSymbol(const char *);
|
static int AddSymbol(const char *);
|
||||||
@ -166,39 +164,36 @@ extern int num_syms;
|
|||||||
* True if loading is successful.
|
* True if loading is successful.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
extern int InitMsyms()
|
extern int InitMsyms(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int rtn,
|
|
||||||
tmp;
|
|
||||||
|
|
||||||
FILE *ksyms;
|
FILE *ksyms;
|
||||||
|
|
||||||
char buf[128];
|
|
||||||
char *p;
|
char *p;
|
||||||
|
char buf[128];
|
||||||
|
int rtn;
|
||||||
|
int tmp;
|
||||||
|
|
||||||
/* Initialize the kernel module symbol table. */
|
/* Initialize the kernel module symbol table. */
|
||||||
FreeModules();
|
FreeModules();
|
||||||
|
|
||||||
ksyms = fopen(KSYMS, "r");
|
ksyms = fopen(KSYMS, "r");
|
||||||
|
|
||||||
if ( ksyms == NULL )
|
if (ksyms == NULL) {
|
||||||
{
|
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
Syslog(LOG_INFO, "No module symbols loaded - "
|
Syslog(LOG_INFO, "No module symbols loaded - "
|
||||||
"kernel modules not enabled.\n");
|
"kernel modules not enabled.\n");
|
||||||
else
|
else
|
||||||
Syslog(LOG_ERR, "Error loading kernel symbols " \
|
Syslog(LOG_ERR, "Error loading kernel symbols "
|
||||||
"- %s\n", strerror(errno));
|
"- %s\n",
|
||||||
|
strerror(errno));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Loading kernel module symbols - "
|
fprintf(stderr, "Loading kernel module symbols - "
|
||||||
"Source: %s\n", KSYMS);
|
"Source: %s\n",
|
||||||
|
KSYMS);
|
||||||
|
|
||||||
while ( fgets(buf, sizeof(buf), ksyms) != NULL )
|
while (fgets(buf, sizeof(buf), ksyms) != NULL) {
|
||||||
{
|
|
||||||
if (num_syms > 0 && index(buf, '[') == NULL)
|
if (num_syms > 0 && index(buf, '[') == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -219,45 +214,39 @@ extern int InitMsyms()
|
|||||||
have_modules = 1;
|
have_modules = 1;
|
||||||
|
|
||||||
/* Sort the symbol tables in each module. */
|
/* Sort the symbol tables in each module. */
|
||||||
for (rtn = tmp = 0; tmp < num_modules; ++tmp)
|
for (rtn = tmp = 0; tmp < num_modules; ++tmp) {
|
||||||
{
|
|
||||||
rtn += sym_array_modules[tmp].num_syms;
|
rtn += sym_array_modules[tmp].num_syms;
|
||||||
if (sym_array_modules[tmp].num_syms < 2)
|
if (sym_array_modules[tmp].num_syms < 2)
|
||||||
continue;
|
continue;
|
||||||
qsort(sym_array_modules[tmp].sym_array, \
|
qsort(sym_array_modules[tmp].sym_array,
|
||||||
sym_array_modules[tmp].num_syms, \
|
sym_array_modules[tmp].num_syms,
|
||||||
sizeof(struct sym_table), symsort);
|
sizeof(struct sym_table), symsort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtn == 0)
|
if (rtn == 0)
|
||||||
Syslog(LOG_INFO, "No module symbols loaded.");
|
Syslog(LOG_INFO, "No module symbols loaded.");
|
||||||
else
|
else
|
||||||
Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn, \
|
Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn,
|
||||||
(rtn == 1) ? "symbol" : "symbols", \
|
(rtn == 1) ? "symbol" : "symbols",
|
||||||
num_modules, (num_modules == 1) ? "." : "s.");
|
num_modules, (num_modules == 1) ? "." : "s.");
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int symsort(const void *p1, const void *p2)
|
||||||
static int symsort(p1, p2)
|
|
||||||
|
|
||||||
const void *p1;
|
|
||||||
|
|
||||||
const void *p2;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto const struct sym_table *sym1 = p1,
|
const struct sym_table *sym1 = p1,
|
||||||
*sym2 = p2;
|
*sym2 = p2;
|
||||||
|
|
||||||
if (sym1->value < sym2->value)
|
if (sym1->value < sym2->value)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (sym1->value == sym2->value)
|
if (sym1->value == sym2->value)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: FreeModules
|
* Function: FreeModules
|
||||||
*
|
*
|
||||||
@ -268,15 +257,11 @@ static int symsort(p1, p2)
|
|||||||
*
|
*
|
||||||
* Return: void
|
* Return: void
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static void FreeModules(void)
|
||||||
static void FreeModules()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int nmods,
|
struct Module *mp;
|
||||||
nsyms;
|
int nmods;
|
||||||
|
int nsyms;
|
||||||
auto struct Module *mp;
|
|
||||||
|
|
||||||
|
|
||||||
/* Check to see if the module symbol tables need to be cleared. */
|
/* Check to see if the module symbol tables need to be cleared. */
|
||||||
have_modules = 0;
|
have_modules = 0;
|
||||||
@ -286,8 +271,7 @@ static void FreeModules()
|
|||||||
if (sym_array_modules == NULL)
|
if (sym_array_modules == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (nmods = 0; nmods < num_modules; ++nmods)
|
for (nmods = 0; nmods < num_modules; ++nmods) {
|
||||||
{
|
|
||||||
mp = &sym_array_modules[nmods];
|
mp = &sym_array_modules[nmods];
|
||||||
if (mp->num_syms == 0)
|
if (mp->num_syms == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -305,7 +289,6 @@ static void FreeModules()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: AddModule
|
* Function: AddModule
|
||||||
*
|
*
|
||||||
@ -319,33 +302,21 @@ static void FreeModules()
|
|||||||
* Return: struct Module *
|
* Return: struct Module *
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
struct Module *AddModule(module)
|
struct Module *AddModule(const char *module)
|
||||||
|
|
||||||
const char *module;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
struct Module *mp;
|
struct Module *mp;
|
||||||
|
|
||||||
if ( num_modules == 0 )
|
if (num_modules == 0) {
|
||||||
{
|
|
||||||
sym_array_modules = (struct Module *)malloc(sizeof(struct Module));
|
sym_array_modules = (struct Module *)malloc(sizeof(struct Module));
|
||||||
|
if (sym_array_modules == NULL) {
|
||||||
if ( sym_array_modules == NULL )
|
|
||||||
{
|
|
||||||
Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
|
Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mp = sym_array_modules;
|
mp = sym_array_modules;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Allocate space for the module. */
|
/* Allocate space for the module. */
|
||||||
mp = (struct Module *) \
|
mp = realloc(sym_array_modules, (num_modules + 1) * sizeof(struct Module));
|
||||||
realloc(sym_array_modules, \
|
if (mp == NULL) {
|
||||||
(num_modules+1) * sizeof(struct Module));
|
|
||||||
|
|
||||||
if ( mp == NULL )
|
|
||||||
{
|
|
||||||
Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
|
Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -366,7 +337,6 @@ struct Module *AddModule(module)
|
|||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: AddSymbol
|
* Function: AddSymbol
|
||||||
*
|
*
|
||||||
@ -387,22 +357,16 @@ struct Module *AddModule(module)
|
|||||||
* A boolean value is assumed. True if the addition is
|
* A boolean value is assumed. True if the addition is
|
||||||
* successful. False if not.
|
* successful. False if not.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
static int AddSymbol(const char *line)
|
||||||
static int AddSymbol(line)
|
|
||||||
|
|
||||||
const char *line;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
char *module;
|
|
||||||
unsigned long address;
|
|
||||||
char *p;
|
|
||||||
static char *lastmodule = NULL;
|
static char *lastmodule = NULL;
|
||||||
struct Module *mp;
|
struct Module *mp;
|
||||||
|
unsigned long address;
|
||||||
|
char *module;
|
||||||
|
char *p;
|
||||||
|
|
||||||
module = index(line, '[');
|
module = index(line, '[');
|
||||||
|
if (module != NULL) {
|
||||||
if ( module != NULL )
|
|
||||||
{
|
|
||||||
p = index(module, ']');
|
p = index(module, ']');
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
@ -410,15 +374,14 @@ static int AddSymbol(line)
|
|||||||
|
|
||||||
p = module++;
|
p = module++;
|
||||||
|
|
||||||
while ( isspace(*(--p)) );
|
while (isspace(*(--p)))
|
||||||
|
;
|
||||||
*(++p) = '\0';
|
*(++p) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
p = index(line, ' ');
|
p = index(line, ' ');
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
address = strtoul(line, (char **)0, 16);
|
address = strtoul(line, (char **)0, 16);
|
||||||
@ -428,20 +391,18 @@ static int AddSymbol(line)
|
|||||||
if (num_modules == 0 ||
|
if (num_modules == 0 ||
|
||||||
(lastmodule == NULL && module != NULL) ||
|
(lastmodule == NULL && module != NULL) ||
|
||||||
(module == NULL && lastmodule != NULL) ||
|
(module == NULL && lastmodule != NULL) ||
|
||||||
( module != NULL && strcmp(module, lastmodule)))
|
(module != NULL && strcmp(module, lastmodule))) {
|
||||||
{
|
|
||||||
mp = AddModule(module);
|
mp = AddModule(module);
|
||||||
|
|
||||||
if (mp == NULL)
|
if (mp == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
mp = &sym_array_modules[num_modules - 1];
|
mp = &sym_array_modules[num_modules - 1];
|
||||||
|
|
||||||
lastmodule = mp->name;
|
lastmodule = mp->name;
|
||||||
|
|
||||||
/* Allocate space for the symbol table entry. */
|
/* Allocate space for the symbol table entry. */
|
||||||
mp->sym_array = (struct sym_table *) realloc(mp->sym_array, \
|
mp->sym_array = (struct sym_table *)realloc(mp->sym_array,
|
||||||
(mp->num_syms + 1) * sizeof(struct sym_table));
|
(mp->num_syms + 1) * sizeof(struct sym_table));
|
||||||
|
|
||||||
if (mp->sym_array == (struct sym_table *)0)
|
if (mp->sym_array == (struct sym_table *)0)
|
||||||
@ -458,7 +419,6 @@ static int AddSymbol(line)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: LookupModuleSymbol
|
* Function: LookupModuleSymbol
|
||||||
*
|
*
|
||||||
@ -478,31 +438,20 @@ static int AddSymbol(line)
|
|||||||
* If a match is found the pointer to the symbolic name most
|
* If a match is found the pointer to the symbolic name most
|
||||||
* closely matching the address is returned.
|
* closely matching the address is returned.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
char *LookupModuleSymbol(unsigned long value, struct symbol *sym)
|
||||||
extern char * LookupModuleSymbol(value, sym)
|
|
||||||
|
|
||||||
unsigned long value;
|
|
||||||
|
|
||||||
struct symbol *sym;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int nmod,
|
|
||||||
nsym;
|
|
||||||
|
|
||||||
auto struct sym_table *last;
|
|
||||||
|
|
||||||
auto struct Module *mp;
|
|
||||||
|
|
||||||
static char ret[100];
|
static char ret[100];
|
||||||
|
struct sym_table *last;
|
||||||
|
struct Module *mp;
|
||||||
|
int nmod;
|
||||||
|
int nsym;
|
||||||
|
|
||||||
sym->size = 0;
|
sym->size = 0;
|
||||||
sym->offset = 0;
|
sym->offset = 0;
|
||||||
if (num_modules == 0)
|
if (num_modules == 0)
|
||||||
return((char *) 0);
|
return NULL;
|
||||||
|
|
||||||
for (nmod = 0; nmod < num_modules; ++nmod)
|
for (nmod = 0; nmod < num_modules; ++nmod) {
|
||||||
{
|
|
||||||
mp = &sym_array_modules[nmod];
|
mp = &sym_array_modules[nmod];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -511,17 +460,14 @@ extern char * LookupModuleSymbol(value, sym)
|
|||||||
*/
|
*/
|
||||||
for (nsym = 1, last = &mp->sym_array[0];
|
for (nsym = 1, last = &mp->sym_array[0];
|
||||||
nsym < mp->num_syms;
|
nsym < mp->num_syms;
|
||||||
++nsym)
|
++nsym) {
|
||||||
{
|
if (mp->sym_array[nsym].value > value) {
|
||||||
if ( mp->sym_array[nsym].value > value )
|
|
||||||
{
|
|
||||||
if (sym->size == 0 ||
|
if (sym->size == 0 ||
|
||||||
(value - last->value) < sym->offset ||
|
(value - last->value) < sym->offset ||
|
||||||
((sym->offset == (value - last->value)) &&
|
((sym->offset == (value - last->value)) &&
|
||||||
(mp->sym_array[nsym].value-last->value) < sym->size ) )
|
(mp->sym_array[nsym].value - last->value) < sym->size)) {
|
||||||
{
|
|
||||||
sym->offset = value - last->value;
|
sym->offset = value - last->value;
|
||||||
sym->size = mp->sym_array[nsym].value - \
|
sym->size = mp->sym_array[nsym].value -
|
||||||
last->value;
|
last->value;
|
||||||
ret[sizeof(ret) - 1] = '\0';
|
ret[sizeof(ret) - 1] = '\0';
|
||||||
if (mp->name == NULL)
|
if (mp->name == NULL)
|
||||||
@ -541,10 +487,9 @@ extern char * LookupModuleSymbol(value, sym)
|
|||||||
return (ret);
|
return (ret);
|
||||||
|
|
||||||
/* It has been a hopeless exercise. */
|
/* It has been a hopeless exercise. */
|
||||||
return((char *) 0);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setting the -DTEST define enables the following code fragment to
|
* Setting the -DTEST define enables the following code fragment to
|
||||||
* be compiled. This produces a small standalone program which will
|
* be compiled. This produces a small standalone program which will
|
||||||
@ -554,42 +499,29 @@ extern char * LookupModuleSymbol(value, sym)
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
extern int main(int, char **);
|
|
||||||
|
|
||||||
|
|
||||||
int main(argc, argv)
|
|
||||||
|
|
||||||
int argc;
|
|
||||||
|
|
||||||
char *argv[];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto int lp, syms;
|
int lp, syms;
|
||||||
|
|
||||||
|
if (!InitMsyms()) {
|
||||||
if ( !InitMsyms() )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot load module symbols.\n");
|
fprintf(stderr, "Cannot load module symbols.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Number of modules: %d\n\n", num_modules);
|
printf("Number of modules: %d\n\n", num_modules);
|
||||||
|
|
||||||
for(lp= 0; lp < num_modules; ++lp)
|
for (lp = 0; lp < num_modules; ++lp) {
|
||||||
{
|
printf("Module #%d = %s, Number of symbols = %d\n", lp + 1,
|
||||||
printf("Module #%d = %s, Number of symbols = %d\n", lp + 1, \
|
|
||||||
sym_array_modules[lp].name == NULL
|
sym_array_modules[lp].name == NULL
|
||||||
? "kernel space"
|
? "kernel space"
|
||||||
:sym_array_modules[lp].name, \
|
: sym_array_modules[lp].name,
|
||||||
sym_array_modules[lp].num_syms);
|
sym_array_modules[lp].num_syms);
|
||||||
|
|
||||||
for (syms= 0; syms < sym_array_modules[lp].num_syms; ++syms)
|
for (syms = 0; syms < sym_array_modules[lp].num_syms; ++syms) {
|
||||||
{
|
|
||||||
printf("\tSymbol #%d\n", syms + 1);
|
printf("\tSymbol #%d\n", syms + 1);
|
||||||
printf("\tName: %s\n", \
|
printf("\tName: %s\n",
|
||||||
sym_array_modules[lp].sym_array[syms].name);
|
sym_array_modules[lp].sym_array[syms].name);
|
||||||
printf("\tAddress: %lx\n\n", \
|
printf("\tAddress: %lx\n\n",
|
||||||
sym_array_modules[lp].sym_array[syms].value);
|
sym_array_modules[lp].sym_array[syms].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -598,8 +530,7 @@ int main(argc, argv)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void Syslog(int priority, char *fmt, ...)
|
void Syslog(int priority, char *fmt, ...)
|
||||||
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -615,9 +546,8 @@ extern void Syslog(int priority, char *fmt, ...)
|
|||||||
#endif /* TEST */
|
#endif /* TEST */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local variables:
|
* Local Variables:
|
||||||
* c-indent-level: 8
|
* indent-tabs-mode: t
|
||||||
* c-basic-offset: 8
|
* c-file-style: "linux"
|
||||||
* tab-width: 8
|
|
||||||
* End:
|
* End:
|
||||||
*/
|
*/
|
||||||
|
41
src/ksyms.h
41
src/ksyms.h
@ -1,29 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
ksym.h - Definitions for symbol table utilities.
|
* ksym.h - Definitions for symbol table utilities.
|
||||||
Copyright (c) 1995, 1996 Dr. G.W. Wettstein <greg@wind.rmcc.com>
|
* Copyright (c) 1995, 1996 Dr. G.W. Wettstein <greg@wind.rmcc.com>
|
||||||
Copyright (c) 1996 Enjellic Systems Development
|
* Copyright (c) 1996 Enjellic Systems Development
|
||||||
|
*
|
||||||
This file is part of the sysklogd package, a kernel and system log daemon.
|
* This file is part of the sysklogd package, a kernel and system log daemon.
|
||||||
|
*
|
||||||
This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Variables, structures and type definitions static to this module. */
|
/* Variables, structures and type definitions static to this module. */
|
||||||
|
|
||||||
struct symbol
|
struct symbol {
|
||||||
{
|
|
||||||
char *name;
|
char *name;
|
||||||
int size;
|
int size;
|
||||||
int offset;
|
int offset;
|
||||||
|
44
src/module.h
44
src/module.h
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
module.h - Miscellaneous module definitions
|
* module.h - Miscellaneous module definitions
|
||||||
Copyright (c) 1996 Richard Henderson <rth@tamu.edu>
|
* Copyright (c) 1996 Richard Henderson <rth@tamu.edu>
|
||||||
Copyright (c) 2004-7 Martin Schulze <joey@infodrom.org>
|
* Copyright (c) 2004-7 Martin Schulze <joey@infodrom.org>
|
||||||
|
*
|
||||||
This file is part of the sysklogd package.
|
* This file is part of the sysklogd package.
|
||||||
|
*
|
||||||
This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ChangeLog:
|
/* ChangeLog:
|
||||||
@ -35,14 +35,12 @@
|
|||||||
* ksym_mod.c over here.
|
* ksym_mod.c over here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct sym_table
|
struct sym_table {
|
||||||
{
|
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
char *name;
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Module
|
struct Module {
|
||||||
{
|
|
||||||
struct sym_table *sym_array;
|
struct sym_table *sym_array;
|
||||||
int num_syms;
|
int num_syms;
|
||||||
|
|
||||||
|
29
src/oops.c
29
src/oops.c
@ -29,11 +29,11 @@
|
|||||||
cat /proc/oops Display current log level and last oops time
|
cat /proc/oops Display current log level and last oops time
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/module.h>
|
||||||
#include <linux/poll.h>
|
#include <linux/poll.h>
|
||||||
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/time.h>
|
#include <linux/time.h>
|
||||||
|
|
||||||
#define MODNAME "oops"
|
#define MODNAME "oops"
|
||||||
@ -75,13 +75,14 @@ struct code priorities[] = {
|
|||||||
|
|
||||||
void oops_decode_level(char *line)
|
void oops_decode_level(char *line)
|
||||||
{
|
{
|
||||||
char *p;
|
|
||||||
struct code *prio;
|
struct code *prio;
|
||||||
|
char *p;
|
||||||
|
|
||||||
if (strncmp(line, "level:", 6))
|
if (strncmp(line, "level:", 6))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (p = (char *)(line) + 6;*p == ' ' || *p == '\t';p++);
|
for (p = (char *)(line) + 6; *p == ' ' || *p == '\t'; p++)
|
||||||
|
;
|
||||||
|
|
||||||
for (prio = priorities; prio->name; prio++)
|
for (prio = priorities; prio->name; prio++)
|
||||||
if (!strcmp(p, prio->name)) {
|
if (!strcmp(p, prio->name)) {
|
||||||
@ -95,9 +96,8 @@ void oops_decode_level (char *line)
|
|||||||
*/
|
*/
|
||||||
static void oops(void)
|
static void oops(void)
|
||||||
{
|
{
|
||||||
auto unsigned long *p = (unsigned long *) 828282828;
|
unsigned long *p = (unsigned long *)828282828;
|
||||||
*p = 5;
|
*p = 5;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int oops_proc_open(struct inode *inode, struct file *file)
|
static int oops_proc_open(struct inode *inode, struct file *file)
|
||||||
@ -111,11 +111,10 @@ static int oops_proc_open (struct inode *inode, struct file *file)
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
oops_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
oops_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
{
|
{
|
||||||
char s[70];
|
|
||||||
int size;
|
|
||||||
|
|
||||||
struct code *prio;
|
struct code *prio;
|
||||||
char *level = NULL;
|
char *level = NULL;
|
||||||
|
char s[70];
|
||||||
|
int size;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printk(KERN_DEBUG "oops_proc_read(%d).\n", nbytes);
|
printk(KERN_DEBUG "oops_proc_read(%d).\n", nbytes);
|
||||||
@ -128,7 +127,8 @@ oops_proc_read (struct file *file, char __user *buf, size_t nbytes, loff_t *ppos
|
|||||||
|
|
||||||
for (prio = priorities;
|
for (prio = priorities;
|
||||||
prio->name && prio->level != oops_data.loglevel;
|
prio->name && prio->level != oops_data.loglevel;
|
||||||
prio++);
|
prio++)
|
||||||
|
;
|
||||||
level = prio->name;
|
level = prio->name;
|
||||||
|
|
||||||
if (oops_data.lastoops == 0)
|
if (oops_data.lastoops == 0)
|
||||||
@ -244,7 +244,12 @@ void oops_cleanup (void)
|
|||||||
printk(KERN_INFO "Removing module " MODNAME ".\n");
|
printk(KERN_INFO "Removing module " MODNAME ".\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module_init(oops_init);
|
module_init(oops_init);
|
||||||
module_exit(oops_cleanup);
|
module_exit(oops_cleanup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
pidfile.c - interact with pidfiles
|
* pidfile.c - interact with pidfiles
|
||||||
Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
|
* Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
|
||||||
|
*
|
||||||
This file is part of the sysklogd package, a kernel and system log daemon.
|
* This file is part of the sysklogd package, a kernel and system log daemon.
|
||||||
|
*
|
||||||
This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -24,14 +24,14 @@
|
|||||||
* First version (v0.2) released
|
* First version (v0.2) released
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/file.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/* read_pid
|
/* read_pid
|
||||||
*
|
*
|
||||||
@ -41,13 +41,16 @@
|
|||||||
*/
|
*/
|
||||||
int read_pid(char *pidfile)
|
int read_pid(char *pidfile)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *fp;
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
if (!(f=fopen(pidfile,"r")))
|
fp = fopen(pidfile, "r");
|
||||||
|
if (!fp)
|
||||||
return 0;
|
return 0;
|
||||||
fscanf(f,"%d", &pid);
|
|
||||||
fclose(f);
|
fscanf(fp, "%d", &pid);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,30 +87,29 @@ int check_pid (char *pidfile)
|
|||||||
*/
|
*/
|
||||||
int write_pid(char *pidfile)
|
int write_pid(char *pidfile)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *fp;
|
||||||
int fd;
|
int fd;
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
if ( ((fd = open(pidfile, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1)
|
if (((fd = open(pidfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) || ((fp = fdopen(fd, "r+")) == NULL)) {
|
||||||
|| ((f = fdopen(fd, "r+")) == NULL) ) {
|
|
||||||
fprintf(stderr, "Can't open or create %s.\n", pidfile);
|
fprintf(stderr, "Can't open or create %s.\n", pidfile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
|
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
|
||||||
fscanf(f, "%d", &pid);
|
fscanf(fp, "%d", &pid);
|
||||||
fclose(f);
|
fclose(fp);
|
||||||
printf("Can't lock, lock is held by pid %d.\n", pid);
|
printf("Can't lock, lock is held by pid %d.\n", pid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
if (!fprintf(f,"%d\n", pid)) {
|
if (!fprintf(fp, "%d\n", pid)) {
|
||||||
printf("Can't write pid , %s.\n", strerror(errno));
|
printf("Can't write pid , %s.\n", strerror(errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fflush(f);
|
fflush(fp);
|
||||||
|
|
||||||
if (flock(fd, LOCK_UN) == -1) {
|
if (flock(fd, LOCK_UN) == -1) {
|
||||||
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
|
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
|
||||||
@ -139,3 +141,9 @@ int remove_pid (char *pidfile)
|
|||||||
return unlink(pidfile);
|
return unlink(pidfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
pidfile.h - interact with pidfiles
|
* pidfile.h - interact with pidfiles
|
||||||
Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
|
* Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
|
||||||
|
*
|
||||||
This file is part of the sysklogd package, a kernel and system log daemon.
|
* This file is part of the sysklogd package, a kernel and system log daemon.
|
||||||
|
*
|
||||||
This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* read_pid
|
/* read_pid
|
||||||
|
77
src/syslog.c
77
src/syslog.c
@ -52,21 +52,21 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90";
|
|||||||
* reconnect klogd to the logger after it went away.
|
* reconnect klogd to the logger after it went away.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <netdb.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <paths.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#define _PATH_LOGNAME "/dev/log"
|
#define _PATH_LOGNAME "/dev/log"
|
||||||
|
|
||||||
@ -76,8 +76,7 @@ static int LogStat = 0; /* status bits, set by openlog() */
|
|||||||
static const char *LogTag = "syslog"; /* string to tag the entry with */
|
static const char *LogTag = "syslog"; /* string to tag the entry with */
|
||||||
static int LogFacility = LOG_USER; /* default facility code */
|
static int LogFacility = LOG_USER; /* default facility code */
|
||||||
|
|
||||||
void
|
void syslog(int pri, const char *fmt, ...)
|
||||||
syslog(int pri, const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -86,18 +85,14 @@ syslog(int pri, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void vsyslog(int pri, const char *fmt, va_list ap)
|
||||||
vsyslog(pri, fmt, ap)
|
|
||||||
int pri;
|
|
||||||
const char *fmt;
|
|
||||||
va_list ap;
|
|
||||||
{
|
{
|
||||||
register int cnt;
|
int cnt;
|
||||||
register char *p;
|
char * p;
|
||||||
time_t now;
|
time_t now;
|
||||||
int fd, saved_errno;
|
int fd, saved_errno;
|
||||||
int result;
|
int result;
|
||||||
char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0;
|
char tbuf[2048], fmt_cpy[1024], *stdp = NULL;
|
||||||
|
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
|
|
||||||
@ -114,16 +109,19 @@ vsyslog(pri, fmt, ap)
|
|||||||
/* build the message */
|
/* build the message */
|
||||||
(void)time(&now);
|
(void)time(&now);
|
||||||
(void)sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4);
|
(void)sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4);
|
||||||
for (p = tbuf; *p; ++p);
|
for (p = tbuf; *p; ++p)
|
||||||
|
;
|
||||||
if (LogStat & LOG_PERROR)
|
if (LogStat & LOG_PERROR)
|
||||||
stdp = p;
|
stdp = p;
|
||||||
if (LogTag) {
|
if (LogTag) {
|
||||||
(void)strcpy(p, LogTag);
|
(void)strcpy(p, LogTag);
|
||||||
for (; *p; ++p);
|
for (; *p; ++p)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
if (LogStat & LOG_PID) {
|
if (LogStat & LOG_PID) {
|
||||||
(void)sprintf(p, "[%d]", getpid());
|
(void)sprintf(p, "[%d]", getpid());
|
||||||
for (; *p; ++p);
|
for (; *p; ++p)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
if (LogTag) {
|
if (LogTag) {
|
||||||
*p++ = ':';
|
*p++ = ':';
|
||||||
@ -132,7 +130,7 @@ vsyslog(pri, fmt, ap)
|
|||||||
|
|
||||||
/* substitute error message for %m */
|
/* substitute error message for %m */
|
||||||
{
|
{
|
||||||
register char ch, *t1, *t2;
|
char ch, *t1, *t2;
|
||||||
char *strerror();
|
char *strerror();
|
||||||
|
|
||||||
for (t1 = fmt_cpy;
|
for (t1 = fmt_cpy;
|
||||||
@ -141,9 +139,9 @@ vsyslog(pri, fmt, ap)
|
|||||||
if (ch == '%' && fmt[1] == 'm') {
|
if (ch == '%' && fmt[1] == 'm') {
|
||||||
++fmt;
|
++fmt;
|
||||||
for (t2 = strerror(saved_errno);
|
for (t2 = strerror(saved_errno);
|
||||||
(*t1 = *t2++); ++t1);
|
(*t1 = *t2++); ++t1)
|
||||||
}
|
;
|
||||||
else
|
} else
|
||||||
*t1++ = ch;
|
*t1++ = ch;
|
||||||
*t1 = '\0';
|
*t1 = '\0';
|
||||||
}
|
}
|
||||||
@ -155,7 +153,7 @@ vsyslog(pri, fmt, ap)
|
|||||||
/* output to stderr if requested */
|
/* output to stderr if requested */
|
||||||
if (LogStat & LOG_PERROR) {
|
if (LogStat & LOG_PERROR) {
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
register struct iovec *v = iov;
|
struct iovec *v = iov;
|
||||||
|
|
||||||
v->iov_base = stdp;
|
v->iov_base = stdp;
|
||||||
v->iov_len = cnt - (stdp - tbuf);
|
v->iov_len = cnt - (stdp - tbuf);
|
||||||
@ -168,8 +166,7 @@ vsyslog(pri, fmt, ap)
|
|||||||
/* output the message to the local logger */
|
/* output the message to the local logger */
|
||||||
result = write(LogFile, tbuf, cnt + 1);
|
result = write(LogFile, tbuf, cnt + 1);
|
||||||
|
|
||||||
if (result == -1
|
if (result == -1 && (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) {
|
||||||
&& (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) {
|
|
||||||
closelog();
|
closelog();
|
||||||
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
|
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
|
||||||
result = write(LogFile, tbuf, cnt + 1);
|
result = write(LogFile, tbuf, cnt + 1);
|
||||||
@ -197,10 +194,7 @@ static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
|||||||
/*
|
/*
|
||||||
* OPENLOG -- open system log
|
* OPENLOG -- open system log
|
||||||
*/
|
*/
|
||||||
void
|
void openlog(const char *ident, int logstat, int logfac)
|
||||||
openlog(ident, logstat, logfac)
|
|
||||||
const char *ident;
|
|
||||||
int logstat, logfac;
|
|
||||||
{
|
{
|
||||||
if (ident != NULL)
|
if (ident != NULL)
|
||||||
LogTag = ident;
|
LogTag = ident;
|
||||||
@ -224,8 +218,7 @@ openlog(ident, logstat, logfac)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (LogFile != -1 && !connected &&
|
if (LogFile != -1 && !connected &&
|
||||||
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+
|
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family) + strlen(SyslogAddr.sa_data)) != -1)
|
||||||
strlen(SyslogAddr.sa_data)) != -1)
|
|
||||||
#else
|
#else
|
||||||
LogFile = fileno(stdout);
|
LogFile = fileno(stdout);
|
||||||
#endif
|
#endif
|
||||||
@ -235,8 +228,7 @@ openlog(ident, logstat, logfac)
|
|||||||
/*
|
/*
|
||||||
* CLOSELOG -- close the system log
|
* CLOSELOG -- close the system log
|
||||||
*/
|
*/
|
||||||
void
|
void closelog()
|
||||||
closelog()
|
|
||||||
{
|
{
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
(void)close(LogFile);
|
(void)close(LogFile);
|
||||||
@ -249,9 +241,7 @@ static int LogMask = 0xff; /* mask of priorities to be logged */
|
|||||||
/*
|
/*
|
||||||
* SETLOGMASK -- set the log mask level
|
* SETLOGMASK -- set the log mask level
|
||||||
*/
|
*/
|
||||||
int
|
int setlogmask(int pmask)
|
||||||
setlogmask(pmask)
|
|
||||||
int pmask;
|
|
||||||
{
|
{
|
||||||
int omask;
|
int omask;
|
||||||
|
|
||||||
@ -260,3 +250,10 @@ setlogmask(pmask)
|
|||||||
LogMask = pmask;
|
LogMask = pmask;
|
||||||
return (omask);
|
return (omask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
@ -17,47 +17,38 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/param.h>
|
|
||||||
|
|
||||||
extern int main(int, char **);
|
extern int main(int, char **);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
auto char *nl,
|
char *nl,
|
||||||
bufr[512];
|
char bufr[512];
|
||||||
auto int logged = 0;
|
int logged = 0;
|
||||||
|
|
||||||
openlog("DOTEST", LOG_PID, LOG_DAEMON);
|
openlog("DOTEST", LOG_PID, LOG_DAEMON);
|
||||||
if (argc > 1)
|
if (argc > 1) {
|
||||||
{
|
if ((*argv[1] == '-') && (*(argv[1] + 1) == '\0')) {
|
||||||
if ( (*argv[1] == '-') && (*(argv[1]+1) == '\0') )
|
|
||||||
{
|
|
||||||
while (!feof(stdin))
|
while (!feof(stdin))
|
||||||
if ( fgets(bufr, sizeof(bufr), stdin) != \
|
if (fgets(bufr, sizeof(bufr), stdin) !=
|
||||||
(char *) 0 )
|
(char *)0) {
|
||||||
{
|
if ((nl = strrchr(bufr, '\n')) !=
|
||||||
if ( (nl = strrchr(bufr, '\n')) != \
|
|
||||||
(char *)0)
|
(char *)0)
|
||||||
*nl = '\0';
|
*nl = '\0';
|
||||||
syslog(LOG_INFO, "%s", bufr);
|
syslog(LOG_INFO, "%s", bufr);
|
||||||
logged += strlen(bufr);
|
logged += strlen(bufr);
|
||||||
if ( logged > 1024 )
|
if (logged > 1024) {
|
||||||
{
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
logged = 0;
|
logged = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
while (argc-- > 1)
|
while (argc-- > 1)
|
||||||
syslog(LOG_INFO, "%s", argv++ [1]);
|
syslog(LOG_INFO, "%s", argv++ [1]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
syslog(LOG_EMERG, "EMERG log.");
|
syslog(LOG_EMERG, "EMERG log.");
|
||||||
syslog(LOG_ALERT, "Alert log.");
|
syslog(LOG_ALERT, "Alert log.");
|
||||||
syslog(LOG_CRIT, "Critical log.");
|
syslog(LOG_CRIT, "Critical log.");
|
||||||
@ -72,3 +63,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
528
src/syslogd.c
528
src/syslogd.c
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user