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

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,23 @@
/* /*
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.
*/ */
/* /*
* Symbols and definitions needed by klogd. * Symbols and definitions needed by klogd.
@ -33,8 +33,8 @@
/* Function prototypes. */ /* Function prototypes. */
extern int InitKsyms(char *); extern int InitKsyms(char *);
extern int InitMsyms(void); extern int InitMsyms(void);
extern char * ExpandKadds(char *, char *); extern char *ExpandKadds(char *, char *);
extern void SetParanoiaLevel(int); extern void SetParanoiaLevel(int);
extern void Syslog(int priority, char *fmt, ...); extern void Syslog(int priority, char *fmt, ...);

View File

@ -125,34 +125,31 @@
* 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]; static struct sym_table *sym_array = (struct sym_table *)0;
static struct sym_table *sym_array = (struct sym_table *) 0;
static char *system_maps[] = static char *system_maps[] =
{ {
"/boot/System.map", "/boot/System.map",
"/System.map", "/System.map",
"/usr/src/linux/System.map", "/usr/src/linux/System.map",
#if defined(TEST) #if defined(TEST)
"./System.map", "./System.map",
#endif #endif
(char *) 0 (char *)0
}; };
#if defined(TEST) #if defined(TEST)
int debugging; int debugging;
@ -160,14 +157,12 @@ int debugging;
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 *);
static void FreeSymbols(void); 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,47 +181,35 @@ 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);
return(0); return (0);
} }
} }
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);
return(0); return (0);
} }
/* /*
@ -237,54 +220,47 @@ 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);
} }
if ( VERBOSE_DEBUGGING && debugging ) if (VERBOSE_DEBUGGING && debugging)
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);
} }
if ( version == 0 ) if (version == 0)
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;
case 1: case 1:
Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring); Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring);
break; break;
} }
fclose(sym_file); fclose(sym_file);
return(1); return (1);
} }
/************************************************************************** /**************************************************************************
* Function: FindSymbolFile * Function: FindSymbolFile
* *
@ -317,61 +293,53 @@ 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) {
Syslog(LOG_ERR, "Cannot get kernel version information.");
return (0);
}
if ( uname(&utsname) < 0 ) if (debugging)
{
Syslog(LOG_ERR, "Cannot get kernel version information.");
return(0);
}
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)
fprintf(stderr, "Trying %s.\n", symfile); fprintf(stderr, "Trying %s.\n", symfile);
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { if ((sym_file = fopen(symfile, "r")) != (FILE *)0) {
if (CheckMapVersion(symfile) == 1) if (CheckMapVersion(symfile) == 1)
file = symfile; file = symfile;
fclose (sym_file); fclose(sym_file);
} }
if (sym_file == (FILE *) 0 || file == (char *) 0) { if (sym_file == (FILE *)0 || file == (char *)0) {
sprintf (symfile, "%s", *mf); sprintf(symfile, "%s", *mf);
if ( debugging ) if (debugging)
fprintf(stderr, "Trying %s.\n", symfile); fprintf(stderr, "Trying %s.\n", symfile);
if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { if ((sym_file = fopen(symfile, "r")) != (FILE *)0) {
if (CheckMapVersion(symfile) == 1) if (CheckMapVersion(symfile) == 1)
file = symfile; file = symfile;
fclose (sym_file); fclose(sym_file);
} }
} }
} }
/* /*
* At this stage of the game we are at the end of the symbol * At this stage of the game we are at the end of the symbol
* tables. * tables.
*/ */
if ( debugging ) if (debugging)
fprintf(stderr, "End of search list encountered.\n"); fprintf(stderr, "End of search list encountered.\n");
return(file); return (file);
} }
/************************************************************************** /**************************************************************************
* Function: CheckVersion * Function: CheckVersion
* *
@ -408,34 +376,25 @@ 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, static char *prefix = { "Version_" };
major, int vnum;
minor, int major;
patch; int minor;
int patch;
#ifndef TESTING #ifndef TESTING
struct utsname utsname;
int kvnum; int kvnum;
auto struct utsname utsname;
#endif #endif
static char *prefix = { "Version_" };
/* 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 */ ||
(*version == '_' && (*version == '_' &&
strncmp(++version, prefix, strlen(prefix)) == 0 ) /* a.out */ ) strncmp(++version, prefix, strlen(prefix)) == 0) /* a.out */)
; ;
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
@ -446,11 +405,13 @@ static int CheckVersion(version)
patch = vnum & 0x000000FF; patch = vnum & 0x000000FF;
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 +
patch); strlen(prefix),
major, minor,
patch);
sprintf(vstring, "%d.%d.%d", major, minor, patch); sprintf(vstring, "%d.%d.%d", major, minor, patch);
#ifndef TESTING #ifndef TESTING
@ -461,35 +422,32 @@ 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);
} }
/* Compute the version code from data sent by the kernel */ /* Compute the version code from data sent by the kernel */
kvnum = (major << 16) | (minor << 8) | patch; kvnum = (major << 16) | (minor << 8) | patch;
/* Failure. */ /* Failure. */
if ( vnum != kvnum ) if (vnum != kvnum)
return(-1); return (-1);
/* Success. */ /* Success. */
#endif #endif
return(1); return (1);
} }
/************************************************************************** /**************************************************************************
* Function: CheckMapVersion * Function: CheckMapVersion
* *
@ -514,20 +472,15 @@ 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) {
/* /*
* At this point a map file was successfully opened. We * At this point a map file was successfully opened. We
* now need to search this file and look for version * now need to search this file and look for version
@ -536,49 +489,46 @@ 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;
} }
return(version); return (version);
} }
return(0); return (0);
} }
/************************************************************************** /**************************************************************************
* Function: AddSymbol * Function: AddSymbol
* *
@ -592,33 +542,24 @@ 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;
strcpy(sym_array[num_syms].name, symbol); strcpy(sym_array[num_syms].name, symbol);
++num_syms; ++num_syms;
return(1); return (1);
} }
/************************************************************************** /**************************************************************************
* Function: LookupSymbol * Function: LookupSymbol
* *
@ -638,37 +579,27 @@ 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);
last = sym_array[0].name; last = sym_array[0].name;
ksym.offset = 0; ksym.offset = 0;
ksym.size = 0; ksym.size = 0;
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.size = sym_array[lp].value -
ksym.offset = value - sym_array[lp-1].value; sym_array[lp - 1].value;
ksym.size = sym_array[lp].value - \
sym_array[lp-1].value;
break; break;
} }
last = sym_array[lp].name; last = sym_array[lp].name;
@ -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,24 +638,20 @@ 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)
free(sym_array[lp].name); free(sym_array[lp].name);
/* Whack the entire array and initialize everything. */ /* Whack the entire array and initialize everything. */
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;
@ -787,52 +701,47 @@ extern char * ExpandKadds(line, el)
* kernel whenever a module is loaded or unloaded. I am * kernel whenever a module is loaded or unloaded. I am
* open for patches. * open for patches.
*/ */
if ( i_am_paranoid && if (i_am_paranoid &&
(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);
} }
dlm = *kp; dlm = *kp;
strncpy(num,sl+1,kp-sl-1); strncpy(num, sl + 1, kp - sl - 1);
num[kp-sl-1] = '\0'; num[kp - sl - 1] = '\0';
value = strtoul(num, (char **) 0, 16); value = strtoul(num, (char **)0, 16);
if ( (symbol = LookupSymbol(value, &sym)) == (char *) 0 ) if ((symbol = LookupSymbol(value, &sym)) == (char *)0)
symbol = sl; symbol = sl;
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);
@ -840,17 +749,15 @@ extern char * ExpandKadds(line, el)
strncat(elp, kp, value); strncat(elp, kp, value);
elp += value; elp += value;
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:
*/ */

View File

@ -103,34 +103,33 @@
* 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"
#define KSYMS "/proc/kallsyms" #define KSYMS "/proc/kallsyms"
static int num_modules = 0; static int num_modules = 0;
struct Module *sym_array_modules = (struct Module *) 0; struct Module *sym_array_modules = (struct Module *)0;
static int have_modules = 0; static int have_modules = 0;
@ -140,12 +139,11 @@ 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 *);
struct Module *AddModule(const char *); struct Module *AddModule(const char *);
static int symsort(const void *, const void *); static int symsort(const void *, const void *);
/* Imported from ksym.c */ /* Imported from ksym.c */
extern int num_syms; extern int num_syms;
@ -166,49 +164,46 @@ 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",
return(0); strerror(errno));
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;
p = index(buf, ' '); p = index(buf, ' ');
if ( p == NULL ) if (p == NULL)
continue; continue;
if ( buf[strlen(buf)-1] == '\n' ) if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf)-1] = '\0'; buf[strlen(buf) - 1] = '\0';
/* overlong lines will be ignored above */ /* overlong lines will be ignored above */
AddSymbol(buf); AddSymbol(buf);
@ -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 )
return(0); if (sym1->value == sym2->value)
return(1); return (0);
return (1);
} }
/************************************************************************** /**************************************************************************
* Function: FreeModules * Function: FreeModules
* *
@ -268,44 +257,38 @@ 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;
if ( num_modules == 0 ) if (num_modules == 0)
return; return;
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;
for (nsyms= 0; nsyms < mp->num_syms; ++nsyms) for (nsyms = 0; nsyms < mp->num_syms; ++nsyms)
free(mp->sym_array[nsyms].name); free(mp->sym_array[nsyms].name);
free(mp->sym_array); free(mp->sym_array);
if ( mp->name != NULL ) if (mp->name != NULL)
free(mp->name); free(mp->name);
} }
free(sym_array_modules); free(sym_array_modules);
sym_array_modules = (struct Module *) 0; sym_array_modules = (struct Module *)0;
num_modules = 0; num_modules = 0;
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;
} }
@ -358,7 +329,7 @@ struct Module *AddModule(module)
mp->sym_array = NULL; mp->sym_array = NULL;
mp->num_syms = 0; mp->num_syms = 0;
if ( module != NULL ) if (module != NULL)
mp->name = strdup(module); mp->name = strdup(module);
else else
mp->name = NULL; mp->name = NULL;
@ -366,7 +337,6 @@ struct Module *AddModule(module)
return mp; return mp;
} }
/************************************************************************** /**************************************************************************
* Function: AddSymbol * Function: AddSymbol
* *
@ -387,78 +357,68 @@ 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)
*p = '\0'; *p = '\0';
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);
p += 3; p += 3;
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)
return(0); return (0);
mp->sym_array[mp->num_syms].name = strdup(p); mp->sym_array[mp->num_syms].name = strdup(p);
if ( mp->sym_array[mp->num_syms].name == (char *) 0 ) if (mp->sym_array[mp->num_syms].name == (char *)0)
return(0); return (0);
/* Stuff interesting information into the module. */ /* Stuff interesting information into the module. */
mp->sym_array[mp->num_syms].value = address; mp->sym_array[mp->num_syms].value = address;
++mp->num_syms; ++mp->num_syms;
return(1); return (1);
} }
/************************************************************************** /**************************************************************************
* Function: LookupModuleSymbol * Function: LookupModuleSymbol
* *
@ -478,73 +438,58 @@ 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];
/* /*
* Run through the list of symbols in this module and * Run through the list of symbols in this module and
* see if the address can be resolved. * see if the address can be resolved.
*/ */
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 ||
{ (value - last->value) < sym->offset ||
if ( sym->size == 0 || ((sym->offset == (value - last->value)) &&
(value - last->value) < sym->offset || (mp->sym_array[nsym].value - last->value) < sym->size)) {
( (sym->offset == (value - last->value)) && sym->offset = value - last->value;
(mp->sym_array[nsym].value-last->value) < sym->size ) ) sym->size = mp->sym_array[nsym].value -
{ last->value;
sym->offset = value - last->value; ret[sizeof(ret) - 1] = '\0';
sym->size = mp->sym_array[nsym].value - \ if (mp->name == NULL)
last->value; snprintf(ret, sizeof(ret) - 1,
ret[sizeof(ret)-1] = '\0'; "%s", last->name);
if ( mp->name == NULL ) else
snprintf(ret, sizeof(ret)-1, snprintf(ret, sizeof(ret) - 1,
"%s", last->name); "%s:%s", mp->name, last->name);
else }
snprintf(ret, sizeof(ret)-1, break;
"%s:%s", mp->name, last->name);
}
break;
} }
last = &mp->sym_array[nsym]; last = &mp->sym_array[nsym];
} }
} }
if ( sym->size > 0 ) if (sym->size > 0)
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,52 +499,38 @@ 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);
} }
} }
FreeModules(); FreeModules();
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:
*/ */

View File

@ -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;
@ -31,5 +30,5 @@ struct symbol
/* Function prototypes. */ /* Function prototypes. */
extern char * LookupSymbol(unsigned long, struct symbol *); extern char *LookupSymbol(unsigned long, struct symbol *);
extern char * LookupModuleSymbol(unsigned long int, struct symbol *); extern char *LookupModuleSymbol(unsigned long int, struct symbol *);

View File

@ -1,24 +1,24 @@
/* /*
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,17 +35,15 @@
* 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;
char *name; char *name;
}; };

View File

@ -29,15 +29,15 @@
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"
#define PROCNAME "oops" #define PROCNAME "oops"
MODULE_AUTHOR("Martin Schulze <joey@infodrom.org>"); MODULE_AUTHOR("Martin Schulze <joey@infodrom.org>");
MODULE_DESCRIPTION("Oops module from klogd"); MODULE_DESCRIPTION("Oops module from klogd");
@ -46,48 +46,49 @@ MODULE_LICENSE("GPL");
static DEFINE_MUTEX(oops_lock); static DEFINE_MUTEX(oops_lock);
struct oops_t { struct oops_t {
unsigned long lastoops; unsigned long lastoops;
int loglevel; int loglevel;
}; };
static struct oops_t oops_data; static struct oops_t oops_data;
static int procflag = 0; static int procflag = 0;
struct code { struct code {
char *name; char *name;
int level; int level;
}; };
struct code priorities[] = { struct code priorities[] = {
{"emerg", 0}, { "emerg", 0 },
{"panic", 0}, /* DEPRECATED */ { "panic", 0 }, /* DEPRECATED */
{"alert", 1}, { "alert", 1 },
{"crit", 2}, { "crit", 2 },
{"err", 3}, { "err", 3 },
{"error", 3}, /* DEPRECATED */ { "error", 3 }, /* DEPRECATED */
{"warning", 4}, { "warning", 4 },
{"warn", 4}, /* DEPRECATED */ { "warn", 4 }, /* DEPRECATED */
{"notice", 5}, { "notice", 5 },
{"info", 6}, { "info", 6 },
{"debug", 7}, { "debug", 7 },
{NULL, -1} { NULL, -1 }
}; };
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)) {
oops_data.loglevel = prio->level; oops_data.loglevel = prio->level;
return; return;
} }
} }
/* /*
@ -95,156 +96,160 @@ 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)
{ {
#ifdef DEBUG #ifdef DEBUG
printk (KERN_DEBUG "oops_proc_open().\n"); printk(KERN_DEBUG "oops_proc_open().\n");
#endif #endif
return 0; return 0;
} }
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]; struct code *prio;
int size; char *level = NULL;
char s[70];
struct code *prio; int size;
char *level = NULL;
#ifdef DEBUG #ifdef DEBUG
printk (KERN_DEBUG "oops_proc_read(%d).\n",nbytes); printk(KERN_DEBUG "oops_proc_read(%d).\n", nbytes);
#endif #endif
if (procflag) { if (procflag) {
procflag = 0; procflag = 0;
return 0; return 0;
} }
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)
size = sprintf (s, "Log level: %s\nLast oops: none\n", level); size = sprintf(s, "Log level: %s\nLast oops: none\n", level);
else { else {
unsigned long now = get_seconds(); unsigned long now = get_seconds();
unsigned long delta = now - oops_data.lastoops; unsigned long delta = now - oops_data.lastoops;
size = sprintf (s, "Log level: %s\nLast oops: %lu (%lu second%s ago)\n", size = sprintf(s, "Log level: %s\nLast oops: %lu (%lu second%s ago)\n",
level, oops_data.lastoops, level, oops_data.lastoops,
delta, delta == 1 ? "" : "s"); delta, delta == 1 ? "" : "s");
} }
if (size < nbytes) if (size < nbytes)
nbytes = size; nbytes = size;
if (copy_to_user(buf, s, nbytes)) if (copy_to_user(buf, s, nbytes))
return -EFAULT; return -EFAULT;
*ppos += nbytes; *ppos += nbytes;
procflag++; procflag++;
return nbytes; return nbytes;
} }
static int static int
oops_proc_release(struct inode *inode, struct file *filp) oops_proc_release(struct inode *inode, struct file *filp)
{ {
#ifdef DEBUG #ifdef DEBUG
printk (KERN_DEBUG "oops_proc_release().\n"); printk(KERN_DEBUG "oops_proc_release().\n");
#endif #endif
return 0; return 0;
} }
static ssize_t static ssize_t
oops_proc_write(struct file *file, const char __user *buf, oops_proc_write(struct file *file, const char __user *buf,
size_t nbytes, loff_t *ppos) size_t nbytes, loff_t *ppos)
{ {
char input[100]; char input[100];
int len; int len;
#ifdef DEBUG #ifdef DEBUG
printk (KERN_DEBUG "oops_proc_write(%d).\n", nbytes); printk(KERN_DEBUG "oops_proc_write(%d).\n", nbytes);
#endif #endif
len = nbytes >= sizeof(input) ? sizeof(input)-1 : nbytes; len = nbytes >= sizeof(input) ? sizeof(input) - 1 : nbytes;
if (copy_from_user(input, buf, len)) if (copy_from_user(input, buf, len))
return -EFAULT; return -EFAULT;
input[len] = '\0'; input[len] = '\0';
if (input[len-1] == '\n') if (input[len - 1] == '\n')
input[len-1] = '\0'; input[len - 1] = '\0';
if (!strncmp(input, "level:", 6)) if (!strncmp(input, "level:", 6))
oops_decode_level(input); oops_decode_level(input);
else if (!strcmp(input, "oops")) { else if (!strcmp(input, "oops")) {
oops_data.lastoops = get_seconds(); oops_data.lastoops = get_seconds();
oops(); oops();
} else } else
printk ("<%d>%s\n", oops_data.loglevel, input); printk("<%d>%s\n", oops_data.loglevel, input);
return nbytes; return nbytes;
} }
static const struct file_operations oops_proc_operations = { static const struct file_operations oops_proc_operations = {
.read = oops_proc_read, .read = oops_proc_read,
.release = oops_proc_release, .release = oops_proc_release,
.write = oops_proc_write, .write = oops_proc_write,
.open = oops_proc_open, .open = oops_proc_open,
}; };
void oops_proc_add (void) void oops_proc_add(void)
{ {
struct proc_dir_entry *entry; struct proc_dir_entry *entry;
mutex_lock (&oops_lock); mutex_lock(&oops_lock);
entry = create_proc_entry (PROCNAME, 0, NULL); entry = create_proc_entry(PROCNAME, 0, NULL);
if (entry) { if (entry) {
entry->proc_fops = &oops_proc_operations; entry->proc_fops = &oops_proc_operations;
} }
mutex_unlock (&oops_lock); mutex_unlock(&oops_lock);
} }
void oops_proc_remove (void) void oops_proc_remove(void)
{ {
mutex_lock (&oops_lock); mutex_lock(&oops_lock);
remove_proc_entry(PROCNAME, NULL); remove_proc_entry(PROCNAME, NULL);
mutex_unlock(&oops_lock); mutex_unlock(&oops_lock);
} }
int oops_init (void) int oops_init(void)
{ {
printk (KERN_INFO "Loading module " MODNAME ".\n"); printk(KERN_INFO "Loading module " MODNAME ".\n");
oops_data.lastoops = 0; oops_data.lastoops = 0;
oops_data.loglevel = 5; oops_data.loglevel = 5;
oops_proc_add(); oops_proc_add();
return 0; return 0;
} }
void oops_cleanup (void) void oops_cleanup(void)
{ {
oops_proc_remove(); oops_proc_remove();
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:
*/

View File

@ -1,37 +1,37 @@
/* /*
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
*/ */
/* /*
* Sat Aug 19 13:24:33 MET DST 1995: Martin Schulze * Sat Aug 19 13:24:33 MET DST 1995: Martin Schulze
* 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
* *
@ -39,16 +39,19 @@
* 0 is returned if either there's no pidfile, it's empty * 0 is returned if either there's no pidfile, it's empty
* or no pid can be read. * or no pid can be read.
*/ */
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");
return 0; if (!fp)
fscanf(f,"%d", &pid); return 0;
fclose(f);
return pid; fscanf(fp, "%d", &pid);
fclose(fp);
return pid;
} }
/* check_pid /* check_pid
@ -57,24 +60,24 @@ int read_pid (char *pidfile)
* table (using /proc) to determine if the process already exists. If * table (using /proc) to determine if the process already exists. If
* so 1 is returned, otherwise 0. * so 1 is returned, otherwise 0.
*/ */
int check_pid (char *pidfile) int check_pid(char *pidfile)
{ {
int pid = read_pid(pidfile); int pid = read_pid(pidfile);
/* Amazing ! _I_ am already holding the pid file... */ /* Amazing ! _I_ am already holding the pid file... */
if ((!pid) || (pid == getpid ())) if ((!pid) || (pid == getpid()))
return 0; return 0;
/* /*
* The 'standard' method of doing this is to try and do a 'fake' kill * The 'standard' method of doing this is to try and do a 'fake' kill
* of the process. If an ESRCH error is returned the process cannot * of the process. If an ESRCH error is returned the process cannot
* be found -- GW * be found -- GW
*/ */
/* But... errno is usually changed only on error.. */ /* But... errno is usually changed only on error.. */
if (kill(pid, 0) && errno == ESRCH) if (kill(pid, 0) && errno == ESRCH)
return(0); return (0);
return pid; return pid;
} }
/* write_pid /* write_pid
@ -82,41 +85,40 @@ int check_pid (char *pidfile)
* Writes the pid to the specified file. If that fails 0 is * Writes the pid to the specified file. If that fails 0 is
* returned, otherwise the pid. * returned, otherwise the pid.
*/ */
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));
close(fd); close(fd);
return 0; return 0;
} }
close(fd); close(fd);
return pid; return pid;
} }
/* touch_pid /* touch_pid
@ -124,9 +126,9 @@ int write_pid (char *pidfile)
* Touches the specified pidfile f.ex. when receiving a SIGHUP * Touches the specified pidfile f.ex. when receiving a SIGHUP
* The result from utimensat() is returned * The result from utimensat() is returned
*/ */
int touch_pid (char *pidfile) int touch_pid(char *pidfile)
{ {
return utimensat(0, pidfile, NULL, 0); return utimensat(0, pidfile, NULL, 0);
} }
/* remove_pid /* remove_pid
@ -134,8 +136,14 @@ int touch_pid (char *pidfile)
* Remove the the specified file. The result from unlink(2) * Remove the the specified file. The result from unlink(2)
* is returned * is returned
*/ */
int remove_pid (char *pidfile) int remove_pid(char *pidfile)
{ {
return unlink (pidfile); return unlink(pidfile);
} }
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

View File

@ -1,23 +1,23 @@
/* /*
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
* *

View File

@ -52,32 +52,31 @@ 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"
static int LogFile = -1; /* fd for log */ static int LogFile = -1; /* fd for log */
static int connected; /* have done connect */ static int connected; /* have done connect */
static int LogStat = 0; /* status bits, set by openlog() */ 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,23 +85,19 @@ 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;
/* see if we should just throw out this message */ /* see if we should just throw out this message */
if (!LOG_MASK(LOG_PRI(pri)) || (pri &~ (LOG_PRIMASK|LOG_FACMASK))) if (!LOG_MASK(LOG_PRI(pri)) || (pri & ~(LOG_PRIMASK | LOG_FACMASK)))
return; return;
if (LogFile < 0 || !connected) if (LogFile < 0 || !connected)
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility); openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
@ -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,18 +130,18 @@ 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;
(ch = *fmt) != '\0' && t1<fmt_cpy+sizeof(fmt_cpy); (ch = *fmt) != '\0' && t1 < fmt_cpy + sizeof(fmt_cpy);
++fmt) ++fmt)
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,21 +166,20 @@ 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);
} }
if (result >= 0 || !(LogStat&LOG_CONS)) if (result >= 0 || !(LogStat & LOG_CONS))
return; return;
/* /*
* output the message to the console; don't worry about * output the message to the console; don't worry about
* blocking, if console blocks everything will. * blocking, if console blocks everything will.
*/ */
if ((fd = open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY, 0)) < 0) if ((fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY, 0)) < 0)
return; return;
(void)strcat(tbuf, "\r\n"); (void)strcat(tbuf, "\r\n");
cnt += 2; cnt += 2;
@ -192,24 +189,21 @@ vsyslog(pri, fmt, ap)
} }
#ifndef TESTING #ifndef TESTING
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
#endif #endif
/* /*
* 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;
LogStat = logstat; LogStat = logstat;
#ifdef ALLOW_KERNEL_LOGGING #ifdef ALLOW_KERNEL_LOGGING
if ((logfac &~ LOG_FACMASK) == 0) if ((logfac & ~LOG_FACMASK) == 0)
#else #else
if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0)
#endif #endif
LogFacility = logfac; LogFacility = logfac;
@ -217,17 +211,16 @@ openlog(ident, logstat, logfac)
if (LogFile == -1) { if (LogFile == -1) {
SyslogAddr.sa_family = AF_UNIX; SyslogAddr.sa_family = AF_UNIX;
strncpy(SyslogAddr.sa_data, _PATH_LOGNAME, strncpy(SyslogAddr.sa_data, _PATH_LOGNAME,
sizeof(SyslogAddr.sa_data)); sizeof(SyslogAddr.sa_data));
if (LogStat & LOG_NDELAY) { if (LogStat & LOG_NDELAY) {
LogFile = socket(AF_UNIX, SOCK_DGRAM, 0); LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
/* fcntl(LogFile, F_SETFD, 1); */ /* fcntl(LogFile, F_SETFD, 1); */
} }
} }
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
connected = 1; connected = 1;
} }
@ -235,23 +228,20 @@ 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);
#endif #endif
LogFile = -1; LogFile = -1;
connected = 0; connected = 0;
} }
static int LogMask = 0xff; /* mask of priorities to be logged */ 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:
*/

View File

@ -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.");
@ -67,8 +58,15 @@ int main(int argc, char *argv[])
syslog(LOG_INFO, "Info log."); syslog(LOG_INFO, "Info log.");
syslog(LOG_DEBUG, "Debug log."); syslog(LOG_DEBUG, "Debug log.");
closelog(); closelog();
return(0); return (0);
} }
return(0); return (0);
} }
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/

File diff suppressed because it is too large Load Diff