diff --git a/TODO.org b/TODO.org index 039fd65..85b0071 100644 --- a/TODO.org +++ b/TODO.org @@ -7,14 +7,13 @@ ** DONE Add syslogp() and vsyslogp() to libsyslog ** DONE Add support for =/etc/syslog.d/*.conf= to syslogd ** DONE Test support of =/etc/syslog.d/*.conf= to syslogd -** Test SIGHUP of syslogd +** DONE Test SIGHUP of syslogd ** DONE Custom facilities! ** DONE Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation -** Test with/without openlog() -** Test custom facilities -** Test setlogmask() -** Test levels? -** Test v1 API, syslogp() +** DONE Test with/without openlog() +** DONE Test custom facilities +** DONE Test setlogmask() +** DONE Test v1 API, syslogp() ** DONE Add RFC5424 parsing of incoming msgs to syslogd ** DONE Local `stdout | stdin` unit testing ** DONE Rewrite man pages do mandoc format diff --git a/test/api.c b/test/api.c index d89b8b1..cc6ca6d 100644 --- a/test/api.c +++ b/test/api.c @@ -1,14 +1,48 @@ +#include +#include #include #include "syslog.h" -int main(void) +int main(int argc, char *argv[]) { + char *ident = NULL; char *msg = getenv("MSG"); + char c; + int severity = LOG_NOTICE; + int facility = LOG_CONSOLE; + int v1 = 0; if (!msg) return 1; - syslog(LOG_ERR, msg); + while ((c = getopt(argc, argv, "i:lp")) != EOF) { + switch (c) { + case 'i': + ident = optarg; + break; + + case 'l': + setlogmask(LOG_UPTO(severity)); + severity = LOG_INFO; + break; + + case 'p': + v1 = 1; + facility = LOG_FTP; + break; + } + } + + if (ident) + openlog(ident, LOG_NOWAIT, facility); + + if (v1) + syslogp(severity, "MSGID", NULL, msg); + else + syslog(severity, msg); + + if (ident) + closelog(); return 0; } diff --git a/test/api.sh b/test/api.sh index c97c18c..7f2db1f 100755 --- a/test/api.sh +++ b/test/api.sh @@ -3,5 +3,32 @@ set -e . ./test.rc export MSG="no-openlog-apitest" + +echo "= Phase 1 - simple syslog(), no openlog() ===============" ./api grep "api ${MSG}" ${LOG} + +echo "= Phase 2 - syslog() with openlog() & custom facility ===" +cat <${CONFD}/bar.conf +console.* -${LOGCONS} +EOF +kill -HUP `cat ${PID}` +sleep 2 + +./api -i foo +grep "foo ${MSG}" ${LOGCONS} + +echo "= Phase 3 - Verify setlogmask() filters out LOG_INFO ====" +./api -i xyzzy -l +grep "xyzzy ${MSG}" ${LOGCONS} || true + +echo "= Phase 4 - Verify RFC5424 API with syslogp() ===========" +cat <${CONFD}/v1.conf +ftp.* -${LOGV1} ;RFC5424 +EOF +kill -HUP `cat ${PID}` +sleep 2 + +./api -i troglobit -p +grep "troglobit - MSGID - ${MSG}" ${LOGV1} + diff --git a/test/stop.sh b/test/stop.sh index 5339a85..fb24863 100755 --- a/test/stop.sh +++ b/test/stop.sh @@ -7,7 +7,10 @@ if [ -e ${PID} ]; then fi rm -f ${LOG} +rm -f ${LOGV1} +rm -f ${LOGCONS} rm -f ${PID} rm -f ${CAP} rm -f ${SOCK} rm -f ${CONF} +rm -rf ${CONFD} diff --git a/test/test.rc b/test/test.rc index ff4e43a..e807d72 100644 --- a/test/test.rc +++ b/test/test.rc @@ -1,5 +1,7 @@ NM=syslog-test LOG=/tmp/${NM}.log +LOGV1=/tmp/${NM}-v1.log +LOGCONS=/tmp/${NM}-cons.log PID=/tmp/${NM}.pid CAP=/tmp/${NM}.pcapng CONF=/tmp/${NM}.conf