Commit 83d6eb16 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a SIGALRM based timeout mechanism for test-termnation, for OS's

like Solaris which do not have pthread_timedjoin_np()

Fixes: #800


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5507 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 90121277
......@@ -37,6 +37,7 @@ SVNID("$Id$")
#include <fcntl.h>
#include <math.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -59,7 +60,7 @@ SVNID("$Id$")
#define MAX_TOKENS 200
static char *vtc_desc;
int vtc_error; /* Error encountered */
volatile sig_atomic_t vtc_error; /* Error encountered */
int vtc_stop; /* Stops current test without error */
pthread_t vtc_thread;
char vtc_tmpdir[PATH_MAX];
......@@ -525,13 +526,29 @@ exec_file_thread(void *priv)
return (NULL);
}
#ifndef HAVE_PTHREAD_TIMEDJOIN_NP
static volatile sig_atomic_t alrm_flag = 0;
static void
sigalrm(int x)
{
(void)x;
alrm_flag = 1;
vtc_error = 1;
}
#endif
static double
exec_file(const char *fn, unsigned dur)
{
double t0, t;
double t0;
struct priv_exec pe;
pthread_t pt;
#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
double t;
struct timespec ts;
#endif
void *v;
int i;
......@@ -546,6 +563,7 @@ exec_file(const char *fn, unsigned dur)
fn, strerror(errno));
pe.fn = fn;
#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
t = TIM_real() + dur;
ts.tv_sec = (long)floor(t);
ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9);
......@@ -553,6 +571,16 @@ exec_file(const char *fn, unsigned dur)
AZ(pthread_create(&pt, NULL, exec_file_thread, &pe));
i = pthread_timedjoin_np(pt, &v, &ts);
memset(&vtc_thread, 0, sizeof vtc_thread);
#else
alrm_flag = 0;
(void)signal(SIGALRM, sigalrm);
alarm(dur);
AZ(pthread_create(&pt, NULL, exec_file_thread, &pe));
i = pthread_join(pt, &v);
alarm(0);
if (alrm_flag)
i = ETIMEDOUT;
#endif
if (i != 0) {
if (i != ETIMEDOUT)
......
......@@ -58,7 +58,7 @@ cmd_f cmd_varnish;
cmd_f cmd_sema;
extern int vtc_verbosity;
extern int vtc_error; /* Error, bail out */
extern volatile sig_atomic_t vtc_error; /* Error, bail out */
extern int vtc_stop; /* Abandon current test, no error */
extern pthread_t vtc_thread;
extern char vtc_tmpdir[PATH_MAX];
......
......@@ -172,6 +172,7 @@ save_LIBS="${LIBS}"
LIBS="${PTHREAD_LIBS}"
AC_CHECK_FUNCS([pthread_set_name_np])
AC_CHECK_FUNCS([pthread_mutex_isowned_np])
AC_CHECK_FUNCS([pthread_timedjoin_np])
LIBS="${save_LIBS}"
# sendfile is tricky: there are multiple versions, and most of them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment