summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2010-02-23 13:48:05 -0600
committerClark Williams <williams@redhat.com>2010-02-23 13:48:05 -0600
commit61482066d5261c1ce76f8e504544b03c2544b6cd (patch)
treeb88d468e63e0ef2917508797581ed8ca04fe3cde
parent2359346741c39f97b98f36cd4bfe0e4f01635edf (diff)
parent4b563630e61f864f6591b0334a64406a98df606f (diff)
downloadrt-tests-61482066d5261c1ce76f8e504544b03c2544b6cd.tar.gz
Merge remote branch 'davids/master' into work
-rw-r--r--src/hackbench/hackbench.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c
index 7a731d3..c8d12bd 100644
--- a/src/hackbench/hackbench.c
+++ b/src/hackbench/hackbench.c
@@ -26,6 +26,7 @@
#include <sys/poll.h>
#include <limits.h>
#include <getopt.h>
+#include <signal.h>
static unsigned int datasize = 100;
static unsigned int loops = 100;
@@ -60,8 +61,17 @@ typedef union {
long long error;
} childinfo_t;
+childinfo_t *child_tab = NULL;
+unsigned int total_children = 0;
+unsigned int signal_caught = 0;
+
inline static void sneeze(const char *msg) {
- fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno));
+ /* Avoid calling these functions when called from a code path
+ * which involves sigcatcher(), as they are not reentrant safe.
+ */
+ if( !signal_caught ) {
+ fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno));
+ }
}
static void barf(const char *msg)
@@ -385,15 +395,22 @@ static void process_options (int argc, char *argv[])
}
}
-
+void sigcatcher(int sig) {
+ /* All caught signals will cause the program to exit */
+ signal_caught = 1;
+ if( child_tab && (total_children > 0) ) {
+ reap_workers(child_tab, total_children, 1);
+ }
+ fprintf(stderr, "** Operation aborted **\n");
+ exit(0);
+}
int main(int argc, char *argv[])
{
- unsigned int i, total_children;
+ unsigned int i;
struct timeval start, stop, diff;
int readyfds[2], wakefds[2];
char dummy;
- childinfo_t *child_tab;
process_options (argc, argv);
@@ -403,13 +420,18 @@ int main(int argc, char *argv[])
printf("Each sender will pass %d messages of %d bytes\n", loops, datasize);
fflush(NULL);
- child_tab = malloc(num_fds * 2 * num_groups * sizeof(childinfo_t));
+ child_tab = calloc(num_fds * 2 * num_groups, sizeof(childinfo_t));
if (!child_tab)
barf("main:malloc()");
fdpair(readyfds);
fdpair(wakefds);
+ /* Catch some signals */
+ signal(SIGINT, sigcatcher);
+ signal(SIGTERM, sigcatcher);
+ signal(SIGHUP, SIG_IGN);
+
total_children = 0;
for (i = 0; i < num_groups; i++) {
int c = group(child_tab, total_children, num_fds, readyfds[1], wakefds[0]);