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:
Joachim Nilsson 2019-10-24 08:39:37 +02:00
parent 1ba3dc5b87
commit 6fa899db38
3 changed files with 11 additions and 11 deletions

View File

@ -34,7 +34,8 @@ klogd_CPPFLAGS = -DALLOW_KERNEL_LOGGING -D_BSD_SOURCE -D_DEFAULT_SOURCE
logger_SOURCES = logger.c syslog.c
logger_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
tsyslogd_SOURCES = syslogd.c pidfile.c pidfile.h
tsyslogd_CPPFLAGS = -D_BSD_SOURCE -D_DEFAULT_SOURCE -DTESTING
tsyslogd_SOURCES = $(syslogd_SOURCES)
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

View File

@ -82,6 +82,9 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90";
#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 connected; /* have done connect */
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);
}
#ifndef TESTING
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
#endif
/*
* OPENLOG -- open system log
*/
@ -222,19 +222,19 @@ void openlog(const char *ident, int logstat, int logfac)
#ifndef TESTING
if (LogFile == -1) {
SyslogAddr.sa_family = AF_UNIX;
strncpy(SyslogAddr.sa_data, _PATH_LOGNAME,
sizeof(SyslogAddr.sa_data));
strncpy(SyslogAddr.sa_data, _PATH_LOGNAME, 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); /* FD_CLOEXEC */
}
}
if (LogFile != -1 && !connected &&
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family) + strlen(SyslogAddr.sa_data)) != -1)
connected = 1;
#else
LogFile = fileno(stdout);
connected = 1;
#endif
connected = 1;
}
/*

View File

@ -54,7 +54,6 @@ int main(int argc, char *argv[])
syslog(LOG_INFO, "Info log.");
syslog(LOG_DEBUG, "Debug log.");
closelog();
return 0;
}
return 0;