Refactor, use NULL and not (char *)0 and similar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
2e84a34758
commit
aef7e07704
16
src/klogd.c
16
src/klogd.c
@ -348,7 +348,7 @@ static void CloseLogSrc(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_file != (FILE *)0)
|
if (output_file != NULL)
|
||||||
fflush(output_file);
|
fflush(output_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ static void Terminate(void)
|
|||||||
CloseLogSrc();
|
CloseLogSrc();
|
||||||
Syslog(LOG_INFO, "Kernel log daemon terminating.");
|
Syslog(LOG_INFO, "Kernel log daemon terminating.");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
if (output_file != (FILE *)0)
|
if (output_file != NULL)
|
||||||
fclose(output_file);
|
fclose(output_file);
|
||||||
closelog();
|
closelog();
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
@ -534,7 +534,7 @@ extern void Syslog(int priority, char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handle output to a file. */
|
/* Handle output to a file. */
|
||||||
if (output_file != (FILE *)0) {
|
if (output_file != NULL) {
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(output_file, fmt, ap);
|
vfprintf(output_file, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -790,11 +790,11 @@ static void LogLine(char *ptr, int len)
|
|||||||
int sym_space;
|
int sym_space;
|
||||||
|
|
||||||
*(line - 1) = 0; /* null terminate the address string */
|
*(line - 1) = 0; /* null terminate the address string */
|
||||||
value = strtoul(sym_start + 1, (char **)0, 16);
|
value = strtoul(sym_start + 1, NULL, 16);
|
||||||
*(line - 1) = '>'; /* put back delim */
|
*(line - 1) = '>'; /* put back delim */
|
||||||
|
|
||||||
symbol = LookupSymbol(value, &sym);
|
symbol = LookupSymbol(value, &sym);
|
||||||
if (!symbol_lookup || symbol == (char *)0) {
|
if (!symbol_lookup || symbol == NULL) {
|
||||||
parse_state = PARSING_TEXT;
|
parse_state = PARSING_TEXT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -978,9 +978,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set console logging level. */
|
/* Set console logging level. */
|
||||||
if (log_level != (char *)0) {
|
if (log_level != NULL) {
|
||||||
if ((strlen(log_level) > 1) ||
|
if ((strlen(log_level) > 1) ||
|
||||||
(strchr("12345678", *log_level) == (char *)0)) {
|
(strchr("12345678", *log_level) == NULL)) {
|
||||||
fprintf(stderr, "klogd: Invalid console logging "
|
fprintf(stderr, "klogd: Invalid console logging "
|
||||||
"level <%s> specified.\n",
|
"level <%s> specified.\n",
|
||||||
log_level);
|
log_level);
|
||||||
@ -1061,7 +1061,7 @@ int main(int argc, char *argv[])
|
|||||||
if (use_output) {
|
if (use_output) {
|
||||||
if (strcmp(output, "-") == 0)
|
if (strcmp(output, "-") == 0)
|
||||||
output_file = stdout;
|
output_file = stdout;
|
||||||
else if ((output_file = fopen(output, "w")) == (FILE *)0) {
|
else if ((output_file = fopen(output, "w")) == NULL) {
|
||||||
fprintf(stderr, "klogd: Cannot open output file "
|
fprintf(stderr, "klogd: Cannot open output file "
|
||||||
"%s - %s\n",
|
"%s - %s\n",
|
||||||
output, strerror(errno));
|
output, strerror(errno));
|
||||||
|
32
src/ksym.c
32
src/ksym.c
@ -138,7 +138,7 @@
|
|||||||
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 = NULL;
|
||||||
|
|
||||||
static char *system_maps[] =
|
static char *system_maps[] =
|
||||||
{
|
{
|
||||||
@ -148,7 +148,7 @@ static char *system_maps[] =
|
|||||||
#if defined(TEST)
|
#if defined(TEST)
|
||||||
"./System.map",
|
"./System.map",
|
||||||
#endif
|
#endif
|
||||||
(char *)0
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(TEST)
|
#if defined(TEST)
|
||||||
@ -309,21 +309,21 @@ static char *FindSymbolFile(void)
|
|||||||
if (debugging)
|
if (debugging)
|
||||||
fputs("Searching for symbol map.\n", stderr);
|
fputs("Searching for symbol map.\n", stderr);
|
||||||
|
|
||||||
for (mf = system_maps; *mf != (char *)0 && file == (char *)0; ++mf) {
|
for (mf = system_maps; *mf != NULL && file == NULL; ++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")) != NULL) {
|
||||||
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 == NULL || file == NULL) {
|
||||||
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")) != NULL) {
|
||||||
if (CheckMapVersion(symfile) == 1)
|
if (CheckMapVersion(symfile) == 1)
|
||||||
file = symfile;
|
file = symfile;
|
||||||
fclose(sym_file);
|
fclose(sym_file);
|
||||||
@ -480,7 +480,7 @@ static int CheckMapVersion(char *fname)
|
|||||||
char type;
|
char type;
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
if ((sym_file = fopen(fname, "r")) != (FILE *)0) {
|
if ((sym_file = fopen(fname, "r")) != NULL) {
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
@ -648,7 +648,7 @@ static void FreeSymbols(void)
|
|||||||
|
|
||||||
/* 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 = NULL;
|
||||||
num_syms = 0;
|
num_syms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ char *ExpandKadds(char *line, char *el)
|
|||||||
* open for patches.
|
* open for patches.
|
||||||
*/
|
*/
|
||||||
if (i_am_paranoid &&
|
if (i_am_paranoid &&
|
||||||
(strstr(line, "Oops:") != (char *)0) && !InitMsyms())
|
(strstr(line, "Oops:") != NULL) && !InitMsyms())
|
||||||
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
|
Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -710,7 +710,7 @@ char *ExpandKadds(char *line, char *el)
|
|||||||
* messages in this line.
|
* messages in this line.
|
||||||
*/
|
*/
|
||||||
if ((num_syms == 0) ||
|
if ((num_syms == 0) ||
|
||||||
(kp = strstr(line, "[<")) == (char *)0) {
|
(kp = strstr(line, "[<")) == NULL) {
|
||||||
strcpy(el, line);
|
strcpy(el, line);
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
@ -721,15 +721,15 @@ char *ExpandKadds(char *line, char *el)
|
|||||||
*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, ">]")) == NULL) {
|
||||||
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, NULL, 16);
|
||||||
if ((symbol = LookupSymbol(value, &sym)) == (char *)0)
|
if ((symbol = LookupSymbol(value, &sym)) == NULL)
|
||||||
symbol = sl;
|
symbol = sl;
|
||||||
|
|
||||||
strcat(elp, symbol);
|
strcat(elp, symbol);
|
||||||
@ -749,9 +749,9 @@ char *ExpandKadds(char *line, char *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, "[<")) == NULL)
|
||||||
strcat(elp, sl);
|
strcat(elp, sl);
|
||||||
} while (kp != (char *)0);
|
} while (kp != NULL);
|
||||||
|
|
||||||
if (debugging)
|
if (debugging)
|
||||||
fprintf(stderr, "Expanded line: %s\n", el);
|
fprintf(stderr, "Expanded line: %s\n", el);
|
||||||
@ -793,7 +793,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
debugging = 1;
|
debugging = 1;
|
||||||
|
|
||||||
if (!InitKsyms((char *)0)) {
|
if (!InitKsyms(NULL)) {
|
||||||
fputs("ksym: Error loading system map.\n", stderr);
|
fputs("ksym: Error loading system map.\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@
|
|||||||
#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 = NULL;
|
||||||
|
|
||||||
static int have_modules = 0;
|
static int have_modules = 0;
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ static void FreeModules(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(sym_array_modules);
|
free(sym_array_modules);
|
||||||
sym_array_modules = (struct Module *)0;
|
sym_array_modules = NULL;
|
||||||
num_modules = 0;
|
num_modules = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ static int AddSymbol(const char *line)
|
|||||||
return 0;
|
return 0;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
address = strtoul(line, (char **)0, 16);
|
address = strtoul(line, NULL, 16);
|
||||||
|
|
||||||
p += 3;
|
p += 3;
|
||||||
|
|
||||||
@ -405,11 +405,11 @@ static int AddSymbol(const char *line)
|
|||||||
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 == NULL)
|
||||||
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 == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Stuff interesting information into the module. */
|
/* Stuff interesting information into the module. */
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern int main(int, char **);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *nl,
|
char *nl,
|
||||||
@ -33,10 +31,8 @@ int main(int argc, char *argv[])
|
|||||||
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) {
|
if ((nl = strrchr(bufr, '\n')))
|
||||||
if ((nl = strrchr(bufr, '\n')) !=
|
|
||||||
(char *)0)
|
|
||||||
*nl = '\0';
|
*nl = '\0';
|
||||||
syslog(LOG_INFO, "%s", bufr);
|
syslog(LOG_INFO, "%s", bufr);
|
||||||
logged += strlen(bufr);
|
logged += strlen(bufr);
|
||||||
|
@ -1076,7 +1076,7 @@ int main(int argc, char *argv[])
|
|||||||
num_fds = getdtablesize();
|
num_fds = getdtablesize();
|
||||||
logit("Allocated parts table for %d file descriptors.\n", num_fds);
|
logit("Allocated parts table for %d file descriptors.\n", num_fds);
|
||||||
if ((parts = (char **)malloc(num_fds * sizeof(char *))) ==
|
if ((parts = (char **)malloc(num_fds * sizeof(char *))) ==
|
||||||
(char **)0) {
|
NULL) {
|
||||||
logerror("Cannot allocate memory for message parts table.");
|
logerror("Cannot allocate memory for message parts table.");
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
if (getpid() != ppid)
|
if (getpid() != ppid)
|
||||||
@ -1085,7 +1085,7 @@ int main(int argc, char *argv[])
|
|||||||
die(0);
|
die(0);
|
||||||
}
|
}
|
||||||
for (i = 0; i < num_fds; ++i)
|
for (i = 0; i < num_fds; ++i)
|
||||||
parts[i] = (char *)0;
|
parts[i] = NULL;
|
||||||
|
|
||||||
logit("Starting.\n");
|
logit("Starting.\n");
|
||||||
init();
|
init();
|
||||||
@ -1246,7 +1246,7 @@ int main(int argc, char *argv[])
|
|||||||
logit("Message from stdin.\n");
|
logit("Message from stdin.\n");
|
||||||
memset(line, '\0', sizeof(line));
|
memset(line, '\0', sizeof(line));
|
||||||
line[0] = '.';
|
line[0] = '.';
|
||||||
parts[fileno(stdin)] = (char *)0;
|
parts[fileno(stdin)] = NULL;
|
||||||
i = read(fileno(stdin), line, MAXLINE);
|
i = read(fileno(stdin), line, MAXLINE);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
printchopped(LocalHostName, line, i + 1, fileno(stdin));
|
printchopped(LocalHostName, line, i + 1, fileno(stdin));
|
||||||
@ -1507,7 +1507,7 @@ void untty(void)
|
|||||||
if (!Debug) {
|
if (!Debug) {
|
||||||
i = open(_PATH_TTY, O_RDWR);
|
i = open(_PATH_TTY, O_RDWR);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
(void)ioctl(i, (int)TIOCNOTTY, (char *)0);
|
(void)ioctl(i, (int)TIOCNOTTY, NULL);
|
||||||
(void)close(i);
|
(void)close(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1527,11 +1527,11 @@ void printchopped(const char *hname, char *msg, size_t len, int fd)
|
|||||||
|
|
||||||
logit("Message length: %d, File descriptor: %d.\n", len, fd);
|
logit("Message length: %d, File descriptor: %d.\n", len, fd);
|
||||||
tmpline[0] = '\0';
|
tmpline[0] = '\0';
|
||||||
if (parts[fd] != (char *)0) {
|
if (parts[fd] != NULL) {
|
||||||
logit("Including part from messages.\n");
|
logit("Including part from messages.\n");
|
||||||
strcpy(tmpline, parts[fd]);
|
strcpy(tmpline, parts[fd]);
|
||||||
free(parts[fd]);
|
free(parts[fd]);
|
||||||
parts[fd] = (char *)0;
|
parts[fd] = NULL;
|
||||||
if ((strlen(msg) + strlen(tmpline)) > MAXLINE) {
|
if ((strlen(msg) + strlen(tmpline)) > MAXLINE) {
|
||||||
logerror("Cannot glue message parts together");
|
logerror("Cannot glue message parts together");
|
||||||
printline(hname, tmpline);
|
printline(hname, tmpline);
|
||||||
@ -1555,7 +1555,7 @@ void printchopped(const char *hname, char *msg, size_t len, int fd)
|
|||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
p++;
|
p++;
|
||||||
ptlngth = strlen(p);
|
ptlngth = strlen(p);
|
||||||
if ((parts[fd] = malloc(ptlngth + 1)) == (char *)0)
|
if ((parts[fd] = malloc(ptlngth + 1)) == NULL)
|
||||||
logerror("Cannot allocate memory for message part.");
|
logerror("Cannot allocate memory for message part.");
|
||||||
else {
|
else {
|
||||||
strcpy(parts[fd], p);
|
strcpy(parts[fd], p);
|
||||||
@ -1937,7 +1937,7 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
|
|||||||
|
|
||||||
#ifdef SYSLOG_INET
|
#ifdef SYSLOG_INET
|
||||||
case F_FORW_SUSP:
|
case F_FORW_SUSP:
|
||||||
fwd_suspend = time((time_t *)0) - f->f_time;
|
fwd_suspend = time(NULL) - f->f_time;
|
||||||
if (fwd_suspend >= INET_SUSPEND_TIME) {
|
if (fwd_suspend >= INET_SUSPEND_TIME) {
|
||||||
logit("\nForwarding suspension over, "
|
logit("\nForwarding suspension over, "
|
||||||
"retrying FORW ");
|
"retrying FORW ");
|
||||||
@ -1962,7 +1962,7 @@ void fprintlog(struct filed *f, char *from, int flags, char *msg)
|
|||||||
*/
|
*/
|
||||||
case F_FORW_UNKN:
|
case F_FORW_UNKN:
|
||||||
logit(" %s\n", f->f_un.f_forw.f_hname);
|
logit(" %s\n", f->f_un.f_forw.f_hname);
|
||||||
fwd_suspend = time((time_t *)0) - f->f_time;
|
fwd_suspend = time(NULL) - f->f_time;
|
||||||
if (fwd_suspend >= INET_SUSPEND_TIME) {
|
if (fwd_suspend >= INET_SUSPEND_TIME) {
|
||||||
logit("Forwarding suspension to unknown over, retrying\n");
|
logit("Forwarding suspension to unknown over, retrying\n");
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
@ -2242,7 +2242,7 @@ void reapchild(int signo)
|
|||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
#if defined(SYSV) && !defined(linux)
|
#if defined(SYSV) && !defined(linux)
|
||||||
(void)signal(SIGCHLD, reapchild); /* reset signal handler -ASP */
|
(void)signal(SIGCHLD, reapchild); /* reset signal handler -ASP */
|
||||||
wait((int *)0);
|
wait(NULL);
|
||||||
#else
|
#else
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -2462,7 +2462,7 @@ void init(void)
|
|||||||
{
|
{
|
||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
#ifndef SYSV
|
#ifndef SYSV
|
||||||
struct filed **nextp = (struct filed **)0;
|
struct filed **nextp = NULL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
struct hostent *hent;
|
struct hostent *hent;
|
||||||
@ -2513,7 +2513,7 @@ void init(void)
|
|||||||
*/
|
*/
|
||||||
nlogs = -1;
|
nlogs = -1;
|
||||||
free((void *)Files);
|
free((void *)Files);
|
||||||
Files = (struct filed *)0;
|
Files = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYSV
|
#ifdef SYSV
|
||||||
@ -2897,7 +2897,7 @@ void cfline(char *line, struct filed *f)
|
|||||||
*/
|
*/
|
||||||
f->f_type = F_FORW_UNKN;
|
f->f_type = F_FORW_UNKN;
|
||||||
f->f_prevcount = INET_RETRY_MAX;
|
f->f_prevcount = INET_RETRY_MAX;
|
||||||
f->f_time = time((time_t *)0);
|
f->f_time = time(NULL);
|
||||||
f->f_un.f_forw.f_addr = NULL;
|
f->f_un.f_forw.f_addr = NULL;
|
||||||
} else {
|
} else {
|
||||||
f->f_type = F_FORW;
|
f->f_type = F_FORW;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user