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:
Joachim Nilsson 2018-08-05 18:54:27 +02:00
parent 53c4dd817d
commit f1f1ee3563
12 changed files with 1850 additions and 2200 deletions

View File

@ -255,22 +255,21 @@
* Remove special treatment of the percent sign.
*/
/* Includes. */
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#ifdef SYSV
#include <fcntl.h>
#else
#include <sys/msgbuf.h>
#endif
#include <sys/stat.h>
#include <stdarg.h>
#include <paths.h>
#include <stdlib.h>
#include "klogd.h"
#include "ksyms.h"
#include <paths.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/stat.h>
#ifndef TESTING
#include "pidfile.h"
#endif
@ -292,29 +291,28 @@ static char *PidFile = "/etc/klogd.pid";
#endif
#endif
static int kmsg,
change_state = 0,
terminate = 0,
caught_TSTP = 0,
reload_symbols = 0,
console_log_level = -1;
static int kmsg;
static int change_state = 0;
static int terminate = 0;
static int caught_TSTP = 0;
static int reload_symbols = 0;
static int console_log_level = -1;
static int use_syscall = 0,
one_shot = 0,
symbol_lookup = 1,
no_fork = 0; /* don't fork - don't run in daemon mode */
static int use_syscall = 0;
static int one_shot = 0;
static int symbol_lookup = 1;
static int no_fork = 0; /* don't fork - don't run in daemon mode */
static char *symfile = (char *) 0,
log_buffer[LOG_BUFFER_SIZE];
static char *symfile = NULL;
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;
int debugging = 0;
int symbols_twice = 0;
/* Function prototypes. */
extern int ksyslog(int type, char *buf, int len);
static void CloseLogSrc(void);
@ -332,101 +330,72 @@ static void LogKernelLine(void);
static void LogProcLine(void);
extern int main(int argc, char *argv[]);
static void CloseLogSrc()
static void CloseLogSrc(void)
{
/* Shutdown the log sources. */
switch ( logsrc )
{
switch (logsrc) {
case kernel:
ksyslog(0, 0, 0);
Syslog(LOG_INFO, "Kernel logging (ksyslog) stopped.");
break;
case proc:
close(kmsg);
Syslog(LOG_INFO, "Kernel logging (proc) stopped.");
break;
case none:
break;
}
if (output_file != (FILE *)0)
fflush(output_file);
return;
}
/*
* Signal handler to terminate the parent process.
*/
#ifndef TESTING
void doexit(sig)
int sig;
void doexit(int signo)
{
exit(0);
}
#endif
void restart(sig)
int sig;
void restart(int signo)
{
signal(SIGCONT, restart);
change_state = 1;
caught_TSTP = 0;
return;
}
void stop_logging(sig)
int sig;
void stop_logging(int signo)
{
signal(SIGTSTP, stop_logging);
change_state = 1;
caught_TSTP = 1;
return;
}
void stop_daemon(sig)
int sig;
void stop_daemon(int signo)
{
Terminate();
return;
}
void reload_daemon(sig)
int sig;
void reload_daemon(int signo)
{
change_state = 1;
reload_symbols = 1;
if ( sig == SIGUSR2 )
{
if (signo == SIGUSR2) {
++reload_symbols;
signal(SIGUSR2, reload_daemon);
}
else
} else
signal(SIGUSR1, reload_daemon);
return;
}
static void Terminate()
static void Terminate(void)
{
CloseLogSrc();
Syslog(LOG_INFO, "Kernel log daemon terminating.");
@ -440,24 +409,18 @@ static void Terminate()
exit(1);
}
static void SignalDaemon(sig)
int sig;
static void SignalDaemon(int signo)
{
#ifndef TESTING
auto int pid = check_pid(PidFile);
int pid = check_pid(PidFile);
kill(pid, sig);
kill(pid, signo);
#else
kill(getpid(), sig);
kill(getpid(), signo);
#endif
return;
}
static void ReloadSymbols()
static void ReloadSymbols(void)
{
if (symbol_lookup) {
if (reload_symbols > 1)
@ -465,12 +428,9 @@ static void ReloadSymbols()
InitMsyms();
}
reload_symbols = change_state = 0;
return;
}
static void ChangeLogging(void)
{
/* Terminate kernel logging. */
if (terminate == 1)
@ -481,15 +441,13 @@ static void ChangeLogging(void)
PACKAGE_VERSION);
/* Reload symbols. */
if ( reload_symbols > 0 )
{
if (reload_symbols > 0) {
ReloadSymbols();
return;
}
/* Stop kernel logging. */
if ( caught_TSTP == 1 )
{
if (caught_TSTP == 1) {
CloseLogSrc();
logsrc = none;
change_state = 0;
@ -504,8 +462,7 @@ static void ChangeLogging(void)
* kernel log state as to what is causing us to restart. Somewhat
* 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.");
change_state = 0;
return;
@ -514,21 +471,15 @@ static void ChangeLogging(void)
/* Restart logging. */
logsrc = GetKernelLogSrc();
change_state = 0;
return;
}
static enum LOGSRC GetKernelLogSrc(void)
{
auto struct stat sb;
struct stat sb;
/* Set level of kernel console messaging.. */
if ( (console_log_level != -1)
&& (ksyslog(8, NULL, console_log_level) < 0) && \
(errno == EINVAL) )
{
if ((console_log_level != -1) && (ksyslog(8, NULL, console_log_level) < 0) &&
(errno == EINVAL)) {
/*
* An invalid arguement error probably indicates that
* 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.
*/
if (use_syscall ||
((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) )
{
((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT))) {
/* Initialize kernel logging. */
ksyslog(1, NULL, 0);
Syslog(LOG_INFO, "klogd v%s, log source = ksyslog "
"started.", PACKAGE_VERSION);
"started.",
PACKAGE_VERSION);
return (kernel);
}
#ifndef TESTING
if ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 )
{
fprintf(stderr, "klogd: Cannot open proc file system, " \
"%d - %s.\n", errno, strerror(errno));
if ((kmsg = open(_PATH_KLOG, O_RDONLY)) < 0) {
fprintf(stderr, "klogd: Cannot open proc file system, "
"%d - %s.\n",
errno, strerror(errno));
ksyslog(7, NULL, 0);
exit(1);
}
@ -570,23 +521,20 @@ static enum LOGSRC GetKernelLogSrc(void)
return (proc);
}
extern void Syslog(int priority, char *fmt, ...)
{
va_list ap;
char *argl;
if ( debugging )
{
if (debugging) {
fputs("Logging line:\n", stderr);
fprintf(stderr, "\tLine: %s\n", fmt);
fprintf(stderr, "\tPriority: %d\n", priority);
}
/* Handle output to a file. */
if ( output_file != (FILE *) 0 )
{
if (output_file != (FILE *)0) {
va_start(ap, fmt);
vfprintf(output_file, fmt, ap);
va_end(ap);
@ -598,14 +546,11 @@ extern void Syslog(int priority, char *fmt, ...)
}
/* Output using syslog. */
if (!strcmp(fmt, "%s"))
{
if (!strcmp(fmt, "%s")) {
va_start(ap, fmt);
argl = va_arg(ap, char *);
if (argl[0] == '<' && argl[1] && argl[2] == '>')
{
switch ( argl[1] )
{
if (argl[0] == '<' && argl[1] && argl[2] == '>') {
switch (argl[1]) {
case '0':
priority = LOG_EMERG;
break;
@ -647,11 +592,8 @@ extern void Syslog(int priority, char *fmt, ...)
#ifdef TESTING
printf("\n");
#endif
return;
}
/*
* Copy characters from ptr to line until a char in the delim
* 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 *delim)
{
auto int i;
auto int count;
int i;
int count;
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);
}
@ -709,23 +652,20 @@ static void LogLine(char *ptr, int len)
static char *sym_start; /* points at the '<' of a symbol */
auto int delta = 0; /* number of chars copied */
auto int symbols_expanded = 0; /* 1 if symbols were expanded */
auto int skip_symbol_lookup = 0; /* skip symbol lookup on this pass */
auto char *save_ptr = ptr; /* save start of input line */
auto int save_len = len; /* save length at start of input line */
int delta = 0; /* number of chars copied */
int symbols_expanded = 0; /* 1 if symbols were expanded */
int skip_symbol_lookup = 0; /* skip symbol lookup on this pass */
char *save_ptr = ptr; /* save start of input line */
int save_len = len; /* save length at start of input line */
while( len > 0 )
{
if( space == 0 ) /* line buffer is full */
{
while (len > 0) {
if (space == 0) { /* line buffer is full */
/*
** Line too long. Start a new line.
*/
*line = 0; /* force null terminator */
if ( debugging )
{
if (debugging) {
fputs("Line buffer full:\n", stderr);
fprintf(stderr, "\tLine: %s\n", line);
}
@ -740,8 +680,7 @@ static void LogLine(char *ptr, int len)
save_len = len;
}
switch( parse_state )
{
switch (parse_state) {
case PARSING_TEXT:
delta = copyin(line, space, ptr, len, "\n[");
line += delta;
@ -750,12 +689,9 @@ static void LogLine(char *ptr, int len)
len -= delta;
if (space == 0 || len == 0)
{
break; /* full line_buff or end of input buffer */
}
if( *ptr == '\0' ) /* zero byte */
{
if (*ptr == '\0') { /* zero byte */
ptr++; /* skip zero byte */
space -= 1;
len -= 1;
@ -763,8 +699,7 @@ static void LogLine(char *ptr, int len)
break;
}
if( *ptr == '\n' ) /* newline */
{
if (*ptr == '\n') { /* newline */
ptr++; /* skip newline */
space -= 1;
len -= 1;
@ -780,9 +715,7 @@ static void LogLine(char *ptr, int len)
skip_symbol_lookup = 1;
ptr = save_ptr;
len = save_len;
}
else
{
} else {
skip_symbol_lookup = 0;
save_ptr = ptr;
save_len = len;
@ -790,8 +723,7 @@ static void LogLine(char *ptr, int len)
}
break;
}
if( *ptr == '[' ) /* possible kernel symbol */
{
if (*ptr == '[') { /* possible kernel symbol */
*line++ = *ptr++;
space -= 1;
len -= 1;
@ -802,8 +734,7 @@ static void LogLine(char *ptr, int len)
break;
case PARSING_SYMSTART:
if( *ptr != '<' )
{
if (*ptr != '<') {
parse_state = PARSING_TEXT; /* not a symbol */
break;
}
@ -813,7 +744,6 @@ static void LogLine(char *ptr, int len)
** be a valid symbol, this char will be replaced later.
** If not, we'll just leave it there.
*/
sym_start = line; /* this will point at the '<' */
*line++ = *ptr++;
@ -829,11 +759,9 @@ static void LogLine(char *ptr, int len)
space -= delta;
len -= delta;
if (space == 0 || len == 0)
{
break; /* full line_buff or end of input buffer */
}
if( *ptr != '>' )
{
if (*ptr != '>') {
parse_state = PARSING_TEXT;
break;
}
@ -843,12 +771,10 @@ static void LogLine(char *ptr, int len)
len -= 1;
parse_state = PARSING_SYMEND;
break;
case PARSING_SYMEND:
if( *ptr != ']' )
{
if (*ptr != ']') {
parse_state = PARSING_TEXT; /* not a symbol */
break;
}
@ -858,19 +784,17 @@ static void LogLine(char *ptr, int len)
** symbol text.
*/
{
auto int sym_space;
unsigned long value;
auto struct symbol sym;
auto char *symbol;
struct symbol sym;
char *symbol;
int sym_space;
*(line - 1) = 0; /* null terminate the address string */
value = strtoul(sym_start + 1, (char **)0, 16);
*(line - 1) = '>'; /* put back delim */
symbol = LookupSymbol(value, &sym);
if ( !symbol_lookup || symbol == (char *) 0 )
{
if (!symbol_lookup || symbol == (char *)0) {
parse_state = PARSING_TEXT;
break;
}
@ -879,8 +803,7 @@ static void LogLine(char *ptr, int len)
** verify there is room in the line buffer
*/
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 */
break;
}
@ -899,18 +822,14 @@ static void LogLine(char *ptr, int len)
default: /* Can't get here! */
parse_state = PARSING_TEXT;
break;
}
}
return;
}
static void LogKernelLine(void)
{
auto int rdcnt;
int rdcnt;
/*
* Zero-fill the log buffer. This should cure a multitude of
@ -919,23 +838,21 @@ static void LogKernelLine(void)
* messages into this fresh 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)
return;
fprintf(stderr, "klogd: Error return from sys_sycall: " \
"%d - %s\n", errno, strerror(errno));
}
else
LogLine(log_buffer, rdcnt);
fprintf(stderr,
"klogd: Error return from sys_sycall: %d - %s\n",
errno, strerror(errno));
return;
}
LogLine(log_buffer, rdcnt);
}
static void LogProcLine(void)
{
auto int rdcnt;
int rdcnt;
/*
* 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.
*/
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)
return;
Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", \
Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.",
errno, strerror(errno));
}
else
LogLine(log_buffer, rdcnt);
return;
}
LogLine(log_buffer, rdcnt);
}
int usage(int code)
{
@ -980,95 +894,101 @@ int usage(int code)
" -v Show program version and exit\n"
" -x Omit EIP translation, i.e. do not read System.map file\n"
"\n"
"Bug report address: %s\n", PACKAGE_BUGREPORT);
"Bug report address: %s\n",
PACKAGE_BUGREPORT);
exit(code);
}
int main(argc, argv)
int argc;
char *argv[];
int main(int argc, char *argv[])
{
auto int ch,
use_output = 0;
auto char *log_level = (char *) 0,
*output = (char *) 0;
char *log_level = NULL;
char *output = NULL;
int use_output = 0;
int ch;
#ifndef TESTING
pid_t ppid = getpid();
chdir("/");
#endif
/* Parse the command-line. */
while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF)
switch((char)ch)
{
while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF) {
switch (ch) {
case '2': /* Print lines with symbols twice. */
symbols_twice = 1;
break;
case 'c': /* Set console message level. */
log_level = optarg;
break;
case 'd': /* Activity debug mode. */
debugging = 1;
break;
case 'f': /* Define an output file. */
output = optarg;
use_output++;
break;
case 'i': /* Reload module symbols. */
SignalDaemon(SIGUSR1);
return (0);
case 'I':
SignalDaemon(SIGUSR2);
return (0);
case 'k': /* Kernel symbol file. */
symfile = optarg;
break;
case 'n': /* don't fork */
no_fork++;
break;
case 'o': /* One-shot mode. */
one_shot = 1;
break;
case 'p':
SetParanoiaLevel(1); /* Load symbols on oops. */
break;
case 's': /* Use syscall interface. */
use_syscall = 1;
break;
case 'v':
printf("klogd v%s\n", VERSION);
exit(1);
case 'x':
symbol_lookup = 0;
break;
case '?':
usage(0);
break;
default:
usage(1);
break;
}
}
/* Set console logging level. */
if ( log_level != (char *) 0 )
{
if ( (strlen(log_level) > 1) || \
(strchr("12345678", *log_level) == (char *) 0) )
{
if (log_level != (char *)0) {
if ((strlen(log_level) > 1) ||
(strchr("12345678", *log_level) == (char *)0)) {
fprintf(stderr, "klogd: Invalid console logging "
"level <%s> specified.\n", log_level);
"level <%s> specified.\n",
log_level);
return (1);
}
console_log_level = *log_level - '0';
}
#ifndef TESTING
/*
* 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
* such process running.
*/
if ( (!one_shot) && (!no_fork) )
{
if (!check_pid(PidFile))
{
if ((!one_shot) && (!no_fork)) {
if (!check_pid(PidFile)) {
signal(SIGTERM, doexit);
if ( fork() == 0 )
{
auto int fl;
if (fork() == 0) {
int num_fds = getdtablesize();
int fl;
signal(SIGTERM, SIG_DFL);
/* 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 (strcmp(output, "-") == 0)
continue;
@ -1103,9 +1019,7 @@ int main(argc, argv)
}
setsid();
}
else
{
} else {
/*
* Parent process
*/
@ -1115,23 +1029,17 @@ int main(argc, argv)
*/
exit(1);
}
}
else
{
} else {
fputs("klogd: Already running.\n", stderr);
exit(1);
}
}
/* tuck my process id away */
if (!check_pid(PidFile))
{
if (!check_pid(PidFile)) {
if (!write_pid(PidFile))
Terminate();
}
else
{
} else {
fputs("klogd: Already running.\n", stderr);
Terminate();
}
@ -1149,26 +1057,21 @@ int main(argc, argv)
signal(SIGUSR1, reload_daemon);
signal(SIGUSR2, reload_daemon);
/* Open outputs. */
if ( use_output )
{
if (use_output) {
if (strcmp(output, "-") == 0)
output_file = stdout;
else if ( (output_file = fopen(output, "w")) == (FILE *) 0 )
{
fprintf(stderr, "klogd: Cannot open output file " \
"%s - %s\n", output, strerror(errno));
else if ((output_file = fopen(output, "w")) == (FILE *)0) {
fprintf(stderr, "klogd: Cannot open output file "
"%s - %s\n",
output, strerror(errno));
return (1);
}
}
else
} else
openlog("kernel", 0, LOG_KERN);
/* Handle one-shot logging. */
if ( one_shot )
{
if (one_shot) {
if (symbol_lookup) {
InitKsyms(symfile);
InitMsyms();
@ -1196,18 +1099,19 @@ int main(argc, argv)
#endif
/* The main loop. */
while (1)
{
while (1) {
if (change_state)
ChangeLogging();
switch ( logsrc )
{
switch (logsrc) {
case kernel:
LogKernelLine();
break;
case proc:
LogProcLine();
break;
case none:
pause();
break;
@ -1216,9 +1120,8 @@ int main(argc, argv)
}
/**
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -1,22 +1,22 @@
/*
klogd.h - main header file for Linux kernel log daemon.
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 program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* klogd.h - main header file for Linux kernel log daemon.
* 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 program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*

View File

@ -125,18 +125,16 @@
* the first hit.
*/
/* Includes. */
#include <stdlib.h>
#include <malloc.h>
#include <sys/utsname.h>
#include "klogd.h"
#include "ksyms.h"
#include "module.h"
#include <malloc.h>
#include <stdlib.h>
#include <sys/utsname.h>
#define VERBOSE_DEBUGGING 0
int num_syms = 0;
static int i_am_paranoid = 0;
static char vstring[12];
@ -153,14 +151,12 @@ static char *system_maps[] =
(char *)0
};
#if defined(TEST)
int debugging;
#else
extern int debugging;
#endif
/* Function prototypes. */
static char *FindSymbolFile(void);
static int AddSymbol(unsigned long, char *);
@ -168,7 +164,6 @@ static void FreeSymbols(void);
static int CheckVersion(char *);
static int CheckMapVersion(char *);
/**************************************************************************
* Function: InitKsyms
*
@ -186,34 +181,23 @@ static int CheckMapVersion(char *);
* A boolean style context is returned. The return value will
* be true if initialization was successful. False if not.
**************************************************************************/
extern int InitKsyms(mapfile)
char *mapfile;
int InitKsyms(char *mapfile)
{
auto char type,
sym[512];
auto int version = 0;
auto unsigned long int address;
auto FILE *sym_file;
unsigned long int address;
FILE *sym_file;
char sym[512];
char type;
int version = 0;
/* Check and make sure that we are starting with a clean slate. */
if (num_syms > 0)
FreeSymbols();
/*
* Search for and open the file containing the kernel symbols.
*/
if ( mapfile == (char *) 0 )
{
if ( (mapfile = FindSymbolFile()) == (char *) 0 )
{
if (mapfile == NULL) {
if ((mapfile = FindSymbolFile()) == NULL) {
Syslog(LOG_WARNING, "Cannot find a map file.");
if (debugging)
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);
if (debugging)
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
* correctness -- GW.
*/
while ( !feof(sym_file) )
{
if ( fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym)
!= 3 )
{
while (!feof(sym_file)) {
if (fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym) != 3) {
Syslog(LOG_ERR, "Error in symbol table input (#1).");
fclose(sym_file);
return (0);
@ -250,8 +230,7 @@ extern int InitKsyms(mapfile)
fprintf(stderr, "Address: %lx, Type: %c, Symbol: %s\n",
address, type, sym);
if ( AddSymbol(address, sym) == 0 )
{
if (AddSymbol(address, sym) == 0) {
Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
fclose(sym_file);
return (0);
@ -261,17 +240,15 @@ extern int InitKsyms(mapfile)
version = CheckVersion(sym);
}
Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
switch ( version )
{
switch (version) {
case -1:
Syslog(LOG_WARNING, "Symbols do not match kernel version.");
num_syms = 0;
break;
case 0:
Syslog(LOG_WARNING, "Cannot verify that symbols match " \
Syslog(LOG_WARNING, "Cannot verify that symbols match "
"kernel version.");
break;
@ -284,7 +261,6 @@ extern int InitKsyms(mapfile)
return (1);
}
/**************************************************************************
* Function: FindSymbolFile
*
@ -317,20 +293,15 @@ extern int InitKsyms(mapfile)
* caller which points to the name of the file containing
* the symbol table to be used.
**************************************************************************/
static char * FindSymbolFile()
static char *FindSymbolFile(void)
{
auto char *file = (char *) 0,
**mf = system_maps;
auto struct utsname utsname;
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.");
return (0);
}
@ -338,8 +309,7 @@ static char * FindSymbolFile()
if (debugging)
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);
if (debugging)
@ -359,7 +329,6 @@ static char * FindSymbolFile()
fclose(sym_file);
}
}
}
/*
@ -371,7 +340,6 @@ static char * FindSymbolFile()
return (file);
}
/**************************************************************************
* Function: CheckVersion
*
@ -408,25 +376,17 @@ static char * FindSymbolFile()
* 1:-> The executing kernel is of the same version
* as the version string.
**************************************************************************/
static int CheckVersion(version)
char *version;
static int CheckVersion(char *version)
{
auto int vnum,
major,
minor,
patch;
#ifndef TESTING
int kvnum;
auto struct utsname utsname;
#endif
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. */
if (strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ ||
@ -436,7 +396,6 @@ static int CheckVersion(version)
else
return (0);
/*
* Since the symbol looks like a kernel version we can start
* things out by decoding the version string into its component
@ -447,9 +406,11 @@ static int CheckVersion(version)
minor = (vnum >> 8) & 0x000000FF;
major = (vnum >> 16) & 0x000000FF;
if (debugging)
fprintf(stderr, "Version string = %s, Major = %d, " \
"Minor = %d, Patch = %d.\n", version +
strlen(prefix), major, minor, \
fprintf(stderr, "Version string = %s, Major = %d, "
"Minor = %d, Patch = %d.\n",
version +
strlen(prefix),
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
* version level.
*/
if ( uname(&utsname) < 0 )
{
if (uname(&utsname) < 0) {
Syslog(LOG_ERR, "Cannot get kernel version information.");
return (0);
}
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);
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'.",
utsname.release);
return (0);
@ -489,7 +448,6 @@ static int CheckVersion(version)
return (1);
}
/**************************************************************************
* Function: CheckMapVersion
*
@ -514,18 +472,13 @@ static int CheckVersion(version)
* 1:-> The executing kernel is of the same version
* as the version of the map file.
**************************************************************************/
static int CheckMapVersion(fname)
char *fname;
static int CheckMapVersion(char *fname)
{
int version;
unsigned long int address;
FILE *sym_file;
auto unsigned long int address;
auto char type,
sym[512];
char sym[512];
char type;
int version;
if ((sym_file = fopen(fname, "r")) != (FILE *)0) {
/*
@ -536,38 +489,36 @@ static int CheckMapVersion(fname)
Syslog(LOG_INFO, "Inspecting %s", fname);
version = 0;
while ( !feof(sym_file) && (version == 0) )
{
if ( fscanf(sym_file, "%lx %c %511s\n", &address, \
&type, sym) != 3 )
{
while (!feof(sym_file) && (version == 0)) {
if (fscanf(sym_file, "%lx %c %511s\n", &address,
&type, sym) != 3) {
Syslog(LOG_ERR, "Error in symbol table input (#2).");
fclose(sym_file);
return (0);
}
if (VERBOSE_DEBUGGING && debugging)
fprintf(stderr, "Address: %lx, Type: %c, " \
"Symbol: %s\n", address, type, sym);
fprintf(stderr, "Address: %lx, Type: %c, "
"Symbol: %s\n",
address, type, sym);
version = CheckVersion(sym);
}
fclose(sym_file);
switch ( version )
{
switch (version) {
case -1:
Syslog(LOG_ERR, "Symbol table has incorrect " \
Syslog(LOG_ERR, "Symbol table has incorrect "
"version number.\n");
break;
case 0:
if (debugging)
fprintf(stderr, "No version information " \
fprintf(stderr, "No version information "
"found.\n");
break;
case 1:
if (debugging)
fprintf(stderr, "Found table with " \
fprintf(stderr, "Found table with "
"matching version number.\n");
break;
}
@ -578,7 +529,6 @@ static int CheckMapVersion(fname)
return (0);
}
/**************************************************************************
* Function: AddSymbol
*
@ -592,24 +542,16 @@ static int CheckMapVersion(fname)
* A boolean value is assumed. True if the addition is
* successful. False if not.
**************************************************************************/
static int AddSymbol(address, symbol)
unsigned long address;
char *symbol;
static int AddSymbol(unsigned long address, char *symbol)
{
/* Allocate the the symbol table entry. */
sym_array = (struct sym_table *) realloc(sym_array, (num_syms+1) * \
sizeof(struct sym_table));
if ( sym_array == (struct sym_table *) 0 )
sym_array = realloc(sym_array, (num_syms + 1) * sizeof(struct sym_table));
if (sym_array == NULL)
return (0);
/* Then the space for the symbol. */
sym_array[num_syms].name = (char *) malloc(strlen(symbol)*sizeof(char)\
+ 1);
if ( sym_array[num_syms].name == (char *) 0 )
sym_array[num_syms].name = malloc(strlen(symbol) * sizeof(char) + 1);
if (sym_array[num_syms].name == NULL)
return (0);
sym_array[num_syms].value = address;
@ -618,7 +560,6 @@ static int AddSymbol(address, symbol)
return (1);
}
/**************************************************************************
* Function: LookupSymbol
*
@ -638,20 +579,12 @@ static int AddSymbol(address, symbol)
* If a match is found the pointer to the symbolic name most
* closely matching the address is returned.
**************************************************************************/
char * LookupSymbol(value, sym)
unsigned long value;
struct symbol *sym;
char *LookupSymbol(unsigned long value, struct symbol *sym)
{
auto int lp;
auto char *last;
auto char *name;
struct symbol ksym, msym;
char *last;
char *name;
int lp;
if (!sym_array)
return ((char *)0);
@ -662,12 +595,10 @@ char * LookupSymbol(value, sym)
if (value < sym_array[0].value)
return ((char *)0);
for(lp = 0; lp <= num_syms; ++lp)
{
if ( sym_array[lp].value > value )
{
for (lp = 0; lp <= num_syms; ++lp) {
if (sym_array[lp].value > 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;
break;
}
@ -676,30 +607,24 @@ char * LookupSymbol(value, sym)
name = LookupModuleSymbol(value, &msym);
if ( ksym.offset == 0 && msym.offset == 0 )
{
return((char *) 0);
if (ksym.offset == 0 && msym.offset == 0) {
return NULL;
}
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->size = ksym.size;
return (last);
}
else
{
} else {
sym->offset = msym.offset;
sym->size = msym.size;
return (name);
}
return((char *) 0);
return NULL;
}
/**************************************************************************
* Function: FreeSymbols
*
@ -713,10 +638,9 @@ char * LookupSymbol(value, sym)
* Return: void
**************************************************************************/
static void FreeSymbols()
static void FreeSymbols(void)
{
auto int lp;
int lp;
/* Free each piece of memory allocated for symbol names. */
for (lp = 0; lp < num_syms; ++lp)
@ -726,11 +650,8 @@ static void FreeSymbols()
free(sym_array);
sym_array = (struct sym_table *)0;
num_syms = 0;
return;
}
/**************************************************************************
* Function: LogExpanded
*
@ -749,23 +670,16 @@ static void FreeSymbols()
* Return: void
**************************************************************************/
extern char * ExpandKadds(line, el)
char *line;
char *el;
char *ExpandKadds(char *line, char *el)
{
auto char dlm,
*kp,
*sl = line,
*elp = el,
*symbol;
unsigned long int value;
struct symbol sym;
char *symbol;
char *elp = el;
char *sl = line;
char *kp;
char num[15];
auto unsigned long int value;
auto struct symbol sym;
char dlm;
sym.offset = 0;
sym.size = 0;
@ -791,27 +705,23 @@ extern char * ExpandKadds(line, el)
(strstr(line, "Oops:") != (char *)0) && !InitMsyms())
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
/*
* Early return if there do not appear to be any kernel
* messages in this line.
*/
if ((num_syms == 0) ||
(kp = strstr(line, "[<")) == (char *) 0 )
{
(kp = strstr(line, "[<")) == (char *)0) {
strcpy(el, line);
return (el);
}
/* Loop through and expand all kernel messages. */
do
{
do {
while (sl < kp + 1)
*elp++ = *sl++;
/* Now poised at a kernel delimiter. */
if ( (kp = strstr(sl, ">]")) == (char *) 0 )
{
if ((kp = strstr(sl, ">]")) == (char *)0) {
strcpy(el, sl);
return (el);
}
@ -825,14 +735,13 @@ extern char * ExpandKadds(line, el)
strcat(elp, symbol);
elp += strlen(symbol);
if (debugging)
fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n", \
sl+1, value, \
(sym.size==0) ? symbol+1 : symbol, \
fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n",
sl + 1, value,
(sym.size == 0) ? symbol + 1 : symbol,
sym.offset, sym.size);
value = 2;
if ( sym.size != 0 )
{
if (sym.size != 0) {
--value;
++kp;
elp += sprintf(elp, "+0x%x/0x%02x", sym.offset, sym.size);
@ -842,15 +751,13 @@ extern char * ExpandKadds(line, el)
sl = kp + value;
if ((kp = strstr(sl, "[<")) == (char *)0)
strcat(elp, sl);
}
while ( kp != (char *) 0);
} while (kp != (char *)0);
if (debugging)
fprintf(stderr, "Expanded line: %s\n", el);
return (el);
}
/**************************************************************************
* Function: SetParanoiaLevel
*
@ -864,17 +771,12 @@ extern char * ExpandKadds(line, el)
* present when resolving kernel exceptions.
* Return: void
**************************************************************************/
extern void SetParanoiaLevel(level)
int level;
void SetParanoiaLevel(int level)
{
i_am_paranoid = level;
return;
}
/*
* Setting the -DTEST define enables the following code fragment to
* be compiled. This produces a small standalone program which will
@ -885,37 +787,30 @@ extern void SetParanoiaLevel(level)
#include <stdarg.h>
extern int main(int, char **);
extern int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
auto char line[1024], eline[2048];
char line[1024], eline[2048];
debugging = 1;
if ( !InitKsyms((char *) 0) )
{
if (!InitKsyms((char *)0)) {
fputs("ksym: Error loading system map.\n", stderr);
return (1);
}
while ( !feof(stdin) )
{
while (!feof(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));
ExpandKadds(line, eline);
fprintf(stdout, "%s\n", eline);
}
return (0);
}
extern void Syslog(int priority, char *fmt, ...)
void Syslog(int priority, char *fmt, ...)
{
va_list ap;
@ -930,9 +825,8 @@ extern void Syslog(int priority, char *fmt, ...)
#endif
/**
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -103,26 +103,25 @@
* the first hit.
*/
/* Includes. */
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <ctype.h>
#include <malloc.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <malloc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#ifdef SYSV
#include <fcntl.h>
#else
#include <sys/msgbuf.h>
#endif
#include <sys/stat.h>
#include "module.h"
#include <stdarg.h>
#include <paths.h>
#include <linux/version.h>
#include <paths.h>
#include <stdarg.h>
#include <sys/stat.h>
#include "klogd.h"
#include "ksyms.h"
@ -140,7 +139,6 @@ static int debugging = 1;
extern int debugging;
#endif
/* Function prototypes. */
static void FreeModules(void);
static int AddSymbol(const char *);
@ -166,39 +164,36 @@ extern int num_syms;
* True if loading is successful.
**************************************************************************/
extern int InitMsyms()
extern int InitMsyms(void)
{
auto int rtn,
tmp;
FILE *ksyms;
char buf[128];
char *p;
char buf[128];
int rtn;
int tmp;
/* Initialize the kernel module symbol table. */
FreeModules();
ksyms = fopen(KSYMS, "r");
if ( ksyms == NULL )
{
if (ksyms == NULL) {
if (errno == ENOENT)
Syslog(LOG_INFO, "No module symbols loaded - "
"kernel modules not enabled.\n");
else
Syslog(LOG_ERR, "Error loading kernel symbols " \
"- %s\n", strerror(errno));
Syslog(LOG_ERR, "Error loading kernel symbols "
"- %s\n",
strerror(errno));
return (0);
}
if (debugging)
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)
continue;
@ -219,45 +214,39 @@ extern int InitMsyms()
have_modules = 1;
/* 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;
if (sym_array_modules[tmp].num_syms < 2)
continue;
qsort(sym_array_modules[tmp].sym_array, \
sym_array_modules[tmp].num_syms, \
qsort(sym_array_modules[tmp].sym_array,
sym_array_modules[tmp].num_syms,
sizeof(struct sym_table), symsort);
}
if (rtn == 0)
Syslog(LOG_INFO, "No module symbols loaded.");
else
Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn, \
(rtn == 1) ? "symbol" : "symbols", \
Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn,
(rtn == 1) ? "symbol" : "symbols",
num_modules, (num_modules == 1) ? "." : "s.");
return (1);
}
static int symsort(p1, p2)
const void *p1;
const void *p2;
static int symsort(const void *p1, const void *p2)
{
auto const struct sym_table *sym1 = p1,
const struct sym_table *sym1 = p1,
*sym2 = p2;
if (sym1->value < sym2->value)
return (-1);
if (sym1->value == sym2->value)
return (0);
return (1);
}
/**************************************************************************
* Function: FreeModules
*
@ -268,15 +257,11 @@ static int symsort(p1, p2)
*
* Return: void
**************************************************************************/
static void FreeModules()
static void FreeModules(void)
{
auto int nmods,
nsyms;
auto struct Module *mp;
struct Module *mp;
int nmods;
int nsyms;
/* Check to see if the module symbol tables need to be cleared. */
have_modules = 0;
@ -286,8 +271,7 @@ static void FreeModules()
if (sym_array_modules == NULL)
return;
for (nmods = 0; nmods < num_modules; ++nmods)
{
for (nmods = 0; nmods < num_modules; ++nmods) {
mp = &sym_array_modules[nmods];
if (mp->num_syms == 0)
continue;
@ -305,7 +289,6 @@ static void FreeModules()
return;
}
/**************************************************************************
* Function: AddModule
*
@ -319,33 +302,21 @@ static void FreeModules()
* Return: struct Module *
**************************************************************************/
struct Module *AddModule(module)
const char *module;
struct Module *AddModule(const char *module)
{
struct Module *mp;
if ( num_modules == 0 )
{
if (num_modules == 0) {
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");
return NULL;
}
mp = sym_array_modules;
}
else
{
} else {
/* Allocate space for the module. */
mp = (struct Module *) \
realloc(sym_array_modules, \
(num_modules+1) * sizeof(struct Module));
if ( mp == NULL )
{
mp = realloc(sym_array_modules, (num_modules + 1) * sizeof(struct Module));
if (mp == NULL) {
Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
return NULL;
}
@ -366,7 +337,6 @@ struct Module *AddModule(module)
return mp;
}
/**************************************************************************
* Function: AddSymbol
*
@ -387,22 +357,16 @@ struct Module *AddModule(module)
* A boolean value is assumed. True if the addition is
* successful. False if not.
**************************************************************************/
static int AddSymbol(line)
const char *line;
static int AddSymbol(const char *line)
{
char *module;
unsigned long address;
char *p;
static char *lastmodule = NULL;
struct Module *mp;
unsigned long address;
char *module;
char *p;
module = index(line, '[');
if ( module != NULL )
{
if (module != NULL) {
p = index(module, ']');
if (p != NULL)
@ -410,15 +374,14 @@ static int AddSymbol(line)
p = module++;
while ( isspace(*(--p)) );
while (isspace(*(--p)))
;
*(++p) = '\0';
}
p = index(line, ' ');
if (p == NULL)
return (0);
*p = '\0';
address = strtoul(line, (char **)0, 16);
@ -428,20 +391,18 @@ static int AddSymbol(line)
if (num_modules == 0 ||
(lastmodule == NULL && module != NULL) ||
(module == NULL && lastmodule != NULL) ||
( module != NULL && strcmp(module, lastmodule)))
{
(module != NULL && strcmp(module, lastmodule))) {
mp = AddModule(module);
if (mp == NULL)
return (0);
}
else
} else
mp = &sym_array_modules[num_modules - 1];
lastmodule = mp->name;
/* 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));
if (mp->sym_array == (struct sym_table *)0)
@ -458,7 +419,6 @@ static int AddSymbol(line)
return (1);
}
/**************************************************************************
* Function: LookupModuleSymbol
*
@ -478,31 +438,20 @@ static int AddSymbol(line)
* If a match is found the pointer to the symbolic name most
* closely matching the address is returned.
**************************************************************************/
extern char * LookupModuleSymbol(value, sym)
unsigned long value;
struct symbol *sym;
char *LookupModuleSymbol(unsigned long value, struct symbol *sym)
{
auto int nmod,
nsym;
auto struct sym_table *last;
auto struct Module *mp;
static char ret[100];
struct sym_table *last;
struct Module *mp;
int nmod;
int nsym;
sym->size = 0;
sym->offset = 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];
/*
@ -511,17 +460,14 @@ extern char * LookupModuleSymbol(value, sym)
*/
for (nsym = 1, last = &mp->sym_array[0];
nsym < mp->num_syms;
++nsym)
{
if ( mp->sym_array[nsym].value > value )
{
++nsym) {
if (mp->sym_array[nsym].value > value) {
if (sym->size == 0 ||
(value - last->value) < sym->offset ||
((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->size = mp->sym_array[nsym].value - \
sym->size = mp->sym_array[nsym].value -
last->value;
ret[sizeof(ret) - 1] = '\0';
if (mp->name == NULL)
@ -541,10 +487,9 @@ extern char * LookupModuleSymbol(value, sym)
return (ret);
/* It has been a hopeless exercise. */
return((char *) 0);
return NULL;
}
/*
* Setting the -DTEST define enables the following code fragment to
* be compiled. This produces a small standalone program which will
@ -554,42 +499,29 @@ extern char * LookupModuleSymbol(value, sym)
#include <stdarg.h>
extern int main(int, char **);
int main(argc, argv)
int argc;
char *argv[];
int main(int argc, char *argv[])
{
auto int lp, syms;
int lp, syms;
if ( !InitMsyms() )
{
if (!InitMsyms()) {
fprintf(stderr, "Cannot load module symbols.\n");
return (1);
}
printf("Number of modules: %d\n\n", num_modules);
for(lp= 0; lp < num_modules; ++lp)
{
printf("Module #%d = %s, Number of symbols = %d\n", lp + 1, \
for (lp = 0; lp < num_modules; ++lp) {
printf("Module #%d = %s, Number of symbols = %d\n", lp + 1,
sym_array_modules[lp].name == NULL
? "kernel space"
:sym_array_modules[lp].name, \
: sym_array_modules[lp].name,
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("\tName: %s\n", \
printf("\tName: %s\n",
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);
}
}
@ -598,8 +530,7 @@ int main(argc, argv)
return (0);
}
extern void Syslog(int priority, char *fmt, ...)
void Syslog(int priority, char *fmt, ...)
{
va_list ap;
@ -615,9 +546,8 @@ extern void Syslog(int priority, char *fmt, ...)
#endif /* TEST */
/**
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -1,29 +1,28 @@
/*
ksym.h - Definitions for symbol table utilities.
Copyright (c) 1995, 1996 Dr. G.W. Wettstein <greg@wind.rmcc.com>
Copyright (c) 1996 Enjellic Systems Development
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* ksym.h - Definitions for symbol table utilities.
* Copyright (c) 1995, 1996 Dr. G.W. Wettstein <greg@wind.rmcc.com>
* Copyright (c) 1996 Enjellic Systems Development
*
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Variables, structures and type definitions static to this module. */
struct symbol
{
struct symbol {
char *name;
int size;
int offset;

View File

@ -1,23 +1,23 @@
/*
module.h - Miscellaneous module definitions
Copyright (c) 1996 Richard Henderson <rth@tamu.edu>
Copyright (c) 2004-7 Martin Schulze <joey@infodrom.org>
This file is part of the sysklogd package.
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* module.h - Miscellaneous module definitions
* Copyright (c) 1996 Richard Henderson <rth@tamu.edu>
* Copyright (c) 2004-7 Martin Schulze <joey@infodrom.org>
*
* This file is part of the sysklogd package.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ChangeLog:
@ -35,14 +35,12 @@
* ksym_mod.c over here.
*/
struct sym_table
{
struct sym_table {
unsigned long value;
char *name;
};
struct Module
{
struct Module {
struct sym_table *sym_array;
int num_syms;

View File

@ -29,11 +29,11 @@
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/proc_fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/time.h>
#define MODNAME "oops"
@ -75,13 +75,14 @@ struct code priorities[] = {
void oops_decode_level(char *line)
{
char *p;
struct code *prio;
char *p;
if (strncmp(line, "level:", 6))
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++)
if (!strcmp(p, prio->name)) {
@ -95,9 +96,8 @@ void oops_decode_level (char *line)
*/
static void oops(void)
{
auto unsigned long *p = (unsigned long *) 828282828;
unsigned long *p = (unsigned long *)828282828;
*p = 5;
return;
}
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
oops_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
{
char s[70];
int size;
struct code *prio;
char *level = NULL;
char s[70];
int size;
#ifdef DEBUG
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;
prio->name && prio->level != oops_data.loglevel;
prio++);
prio++)
;
level = prio->name;
if (oops_data.lastoops == 0)
@ -244,7 +244,12 @@ void oops_cleanup (void)
printk(KERN_INFO "Removing module " MODNAME ".\n");
}
module_init(oops_init);
module_exit(oops_cleanup);
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -1,22 +1,22 @@
/*
pidfile.c - interact with pidfiles
Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
* pidfile.c - interact with pidfiles
* Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
*
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
*/
/*
@ -24,14 +24,14 @@
* 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 <signal.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
*
@ -41,13 +41,16 @@
*/
int read_pid(char *pidfile)
{
FILE *f;
FILE *fp;
int pid;
if (!(f=fopen(pidfile,"r")))
fp = fopen(pidfile, "r");
if (!fp)
return 0;
fscanf(f,"%d", &pid);
fclose(f);
fscanf(fp, "%d", &pid);
fclose(fp);
return pid;
}
@ -84,30 +87,29 @@ int check_pid (char *pidfile)
*/
int write_pid(char *pidfile)
{
FILE *f;
FILE *fp;
int fd;
int pid;
if ( ((fd = open(pidfile, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1)
|| ((f = fdopen(fd, "r+")) == NULL) ) {
if (((fd = open(pidfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) || ((fp = fdopen(fd, "r+")) == NULL)) {
fprintf(stderr, "Can't open or create %s.\n", pidfile);
return 0;
}
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
fscanf(f, "%d", &pid);
fclose(f);
fscanf(fp, "%d", &pid);
fclose(fp);
printf("Can't lock, lock is held by pid %d.\n", pid);
return 0;
}
pid = getpid();
if (!fprintf(f,"%d\n", pid)) {
if (!fprintf(fp, "%d\n", pid)) {
printf("Can't write pid , %s.\n", strerror(errno));
close(fd);
return 0;
}
fflush(f);
fflush(fp);
if (flock(fd, LOCK_UN) == -1) {
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
@ -139,3 +141,9 @@ int remove_pid (char *pidfile)
return unlink(pidfile);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -1,22 +1,22 @@
/*
pidfile.h - interact with pidfiles
Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
* pidfile.h - interact with pidfiles
* Copyright (c) 1995 Martin Schulze <Martin.Schulze@Linux.DE>
*
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*/
/* read_pid

View File

@ -52,21 +52,21 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90";
* reconnect klogd to the logger after it went away.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.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/socket.h>
#include <sys/syslog.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <netdb.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <paths.h>
#include <stdio.h>
#include <fcntl.h>
#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 int LogFacility = LOG_USER; /* default facility code */
void
syslog(int pri, const char *fmt, ...)
void syslog(int pri, const char *fmt, ...)
{
va_list ap;
@ -86,18 +85,14 @@ syslog(int pri, const char *fmt, ...)
va_end(ap);
}
void
vsyslog(pri, fmt, ap)
int pri;
const char *fmt;
va_list ap;
void vsyslog(int pri, const char *fmt, va_list ap)
{
register int cnt;
register char *p;
int cnt;
char * p;
time_t now;
int fd, saved_errno;
int result;
char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0;
char tbuf[2048], fmt_cpy[1024], *stdp = NULL;
saved_errno = errno;
@ -114,16 +109,19 @@ vsyslog(pri, fmt, ap)
/* build the message */
(void)time(&now);
(void)sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4);
for (p = tbuf; *p; ++p);
for (p = tbuf; *p; ++p)
;
if (LogStat & LOG_PERROR)
stdp = p;
if (LogTag) {
(void)strcpy(p, LogTag);
for (; *p; ++p);
for (; *p; ++p)
;
}
if (LogStat & LOG_PID) {
(void)sprintf(p, "[%d]", getpid());
for (; *p; ++p);
for (; *p; ++p)
;
}
if (LogTag) {
*p++ = ':';
@ -132,7 +130,7 @@ vsyslog(pri, fmt, ap)
/* substitute error message for %m */
{
register char ch, *t1, *t2;
char ch, *t1, *t2;
char *strerror();
for (t1 = fmt_cpy;
@ -141,9 +139,9 @@ vsyslog(pri, fmt, ap)
if (ch == '%' && fmt[1] == 'm') {
++fmt;
for (t2 = strerror(saved_errno);
(*t1 = *t2++); ++t1);
}
else
(*t1 = *t2++); ++t1)
;
} else
*t1++ = ch;
*t1 = '\0';
}
@ -155,7 +153,7 @@ vsyslog(pri, fmt, ap)
/* output to stderr if requested */
if (LogStat & LOG_PERROR) {
struct iovec iov[2];
register struct iovec *v = iov;
struct iovec *v = iov;
v->iov_base = stdp;
v->iov_len = cnt - (stdp - tbuf);
@ -168,8 +166,7 @@ vsyslog(pri, fmt, ap)
/* output the message to the local logger */
result = write(LogFile, tbuf, cnt + 1);
if (result == -1
&& (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) {
if (result == -1 && (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) {
closelog();
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
result = write(LogFile, tbuf, cnt + 1);
@ -197,10 +194,7 @@ static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
/*
* OPENLOG -- open system log
*/
void
openlog(ident, logstat, logfac)
const char *ident;
int logstat, logfac;
void openlog(const char *ident, int logstat, int logfac)
{
if (ident != NULL)
LogTag = ident;
@ -224,8 +218,7 @@ openlog(ident, logstat, logfac)
}
}
if (LogFile != -1 && !connected &&
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+
strlen(SyslogAddr.sa_data)) != -1)
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family) + strlen(SyslogAddr.sa_data)) != -1)
#else
LogFile = fileno(stdout);
#endif
@ -235,8 +228,7 @@ openlog(ident, logstat, logfac)
/*
* CLOSELOG -- close the system log
*/
void
closelog()
void closelog()
{
#ifndef TESTING
(void)close(LogFile);
@ -249,9 +241,7 @@ static int LogMask = 0xff; /* mask of priorities to be logged */
/*
* SETLOGMASK -- set the log mask level
*/
int
setlogmask(pmask)
int pmask;
int setlogmask(int pmask)
{
int omask;
@ -260,3 +250,10 @@ setlogmask(pmask)
LogMask = pmask;
return (omask);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -17,47 +17,38 @@
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/param.h>
extern int main(int, char **);
int main(int argc, char *argv[])
{
auto char *nl,
bufr[512];
auto int logged = 0;
char *nl,
char bufr[512];
int logged = 0;
openlog("DOTEST", LOG_PID, LOG_DAEMON);
if (argc > 1)
{
if ( (*argv[1] == '-') && (*(argv[1]+1) == '\0') )
{
if (argc > 1) {
if ((*argv[1] == '-') && (*(argv[1] + 1) == '\0')) {
while (!feof(stdin))
if ( fgets(bufr, sizeof(bufr), stdin) != \
(char *) 0 )
{
if ( (nl = strrchr(bufr, '\n')) != \
if (fgets(bufr, sizeof(bufr), stdin) !=
(char *)0) {
if ((nl = strrchr(bufr, '\n')) !=
(char *)0)
*nl = '\0';
syslog(LOG_INFO, "%s", bufr);
logged += strlen(bufr);
if ( logged > 1024 )
{
if (logged > 1024) {
sleep(1);
logged = 0;
}
}
}
else
} else
while (argc-- > 1)
syslog(LOG_INFO, "%s", argv++ [1]);
}
else
{
} else {
syslog(LOG_EMERG, "EMERG log.");
syslog(LOG_ALERT, "Alert log.");
syslog(LOG_CRIT, "Critical log.");
@ -72,3 +63,10 @@ int main(int argc, char *argv[])
return (0);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

File diff suppressed because it is too large Load Diff