X-Git-Url: http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu%2Fglibc.git;a=blobdiff_plain;f=test-skeleton.c;h=e4fed67ae3123c11a0fd32283001a7f532e6a0ce;hp=418f69abdde0b6dbcb51586adcb253b1b5c6b001;hb=90a192105a28451b18ed23491b2b5f556e8dc92b;hpb=9cdcba42417897bc76e8f859a82ee97f576b9c7e diff --git a/test-skeleton.c b/test-skeleton.c index 418f69abdd..e4fed67ae3 100644 --- a/test-skeleton.c +++ b/test-skeleton.c @@ -18,6 +18,7 @@ Boston, MA 02111-1307, USA. */ #include +#include #include #include #include @@ -52,6 +53,39 @@ static int pid; /* Directory to place temporary files in. */ static const char *test_dir; +/* List of temporary files. */ +struct name_list +{ + struct qelem q; + const char *name; +} *name_list; + +/* Add temporary files in list. */ +void +add_temp_file (const char *name) +{ + struct name_list *newp = (struct name_list *) calloc (sizeof (*newp), 1); + if (newp != NULL) + { + newp->name = name; + if (name_list == NULL) + name_list = (struct name_list *) &newp->q; + else + insque (newp, name_list); + } +} + +/* Delete all temporary files. */ +void +delete_temp_files (void) +{ + while (name_list != NULL) + { + remove (name_list->name); + name_list = (struct name_list *) name_list->q.q_forw; + } +} + /* Timeout handler. We kill the child and exit with an error. */ void timeout_handler (int sig __attribute__ ((unused))) @@ -114,6 +148,23 @@ main (int argc, char *argv[]) exit (1); } } + else + { + test_dir = getenv ("TMPDIR"); + if (test_dir == NULL || test_dir[0] == '\0') + test_dir = "/tmp"; + } + + /* Make sure we see all message, even those on stdout. */ + setvbuf (stdout, NULL, _IONBF, 0); + + /* make sure temporary files are deleted. */ + atexit (delete_temp_files); + + /* Call the initializing function, if one is available. */ +#ifdef PREPARE + PREPARE (argc, argv); +#endif /* If we are not expected to fork run the function immediately. */ if (direct) @@ -164,11 +215,14 @@ main (int argc, char *argv[]) /* We don't expect any signal. */ # define EXPECTED_SIGNAL 0 #endif - if (WIFSIGNALED (status) != EXPECTED_SIGNAL) + if (WTERMSIG (status) != EXPECTED_SIGNAL) { - fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n", - strsignal (WIFSIGNALED (status)), - strsignal (EXPECTED_SIGNAL)); + if (EXPECTED_SIGNAL != 0) + fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n", + strsignal (WTERMSIG (status)), strsignal (EXPECTED_SIGNAL)); + else + fprintf (stderr, "Didn't expect signal from child: got `%s'\n", + strsignal (WTERMSIG (status))); exit (1); }