2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

revisit waitpid EINTR handling

This commit is contained in:
William King
1999-10-26 21:51:37 +00:00
parent e7b4d4feb4
commit e8fe5175c5

View File

@@ -44,11 +44,12 @@ static char *Usage = "\t-a : run all tests\n"
/* /*
* -a --> run all tests * -a --> run all tests
* -b dir --> chdir to dir before running tests * -b dir --> chdir to dir before running tests
* -tn --> run test n
* -c config --> use config file 'config' * -c config --> use config file 'config'
* -d --> turn on api debugging * -d --> turn on api debugging
* -n name --> run test named name
* -h --> print out available test names * -h --> print out available test names
* -u --> print usage info
* -n name --> run test named name
* -tn --> run test n
* -x --> don't execute testcases in a subproc * -x --> don't execute testcases in a subproc
* -q timeout --> use 'timeout' as the timeout value * -q timeout --> use 'timeout' as the timeout value
*/ */
@@ -75,36 +76,39 @@ static int t_putinfo(const char *key, const char *info);
static char *t_getdate(char *buf, size_t buflen); static char *t_getdate(char *buf, size_t buflen);
static void printhelp(void); static void printhelp(void);
static void printusage(void); static void printusage(void);
static void t_sigalrm(); static void t_sighandler();
static int T_int;
static void static void
t_sigalrm() { t_sighandler() {
int a; T_int = 1;
a = 1;
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int c; int c;
int tnum; int tnum;
int subprocs; int subprocs;
pid_t deadpid; pid_t deadpid;
int status; int status;
int len; int len;
testspec_t *pts; testspec_t *pts;
struct sigaction sa;
subprocs = 1; subprocs = 1;
T_timeout = T_TIMEOUT; T_timeout = T_TIMEOUT;
/* -a option is now default */
memset(T_tvec, 0xffff, sizeof(T_tvec));
/* parse args */ /* parse args */
while ((c = isc_commandline_parse(argc, argv, ":at:c:d:n:huxq:b:")) while ((c = isc_commandline_parse(argc, argv, ":at:c:d:n:huxq:b:")) != -1) {
!= -1) {
if (c == 'a') { if (c == 'a') {
/* flag all tests to be run */ /* flag all tests to be run */
memset(T_tvec, 0xffff, sizeof(T_tvec)); memset(T_tvec, 0xffff, sizeof(T_tvec));
/* memset(T_tvec, UINT_MAX, sizeof(T_tvec)); */
} }
else if (c == 'b') { else if (c == 'b') {
T_dir = isc_commandline_argument; T_dir = isc_commandline_argument;
@@ -167,12 +171,24 @@ main(int argc, char **argv)
} }
} }
/* set cwd */
if (T_dir != NULL) if (T_dir != NULL)
(void) chdir(T_dir); (void) chdir(T_dir);
/* we don't want buffered output */
(void) setbuf(stdout, NULL); (void) setbuf(stdout, NULL);
(void) setbuf(stderr, NULL); (void) setbuf(stderr, NULL);
/* setup signals */
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
sa.sa_handler = t_sighandler;
(void) sigaction(SIGALRM, &sa, NULL);
(void) sigaction(SIGINT, &sa, NULL);
/* output start stanza to journal */ /* output start stanza to journal */
sprintf(T_buf, "%s:", argv[0]); sprintf(T_buf, "%s:", argv[0]);
@@ -180,9 +196,8 @@ main(int argc, char **argv)
(void) t_getdate(T_buf + len, T_BIGBUF - len); (void) t_getdate(T_buf + len, T_BIGBUF - len);
t_putinfo("S", T_buf); t_putinfo("S", T_buf);
/* /* setup the test environment using the config file */
* setup the test environment using the config file
*/
if (T_config == NULL) if (T_config == NULL)
T_config = T_DEFAULT_CONFIG; T_config = T_DEFAULT_CONFIG;
@@ -190,9 +205,8 @@ main(int argc, char **argv)
if (T_debug) if (T_debug)
t_dumpconf(T_config); t_dumpconf(T_config);
/* /* now invoke all the test cases */
* now invoke all the test cases
*/
tnum = 0; tnum = 0;
pts = &T_testlist[0]; pts = &T_testlist[0];
while (*pts->pfv != NULL) { while (*pts->pfv != NULL) {
@@ -205,14 +219,7 @@ main(int argc, char **argv)
} }
else if (T_pid > 0) { else if (T_pid > 0) {
struct sigaction sa; T_int = 0;
struct sigaction osa;
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
sa.sa_handler = t_sigalrm;
(void) sigaction(SIGALRM, &sa, &osa);
alarm(T_timeout); alarm(T_timeout);
deadpid = (pid_t) -1; deadpid = (pid_t) -1;
@@ -220,26 +227,22 @@ main(int argc, char **argv)
deadpid = waitpid(T_pid, &status, 0); deadpid = waitpid(T_pid, &status, 0);
if (deadpid == T_pid) { if (deadpid == T_pid) {
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGABRT) { t_info("the test case caught an exception\n");
t_info("the test case caused an exception\n"); t_result(T_UNRESOLVED);
t_result(T_UNRESOLVED);
}
} }
} }
else if ((deadpid == -1) && (errno == EINTR)) { else if ((deadpid == -1) && (errno == EINTR) && T_int) {
t_info("the test case was interrupted\n"); t_info("the test case was interrupted\n");
kill(T_pid, SIGTERM); kill(T_pid, SIGTERM);
t_result(T_UNRESOLVED); t_result(T_UNRESOLVED);
alarm(0);
break; break;
} }
} }
alarm(0); alarm(0);
(void) sigaction(SIGALRM, &osa, NULL);
} }
else { else {
t_info("fork failed errno = %d\n", errno); t_info("fork failed, errno == %d\n", errno);
t_result(T_UNRESOLVED); t_result(T_UNRESOLVED);
} }
} }