fix some races in check_clamd.sh

add more valgrind suppressions
better log parsing for valgrind
add mutex to prevent multiple simultaneous forks (bb #1187)

git-svn: trunk@4182
0.95
Török Edvin 17 years ago
parent f45111e58f
commit 1642ffba29
  1. 6
      clamd/others.c
  2. 31
      unit_tests/check_clamd.sh
  3. 36
      unit_tests/valgrind.supp
  4. 13
      unit_tests/valgrind_tests.sh

@ -56,6 +56,7 @@
#include <sys/filio.h>
#endif
#include <pthread.h>
/* submitted by breiter@wolfereiter.com: do not use poll(2) on Interix */
#ifdef C_INTERIX
#undef HAVE_POLL
@ -90,6 +91,8 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru
}
#else
static pthread_mutex_t virusaction_lock = PTHREAD_MUTEX_INITIALIZER;
void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
{
pid_t pid;
@ -137,6 +140,7 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru
free(buffer_vir);
return;
}
pthread_mutex_lock(&virusaction_lock);
/* We can only call async-signal-safe functions after fork(). */
pid = fork();
@ -145,9 +149,11 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru
/* WARNING: this is uninterruptable ! */
exit(execle("/bin/sh", "sh", "-c", cmd, NULL, env));
} else if (pid > 0) {
pthread_mutex_unlock(&virusaction_lock);
/* parent */
waitpid(pid, NULL, 0);
} else {
pthread_mutex_unlock(&virusaction_lock);
/* error.. */
logg("!VirusAction: fork failed.\n");
}

@ -107,27 +107,30 @@ run_clamdscan_fdpass() {
}
# We run multiple clamd tests in parallel, each in its own directory
rm -rf clamdtest$CLAMD_TEST_UNIQ1 clamdtest$CLAMD_TEST_UNIQ2
mkdir clamdtest$CLAMD_TEST_UNIQ1 clamdtest$CLAMD_TEST_UNIQ2 ||
{ echo "Unable to create temporary directories!"; exit 1; }
# Set up test DBdir
rm -rf test-db
mkdir -p test-db
cat <<EOF >test-db/test.hdb
prepare_clamd()
{
cd clamdtest$1
# Set up test DBdir
rm -rf test-db
mkdir -p test-db
cat <<EOF >test-db/test.hdb
aa15bcf478d165efd2065190eb473bcb:544:ClamAV-Test-File
EOF
cp $abs_srcdir/input/daily.ftm test-db/
cp $abs_srcdir/input/daily.pdb test-db/
cp $abs_srcdir/input/daily.ftm test-db/
cp $abs_srcdir/input/daily.pdb test-db/
awk "{ sub(/X/,\"$1\"); sub(/CWD/,\"`pwd`\"); print }" $abs_srcdir/test-clamd.conf >test-clamd.conf
}
rm -rf clamdtest$CLAMD_TEST_UNIQ1 clamdtest$CLAMD_TEST_UNIQ2
mkdir clamdtest$CLAMD_TEST_UNIQ1 clamdtest$CLAMD_TEST_UNIQ2 ||
{ echo "Unable to create temporary directories!"; exit 1; }
# Prepare configuration for clamd #1 and #2
awk "{ sub(/X/,\"$CLAMD_TEST_UNIQ1\"); sub(/CWD/,\"`pwd`/clamdtest$CLAMD_TEST_UNIQ1\"); print }" $abs_srcdir/test-clamd.conf >clamdtest$CLAMD_TEST_UNIQ1/test-clamd.conf
awk "{ sub(/X/,\"$CLAMD_TEST_UNIQ2\"); sub(/CWD/,\"`pwd`/clamdtest$CLAMD_TEST_UNIQ2\"); print }" $abs_srcdir/test-clamd.conf >clamdtest$CLAMD_TEST_UNIQ2/test-clamd.conf
(prepare_clamd $CLAMD_TEST_UNIQ1)
(prepare_clamd $CLAMD_TEST_UNIQ2)
# Add clamd #2 specific configuration
echo "VirusEvent $abs_srcdir/virusaction-test.sh `pwd`/clamdtest$CLAMD_TEST_UNIQ2 \"Virus found: %v\"" >>clamdtest$CLAMD_TEST_UNIQ2/test-clamd.conf
echo "HeuristicScanPrecedence yes" >>clamdtest$CLAMD_TEST_UNIQ2/test-clamd.conf
# Duplicate dbdirs
cp -R test-db clamdtest$CLAMD_TEST_UNIQ1/
cp -R test-db clamdtest$CLAMD_TEST_UNIQ2/
# Start clamd #1 tests
(cd clamdtest$CLAMD_TEST_UNIQ1

@ -12,6 +12,36 @@
obj:/lib*/libc-*.so
fun:__libc_freeres
}
{
glibc-etch1
Memcheck:Free
fun:*
fun:_dl_allocate_tls
}
{
glibc-etch2
Memcheck:Free
obj:/lib*/ld-*.so
obj:/lib*/ld-*.so
}
{
glibc-etch1
Memcheck:Free
fun:*
fun:_dl_allocate_tls
}
{
glibc-etch2
Memcheck:Addr8
obj:/lib*/ld-*.so
obj:/lib*/ld-*.so
}
{
glibc-etch2
Memcheck:Addr4
obj:/lib*/ld-*.so
obj:/lib*/ld-*.so
}
{
helgrind-glibc27-dbg01
Helgrind:Race
@ -123,3 +153,9 @@
Helgrind:Race
fun:exit
}
#{
# helgrind-glibc27-dbg18
# Helgrind:Race
# fun:__reclaim_stacks
# fun:fork
#}

@ -17,10 +17,10 @@ parse_valgrindlog()
echo "*** Logfile $1 not found. Valgrind failed to run?"
fi
NRUNS=`grep "ERROR SUMMARY" $1 | wc -l`
if test $NRUNS -eq `grep "ERROR SUMMARY: 0 errors" $1 | wc -l`; then
if test $NRUNS -eq `grep "ERROR SUMMARY: 0 errors" $1 | wc -l` -a `grep "FATAL:" $1|wc -l ` -eq 0; then
if test "$1" = "valgrind-race.log" ||
test $NRUNS -eq `grep "no leaks are possible" $1 | wc -l` ||
test `grep "lost:" $1 | grep -v "0 bytes" | wc -l` -ne 0; then
test `grep "lost:" $1 | grep -v "0 bytes" | wc -l` -eq 0; then
rm -f $1;
return
else
@ -40,22 +40,19 @@ parse_valgrindlog()
x
# print hold buffer
p
# get original line back
# get original line back and print
x
p
}
# store it in hold buffer
h
/^[=0-9]+ FILE DESC/ {
q
}
' <$1 | grep -v "Thread.+was created"
' <$1 | grep -Ev "Thread.+was created" | grep -v "Open"
fi
echo "***"
echo "*** Please submit $1 to http://bugs.clamav.net"
echo "***"
}
VALGRIND_FLAGS="-v --trace-children=yes --track-fds=yes --leak-check=full --suppressions=$abs_srcdir/valgrind.supp"
VALGRIND_FLAGS_RACE="-v --tool=helgrind --trace-children=yes --suppressions=$abs_srcdir/valgrind.supp"

Loading…
Cancel
Save