Merge remote branch 'davids/master' into work
This commit is contained in:
commit
61482066d5
|
@ -26,6 +26,7 @@
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
static unsigned int datasize = 100;
|
static unsigned int datasize = 100;
|
||||||
static unsigned int loops = 100;
|
static unsigned int loops = 100;
|
||||||
|
@ -60,8 +61,17 @@ typedef union {
|
||||||
long long error;
|
long long error;
|
||||||
} childinfo_t;
|
} childinfo_t;
|
||||||
|
|
||||||
|
childinfo_t *child_tab = NULL;
|
||||||
|
unsigned int total_children = 0;
|
||||||
|
unsigned int signal_caught = 0;
|
||||||
|
|
||||||
inline static void sneeze(const char *msg) {
|
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)
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned int i, total_children;
|
unsigned int i;
|
||||||
struct timeval start, stop, diff;
|
struct timeval start, stop, diff;
|
||||||
int readyfds[2], wakefds[2];
|
int readyfds[2], wakefds[2];
|
||||||
char dummy;
|
char dummy;
|
||||||
childinfo_t *child_tab;
|
|
||||||
|
|
||||||
process_options (argc, argv);
|
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);
|
printf("Each sender will pass %d messages of %d bytes\n", loops, datasize);
|
||||||
fflush(NULL);
|
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)
|
if (!child_tab)
|
||||||
barf("main:malloc()");
|
barf("main:malloc()");
|
||||||
|
|
||||||
fdpair(readyfds);
|
fdpair(readyfds);
|
||||||
fdpair(wakefds);
|
fdpair(wakefds);
|
||||||
|
|
||||||
|
/* Catch some signals */
|
||||||
|
signal(SIGINT, sigcatcher);
|
||||||
|
signal(SIGTERM, sigcatcher);
|
||||||
|
signal(SIGHUP, SIG_IGN);
|
||||||
|
|
||||||
total_children = 0;
|
total_children = 0;
|
||||||
for (i = 0; i < num_groups; i++) {
|
for (i = 0; i < num_groups; i++) {
|
||||||
int c = group(child_tab, total_children, num_fds, readyfds[1], wakefds[0]);
|
int c = group(child_tab, total_children, num_fds, readyfds[1], wakefds[0]);
|
||||||
|
|
Loading…
Reference in New Issue