Misc, initial cleanup of syslog testing framework
- Let syslog_tst.c use local syslog.c API, for wrapping - Add -DTESTING to build of syslog_tst & C:o - Enable CLOEXEC on each opened log file in syslog.c - Simplify code for readability Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
1ba3dc5b87
commit
6fa899db38
@ -34,7 +34,8 @@ klogd_CPPFLAGS = -DALLOW_KERNEL_LOGGING -D_BSD_SOURCE -D_DEFAULT_SOURCE
|
|||||||
logger_SOURCES = logger.c syslog.c
|
logger_SOURCES = logger.c syslog.c
|
||||||
logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
||||||
|
|
||||||
tsyslogd_SOURCES = syslogd.c pidfile.c pidfile.h
|
tsyslogd_SOURCES = $(syslogd_SOURCES)
|
||||||
tsyslogd_CPPFLAGS = -D_BSD_SOURCE -D_DEFAULT_SOURCE -DTESTING
|
tsyslogd_CPPFLAGS = $(syslogd_CPPFLAGS) -DTESTING
|
||||||
|
|
||||||
syslog_tst_SOURCES = syslog_tst.c
|
syslog_tst_SOURCES = syslog_tst.c syslog.c
|
||||||
|
syslog_tst_CPPFLAGS = -D_BSD_SOURCE -D_DEFAULT_SOURCE -DTESTING
|
||||||
|
14
src/syslog.c
14
src/syslog.c
@ -82,6 +82,9 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90";
|
|||||||
|
|
||||||
#define _PATH_LOGNAME "/dev/log"
|
#define _PATH_LOGNAME "/dev/log"
|
||||||
|
|
||||||
|
#ifndef TESTING
|
||||||
|
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
||||||
|
#endif
|
||||||
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() */
|
||||||
@ -200,9 +203,6 @@ void vsyslog(int pri, const char *fmt, va_list ap)
|
|||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TESTING
|
|
||||||
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
|
||||||
#endif
|
|
||||||
/*
|
/*
|
||||||
* OPENLOG -- open system log
|
* OPENLOG -- open system log
|
||||||
*/
|
*/
|
||||||
@ -222,19 +222,19 @@ void openlog(const char *ident, int logstat, int logfac)
|
|||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
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); /* FD_CLOEXEC */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (LogFile != -1 && !connected &&
|
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)
|
||||||
|
connected = 1;
|
||||||
#else
|
#else
|
||||||
LogFile = fileno(stdout);
|
LogFile = fileno(stdout);
|
||||||
|
connected = 1;
|
||||||
#endif
|
#endif
|
||||||
connected = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -54,7 +54,6 @@ 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user