Merge pull request #1232 from rgerhards/i-1040-incl-testbench

merge fixe for #1040 including new testbench
This commit is contained in:
Rainer Gerhards 2016-11-03 12:00:02 +01:00 committed by GitHub
commit cd5a131017
6 changed files with 65 additions and 4 deletions

View File

@ -1150,8 +1150,16 @@ getLocalHostname(uchar **ppName)
if(gethostname(hnbuf, sizeof(hnbuf)) != 0) {
strcpy(hnbuf, "localhost");
} else {
hnbuf[sizeof(hnbuf)-1] = '\0'; /* be on the safe side... */
/* now guard against empty hostname
* see https://github.com/rsyslog/rsyslog/issues/1040
*/
if(hnbuf[0] == '\0') {
strcpy(hnbuf, "localhost");
} else {
hnbuf[sizeof(hnbuf)-1] = '\0'; /* be on the safe side... */
}
}
char *dot = strstr(hnbuf, ".");
if(dot == NULL) {
/* we need to (try) to find the real name via resolver */

View File

@ -4,6 +4,14 @@ CLEANFILES = \
# IN_AUTO_DEBUG should be deleted each time make check is run, but
# there exists no such hook. Se we at least delete it on make clean.
pkglib_LTLIBRARIES =
pkglib_LTLIBRARIES += liboverride_gethostname.la
liboverride_gethostname_la_SOURCES = override_gethostname.c
liboverride_gethostname_la_CFLAGS =
liboverride_gethostname_la_LDFLAGS = -avoid-version -shared
# TODO: reenable TESTRUNS = rt_init rscript
check_PROGRAMS = $(TESTRUNS) ourtail nettester tcpflood chkseq msleep randomgen \
diagtalker uxsockrcvr syslog_caller inputfilegen minitcpsrv \
@ -13,6 +21,7 @@ TESTS = $(TESTRUNS)
#TESTS = $(TESTRUNS) cfg.sh
TESTS += \
empty-hostname.sh \
hostname-with-slash-pmrfc5424.sh \
hostname-with-slash-pmrfc3164.sh \
hostname-with-slash-dflt-invld.sh \
@ -529,6 +538,7 @@ DISTCLEANFILES=rsyslog.pid
test_files = testbench.h runtime-dummy.c
EXTRA_DIST= \
empty-hostname.sh \
hostname-with-slash-pmrfc5424.sh \
hostname-with-slash-pmrfc3164.sh \
hostname-with-slash-dflt-invld.sh \

View File

@ -145,7 +145,7 @@ case $1 in
echo "ERROR: config file '$CONF_FILE' not found!"
exit 1
fi
$valgrind ../tools/rsyslogd -C -n -irsyslog$3.pid -M../runtime/.libs:../.libs -f$CONF_FILE &
LD_PRELOAD=$RSYSLOG_PRELOAD $valgrind ../tools/rsyslogd -C -n -irsyslog$3.pid -M../runtime/.libs:../.libs -f$CONF_FILE &
. $srcdir/diag.sh wait-startup $3
;;
'startup-silent') # start rsyslogd with default params. $2 is the config file name to use

21
tests/empty-hostname.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# This is part of the rsyslog testbench, licensed under ASL 2.0
echo ======================================================================
. $srcdir/diag.sh init
. $srcdir/diag.sh generate-conf
. $srcdir/diag.sh add-conf '
action(type="omfile" file="rsyslog.out.log")
'
export RSYSLOG_PRELOAD=.libs/liboverride_gethostname.so
. $srcdir/diag.sh startup
. $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
. $srcdir/diag.sh wait-shutdown # we need to wait until rsyslogd is finished!
grep " localhost " < rsyslog.out.log
if [ ! $? -eq 0 ]; then
echo "expected hostname \"localhost\" not found in logs, rsyslog.out.log is:"
cat rsyslog.out.log
. $srcdir/diag.sh error-exit 1
fi;
. $srcdir/diag.sh exit

View File

@ -36,11 +36,11 @@ rsyslog_testbench_preload_libfaketime() {
exit 77
else
echo "Test passed! Will use '${RSYSLOG_LIBFAKETIME}' library!"
export LD_PRELOAD="${RSYSLOG_LIBFAKETIME}"
export RSYSLOG_PRELOAD="${RSYSLOG_LIBFAKETIME}"
fi
# GMT-1 (POSIX TIME) is GMT+1 in "Human Time"
faketime_testtime=$(FAKETIME="2040-01-01 16:00:00" TZ=GMT-1 date +%s 2>/dev/null)
faketime_testtime=$(LD_PRELOAD="${RSYSLOG_LIBFAKETIME}" FAKETIME="2040-01-01 16:00:00" TZ=GMT-1 date +%s 2>/dev/null)
if [ ${faketime_testtime} -eq -1 ]; then
echo "Note: System is not year-2038 compliant"
RSYSLOG_TESTBENCH_Y2K38_INCOMPATIBLE="yes"

View File

@ -0,0 +1,22 @@
// we need this for dlsym(): #include <dlfcn.h>
#include <stdio.h>
int gethostname(char *name, size_t __attribute__((unused)) len)
{
*name = '\0';
return 0;
}
static void __attribute__((constructor))
my_init(void)
{
/* we currently do not need this entry point, but keep it as
* a "template". It can be used, e.g. to emit some diagnostic
* information:
printf("loaded\n");
* or - more importantly - obtain a pointer to the overriden
* API:
orig_etry = dlsym(RTLD_NEXT, "original_entry_point");
*/
}