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:
117
src/syslog.c
117
src/syslog.c
@ -52,32 +52,31 @@ 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"
|
||||
#define _PATH_LOGNAME "/dev/log"
|
||||
|
||||
static int LogFile = -1; /* fd for log */
|
||||
static int connected; /* have done connect */
|
||||
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 */
|
||||
static int LogFile = -1; /* fd for log */
|
||||
static int connected; /* have done connect */
|
||||
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,23 +85,19 @@ 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;
|
||||
int fd, saved_errno;
|
||||
int result;
|
||||
char tbuf[2048], fmt_cpy[1024], *stdp = NULL;
|
||||
|
||||
saved_errno = errno;
|
||||
|
||||
/* 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;
|
||||
if (LogFile < 0 || !connected)
|
||||
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
|
||||
@ -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,18 +130,18 @@ vsyslog(pri, fmt, ap)
|
||||
|
||||
/* substitute error message for %m */
|
||||
{
|
||||
register char ch, *t1, *t2;
|
||||
char ch, *t1, *t2;
|
||||
char *strerror();
|
||||
|
||||
for (t1 = fmt_cpy;
|
||||
(ch = *fmt) != '\0' && t1<fmt_cpy+sizeof(fmt_cpy);
|
||||
(ch = *fmt) != '\0' && t1 < fmt_cpy + sizeof(fmt_cpy);
|
||||
++fmt)
|
||||
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,21 +166,20 @@ 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);
|
||||
}
|
||||
|
||||
if (result >= 0 || !(LogStat&LOG_CONS))
|
||||
if (result >= 0 || !(LogStat & LOG_CONS))
|
||||
return;
|
||||
|
||||
/*
|
||||
* output the message to the console; don't worry about
|
||||
* 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;
|
||||
(void)strcat(tbuf, "\r\n");
|
||||
cnt += 2;
|
||||
@ -192,24 +189,21 @@ vsyslog(pri, fmt, ap)
|
||||
}
|
||||
|
||||
#ifndef TESTING
|
||||
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
||||
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
||||
#endif
|
||||
/*
|
||||
* 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;
|
||||
LogStat = logstat;
|
||||
|
||||
#ifdef ALLOW_KERNEL_LOGGING
|
||||
if ((logfac &~ LOG_FACMASK) == 0)
|
||||
if ((logfac & ~LOG_FACMASK) == 0)
|
||||
#else
|
||||
if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
|
||||
if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0)
|
||||
#endif
|
||||
LogFacility = logfac;
|
||||
|
||||
@ -217,17 +211,16 @@ openlog(ident, logstat, logfac)
|
||||
if (LogFile == -1) {
|
||||
SyslogAddr.sa_family = AF_UNIX;
|
||||
strncpy(SyslogAddr.sa_data, _PATH_LOGNAME,
|
||||
sizeof(SyslogAddr.sa_data));
|
||||
sizeof(SyslogAddr.sa_data));
|
||||
if (LogStat & LOG_NDELAY) {
|
||||
LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
/* fcntl(LogFile, F_SETFD, 1); */
|
||||
/* fcntl(LogFile, F_SETFD, 1); */
|
||||
}
|
||||
}
|
||||
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);
|
||||
LogFile = fileno(stdout);
|
||||
#endif
|
||||
connected = 1;
|
||||
}
|
||||
@ -235,23 +228,20 @@ openlog(ident, logstat, logfac)
|
||||
/*
|
||||
* CLOSELOG -- close the system log
|
||||
*/
|
||||
void
|
||||
closelog()
|
||||
void closelog()
|
||||
{
|
||||
#ifndef TESTING
|
||||
(void) close(LogFile);
|
||||
(void)close(LogFile);
|
||||
#endif
|
||||
LogFile = -1;
|
||||
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
|
||||
*/
|
||||
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:
|
||||
*/
|
||||
|
Reference in New Issue
Block a user