diff --git a/src/fakewww.c b/src/fakewww.c
index 42f89aa..906d1a0 100644
--- a/src/fakewww.c
+++ b/src/fakewww.c
@@ -571,9 +571,9 @@ void dowww(int sd, I2Addr addr, char* port, char* AcLogFileName,
             I2AddrNodeName(serv_addr, onenodename, &nlen);
             log_println(4, "find_compare6() returned 0, reset to [%s]",
                         onenodename);
-	    struct sockaddr* sock_addr = I2AddrSAddr(serv_addr, NULL);
+            struct sockaddr* sock_addr = I2AddrSAddr(serv_addr, NULL);
             memcpy(srv_addr6,
-                   &((struct sockaddr_in6*)sock_addr)->sin6_addr,
+                   &(((struct sockaddr_in6*)sock_addr)->sin6_addr),
                    16);
           }
 
diff --git a/src/genplot.c b/src/genplot.c
index 1db6f77..cb3bcd1 100644
--- a/src/genplot.c
+++ b/src/genplot.c
@@ -50,7 +50,8 @@ int checkmz(int x) {
 }
 
 void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
-               web100_group* group, char* title, char* remport) {
+               web100_group* group, char* title, size_t title_len,
+               char* remport, size_t remport_len) {
   web100_var* var;
   char buf[128];
 
@@ -68,8 +69,8 @@ void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
     web100_perror("web100_snap_read");
     exit(EXIT_FAILURE);
   }
-  strcpy(title, web100_value_to_text(web100_get_var_type(var), buf));
-  strncat(title, ":", 1);
+  snprintf(title, title_len, "%s:",
+           web100_value_to_text(web100_get_var_type(var), buf));
   if ((web100_agent_find_var_and_group(agent, "LocalPort", &group, &var))
       != WEB100_ERR_SUCCESS) {
     web100_perror("web100_agent_find_var_and_group");
@@ -79,8 +80,8 @@ void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
     web100_perror("web100_snap_read");
     exit(EXIT_FAILURE);
   }
-  strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
-  strncat(title, " --> ", 5);
+  snprintf(title, title_len, "%s --> ", title,
+           web100_value_to_text(web100_get_var_type(var), buf));
   if ((web100_agent_find_var_and_group(agent, "RemAddress", &group, &var))
       != WEB100_ERR_SUCCESS) {
     web100_perror("web100_agent_find_var_and_group");
@@ -90,7 +91,8 @@ void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
     web100_perror("web100_snap_read");
     exit(EXIT_FAILURE);
   }
-  strcat(title, web100_value_to_text(web100_get_var_type(var), buf));
+  snprintf(title, title_len, "%s%s", title,
+           web100_value_to_text(web100_get_var_type(var), buf));
   if ((web100_agent_find_var_and_group(agent, "RemPort", &group, &var))
       != WEB100_ERR_SUCCESS) {
     web100_perror("web100_agent_find_var_and_group");
@@ -100,7 +102,8 @@ void get_title(web100_snapshot* snap, web100_log* log, web100_agent* agent,
     web100_perror("web100_snap_read");
     exit(EXIT_FAILURE);
   }
-  strcpy(remport, web100_value_to_text(web100_get_var_type(var), buf));
+  snprintf(remport, remport_len, "%s",
+           web100_value_to_text(web100_get_var_type(var), buf));
   /* printf("%s:%s\n", title, remport); */
 }
 
@@ -117,14 +120,15 @@ void plot_var(char *list, int cnt, char *name, web100_snapshot* snap,
   FILE *fn;
 
   /* Write a xplot file out to the requested file.
-   * Start by extracting the connection info for the 
+   * Start by extracting the connection info for the
    * page title.  Then its a series of line statements
    * with the x1 y1 x2 y2 coordinates.
    */
 
   memset(lname, 0, 256);
 
-  get_title(snap, log, agent, group, title, remport);
+  get_title(snap, log, agent, group, title, sizeof(title),
+            remport, sizeof(remport));
 
   if (name == NULL) {
     fn = stdout;
@@ -284,7 +288,8 @@ void plot_cwndtime(char *name, web100_snapshot* snap, web100_log* log,
 
   memset(lname, 0, 256);
 
-  get_title(snap, log, agent, group, title, remport);
+  get_title(snap, log, agent, group, title, sizeof(title),
+            remport, sizeof(remport));
 
   if (name == NULL) {
     fn = stdout;
@@ -394,7 +399,8 @@ void print_var(char *varlist, web100_snapshot* snap, web100_log* log,
   FILE* fn;
 
   fn = stdout;
-  get_title(snap, log, agent, group, title, remport);
+  get_title(snap, log, agent, group, title, sizeof(title),
+            remport, sizeof(remport));
   fprintf(fn, "Extracting Data from %s:%s connection\n\n", title, remport);
 
   strncpy(savelist, varlist, strlen(varlist) + 1);
diff --git a/src/utils.c b/src/utils.c
index 61f8db3..23d82ed 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -91,8 +91,8 @@ int check_long(char* text, long* number) {
   assert(text != NULL);
   assert(number != NULL);
 
-  if (((*number = strtol(text, &tmp, 10)) == LONG_MAX)
-      || (*number == LONG_MIN)) {
+  if (((*number = strtol(text, &tmp, 10)) == LONG_MAX) ||
+      (*number == LONG_MIN)) {
     return 1;
   }
   if ((*text != '\0') && (*tmp == '\0')) {
diff --git a/src/web100-admin.c b/src/web100-admin.c
index 06bf6e7..d40f862 100644
--- a/src/web100-admin.c
+++ b/src/web100-admin.c
@@ -13,6 +13,7 @@
 #include <unistd.h>
 
 #include "web100srv.h"
+#include "heuristics.h"
 #include "logging.h"
 #include "web100-admin.h"
 #include "utils.h"
@@ -350,7 +351,6 @@ void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts,
               int bad_cable, int totalcnt, int refresh) {
   FILE * fp;
   char view_string[256], tmpstr[256];
-  int i;
   struct flock lock;
 
   fp = fopen(AdminFileName, "w");
@@ -532,7 +532,7 @@ void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts,
   /* Save the current variables into a file for later use.  These
    * variables are updated by each child process at the end of every
    * test.  This data must be shared between multiple children.  If
-   * not, then the admin view page doesn't get update after every 
+   * not, then the admin view page doesn't get update after every
    * test.
    */
   fp = fopen("/tmp/view.string", "w");
@@ -540,7 +540,11 @@ void gen_html(int c2sspd, int s2cspd, int MinRTT, int PktsRetrans, int Timeouts,
     return;
   }
   lock.l_type = F_WRLCK;
-  i = fcntl(fileno(fp), F_SETLKW, lock);
+  if (fcntl(fileno(fp), F_SETLKW, lock) == -1) {
+    log_println(0, "Failed to lock '/tmp/view.string' for updating: %s",
+                strerror(errno));
+    return;
+  }
   log_println(1, "successfully locked '/tmp/view.string' for updating");
   snprintf(view_string, sizeof(view_string),
       "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,"
diff --git a/src/web100-pcap.c b/src/web100-pcap.c
index 889da44..8953923 100644
--- a/src/web100-pcap.c
+++ b/src/web100-pcap.c
@@ -820,153 +820,140 @@ void print_speed(u_char *user, const struct pcap_pkthdr *h, const u_char *p) {
         if (I2SockAddrIsLoopback(sock_addr, saddrlen) > 0)
           // hardcoding device address to 100, as initialised in main()
           strlcpy(device, "lo", 100);
-        if (device == NULL) {
-          if (pcap_findalldevs(&alldevs, errbuf) == 0) {
-            for (dp = alldevs; dp != NULL; dp = dp->next) {
-              for (curAddr = dp->addresses; curAddr != NULL;
-                   curAddr = curAddr->next) {
-                switch (curAddr->addr->sa_family) {
-                  case AF_INET:
-                    memset(namebuf, 0, 200);
-                    inet_ntop(
-                        AF_INET,
-                        &((struct sockaddr_in *) curAddr->addr)->sin_addr,
-                        namebuf, INET_ADDRSTRLEN);
-                    log_println(3, "IPv4 interface found address=%s",
-                                namebuf);
-                    if (((struct sockaddr_in *) curAddr->addr)->sin_addr.s_addr
-                        == ((struct sockaddr_in *) src_addr)->sin_addr.s_addr) {
-                      log_println(
-                          4,
-                          "IPv4 address match, setting device to '%s'",
-                          dp->name);
-                      device = dp->name;
-                      ifspeed = -1;
-                      for (i = 0; iflist.name[0][i] != '0'; i++) {
-                        if (strncmp((char *) iflist.name[i], device, 4)
-                            == 0) {
-                          ifspeed = iflist.speed[i];
-                          break;
-                        }
+        if (device == NULL && pcap_findalldevs(&alldevs, errbuf) == 0) {
+          for (dp = alldevs; dp != NULL; dp = dp->next) {
+            for (curAddr = dp->addresses; curAddr != NULL;
+                 curAddr = curAddr->next) {
+              switch (curAddr->addr->sa_family) {
+                case AF_INET:
+                  memset(namebuf, 0, 200);
+                  inet_ntop(
+                      AF_INET,
+                      &((struct sockaddr_in *) curAddr->addr)->sin_addr,
+                      namebuf, INET_ADDRSTRLEN);
+                  log_println(3, "IPv4 interface found address=%s",
+                              namebuf);
+                  if (((struct sockaddr_in*) curAddr->addr)->sin_addr.s_addr ==
+                      ((struct sockaddr_in*) src_addr)->sin_addr.s_addr) {
+                    log_println(4,
+                                "IPv4 address match, setting device to '%s'",
+                                dp->name);
+                    device = dp->name;
+                    ifspeed = -1;
+                    for (i = 0; iflist.name[0][i] != '0'; i++) {
+                      if (strncmp((char *) iflist.name[i], device, 4) == 0) {
+                        ifspeed = iflist.speed[i];
+                        break;
                       }
+                    }
 
-                      if (direction[0] == 's') {
+                    if (direction[0] == 's') {
 #if defined(AF_INET6)
-                        fwd.saddr[0] =
-                            ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
-                        fwd.daddr[0] =
-                            ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
-                        rev.saddr[0] =
-                            ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
-                        rev.daddr[0] =
-                            ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+                      fwd.saddr[0] =
+                          ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+                      fwd.daddr[0] =
+                          ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+                      rev.saddr[0] =
+                          ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+                      rev.daddr[0] =
+                          ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
 #else
-                        fwd.saddr =
-                            ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
-                        fwd.daddr =
-                            ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
-                        rev.saddr =
-                            ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
-                        rev.daddr =
-                            ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
+                      fwd.saddr =
+                          ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
+                      fwd.daddr =
+                          ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
+                      rev.saddr =
+                          ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
+                      rev.daddr =
+                          ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
 #endif
-                        fwd.sport =
-                            ntohs(
-                                ((struct sockaddr_in *) src_addr)->sin_port);
-                        fwd.dport =
-                            ntohs(
-                                ((struct sockaddr_in *) sock_addr)->sin_port);
-                        rev.sport =
-                            ntohs(
-                                ((struct sockaddr_in *) sock_addr)->sin_port);
-                        rev.dport =
-                            ntohs(
-                                ((struct sockaddr_in *) src_addr)->sin_port);
-                      } else {
+                      fwd.sport = ntohs(
+                          ((struct sockaddr_in *) src_addr)->sin_port);
+                      fwd.dport = ntohs(
+                          ((struct sockaddr_in *) sock_addr)->sin_port);
+                      rev.sport = ntohs(
+                          ((struct sockaddr_in *) sock_addr)->sin_port);
+                      rev.dport = ntohs(
+                          ((struct sockaddr_in *) src_addr)->sin_port);
+                    } else {
 #if defined(AF_INET6)
-                        rev.saddr[0] =
-                            ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
-                        rev.daddr[0] =
-                            ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
-                        fwd.saddr[0] =
-                            ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
-                        fwd.daddr[0] =
-                            ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+                      rev.saddr[0] =
+                          ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+                      rev.daddr[0] =
+                          ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+                      fwd.saddr[0] =
+                          ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+                      fwd.daddr[0] =
+                          ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
 #else
-                        rev.saddr =
-                            ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
-                        rev.daddr =
-                            ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
-                        fwd.saddr =
-                            ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
-                        fwd.daddr =
-                            ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
+                      rev.saddr =
+                          ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
+                      rev.daddr =
+                          ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
+                      fwd.saddr =
+                          ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
+                      fwd.daddr =
+                          ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
 #endif
-                        rev.sport =
-                            ntohs(
-                                ((struct sockaddr_in *) src_addr)->sin_port);
-                        rev.dport =
-                            ntohs(
-                                ((struct sockaddr_in *) sock_addr)->sin_port);
-                        fwd.sport =
-                            ntohs(
-                                ((struct sockaddr_in *) sock_addr)->sin_port);
-                        fwd.dport =
-                            ntohs(
-                                ((struct sockaddr_in *) src_addr)->sin_port);
-                      }
-                      goto endLoop;
+                      rev.sport = ntohs(
+                          ((struct sockaddr_in *) src_addr)->sin_port);
+                      rev.dport = ntohs(
+                          ((struct sockaddr_in *) sock_addr)->sin_port);
+                      fwd.sport = ntohs(
+                          ((struct sockaddr_in *) sock_addr)->sin_port);
+                      fwd.dport = ntohs(
+                          ((struct sockaddr_in *) src_addr)->sin_port);
                     }
-                    break;
+                    goto endLoop;
+                  }
+                  break;
 #if defined(AF_INET6)
-                  case AF_INET6:
-                    memset(namebuf, 0, 200);
-                    inet_ntop(AF_INET6,
-                              &((struct sockaddr_in6*)(curAddr->addr))->sin6_addr,
-                              namebuf, INET6_ADDRSTRLEN);
-                    /* I2AddrNodeName(srcAddr, namebuf, &nameBufLen); */
-                    log_println(3, "IPv6 interface found address=%s", namebuf);
-                    if (memcmp(((struct sockaddr_in6 *)curAddr->addr)->
-                                  sin6_addr.s6_addr,
-                               ((struct sockaddr_in6 *)src_addr)->
-                                  sin6_addr.s6_addr,
-                               16) == 0) {
-                      log_println(4, "IPv6 address match, setting device to "
-                                  "'%s'", dp->name);
-                      device = dp->name;
-
-                      struct sockaddr_in6* src_addr6 =
-                          (struct sockaddr_in6*)src_addr;
-                      struct sockaddr_in6* sock_addr6 =
-                          (struct sockaddr_in6*)sock_addr;
-
-                      if (direction[0] == 's') {
-                        memcpy(fwd.saddr, src_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(fwd.daddr, sock_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(rev.saddr, sock_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(rev.daddr, src_addr6->sin6_addr.s6_addr, 16);
-                        fwd.sport = ntohs(src_addr6->sin6_port);
-                        fwd.dport = ntohs(sock_addr6->sin6_port);
-                        rev.sport = ntohs(sock_addr6->sin6_port);
-                        rev.dport = ntohs(src_addr6->sin6_port);
-                      } else {
-                        memcpy(rev.saddr, src_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(rev.daddr, sock_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(fwd.saddr, sock_addr6->sin6_addr.s6_addr, 16);
-                        memcpy(fwd.daddr, src_addr6->sin6_addr.s6_addr, 16);
-                        rev.sport = ntohs(src_addr6->sin6_port);
-                        rev.dport = ntohs(sock_addr6->sin6_port);
-                        fwd.sport = ntohs(sock_addr6->sin6_port);
-                        fwd.dport = ntohs(src_addr6->sin6_port);
-                      }
-                      goto endLoop;
+                case AF_INET6:
+                  memset(namebuf, 0, 200);
+                  inet_ntop(AF_INET6,
+                            &((struct sockaddr_in6*)(curAddr->addr))->sin6_addr,
+                            namebuf, INET6_ADDRSTRLEN);
+                  /* I2AddrNodeName(srcAddr, namebuf, &nameBufLen); */
+                  log_println(3, "IPv6 interface found address=%s", namebuf);
+                  if (memcmp(
+                      ((struct sockaddr_in6*)curAddr->addr)->sin6_addr.s6_addr,
+                      ((struct sockaddr_in6*)src_addr)->sin6_addr.s6_addr,
+                      16) == 0) {
+                    log_println(4, "IPv6 address match, setting device to '%s'",
+                                dp->name);
+                    device = dp->name;
+
+                    struct sockaddr_in6* src_addr6 =
+                        (struct sockaddr_in6*)src_addr;
+                    struct sockaddr_in6* sock_addr6 =
+                        (struct sockaddr_in6*)sock_addr;
+
+                    if (direction[0] == 's') {
+                      memcpy(fwd.saddr, src_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(fwd.daddr, sock_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(rev.saddr, sock_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(rev.daddr, src_addr6->sin6_addr.s6_addr, 16);
+                      fwd.sport = ntohs(src_addr6->sin6_port);
+                      fwd.dport = ntohs(sock_addr6->sin6_port);
+                      rev.sport = ntohs(sock_addr6->sin6_port);
+                      rev.dport = ntohs(src_addr6->sin6_port);
+                    } else {
+                      memcpy(rev.saddr, src_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(rev.daddr, sock_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(fwd.saddr, sock_addr6->sin6_addr.s6_addr, 16);
+                      memcpy(fwd.daddr, src_addr6->sin6_addr.s6_addr, 16);
+                      rev.sport = ntohs(src_addr6->sin6_port);
+                      rev.dport = ntohs(sock_addr6->sin6_port);
+                      fwd.sport = ntohs(sock_addr6->sin6_port);
+                      fwd.dport = ntohs(src_addr6->sin6_port);
                     }
-                    break;
+                    goto endLoop;
+                  }
+                  break;
 #endif
-                  default:
-                    log_println(4, "Unknown address family=%d found",
-                                curAddr->addr->sa_family);
-                }
+                default:
+                  log_println(4, "Unknown address family=%d found",
+                              curAddr->addr->sa_family);
               }
             }
           }
diff --git a/src/web100-util.c b/src/web100-util.c
index 6164c02..2f8ab35 100644
--- a/src/web100-util.c
+++ b/src/web100-util.c
@@ -759,12 +759,12 @@ int CwndDecrease(web100_agent* agent, char* logname, u_int32_t *dec_cnt,
  * @param nwords integer length (in bytes) of the header
  * @return unsigned short checksum
  */
-unsigned short csum(unsigned short *buff, int nwords) {
+uint16_t csum(uint16_t *buff, int nwords) {
   /* generate a TCP/IP checksum for our packet */
 
-  register int sum = 0;
-  u_short answer = 0;
-  register u_short *w = buff;
+  register int32_t sum = 0;
+  uint16_t answer = 0;
+  register uint16_t *w = buff;
   register int nleft = nwords;
 
   // make 16 bit words out of every couple of 8 bit words and
@@ -775,7 +775,7 @@ unsigned short csum(unsigned short *buff, int nwords) {
   }
 
   if (nleft == 1) {
-    *(u_char *) (&answer) = *(u_char *) w;
+    *(uint8_t*) (&answer) = *(uint8_t*) w;
     sum += answer;
   }
 
@@ -902,7 +902,7 @@ int KillHung(void) {
       tcp->ack = 1;
       /* tcp->fin = 1; */
       tcp->urg_ptr = 0;
-      tcp->check = csum((unsigned short *) phdr,
+      tcp->check = csum((uint16_t*) phdr,
                         sizeof(struct tcphdr) + sizeof(struct pseudo_hdr));
 
       bzero(pkt, sizeof(struct iphdr));
@@ -918,7 +918,7 @@ int KillHung(void) {
       ip->daddr = dst.s_addr;
       sin.sin_addr.s_addr = dst.s_addr;
 
-      ip->check = csum((unsigned short *) pkt, sizeof(struct iphdr));
+      ip->check = csum((uint16_t*) pkt, sizeof(struct iphdr));
 
       if (setsockopt(sd, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)) < 0)
         return (-1);
diff --git a/src/web100srv.c b/src/web100srv.c
index b3c1abb..3da73e8 100644
--- a/src/web100srv.c
+++ b/src/web100srv.c
@@ -1914,846 +1914,806 @@ int main(int argc, char** argv) {
   sem_init(&ndtq, 0, 1);
 
   for (;;) {
-mainloop: if (head_ptr == NULL)
-            log_println(3, "nothing in queue");
-          else
-            log_println(
-                3,
-                "Queue pointer=%d, testing=%d, waiting=%d, mclients=%d, "
-                "zombie_check=%d",
-                head_ptr->pid, testing, waiting, mclients, zombie_check);
-
-          // moved condition from interrupt handler to here
-          /* if ((sig1 > 0) || (sig2 > 0))
-           * 	check_signal_flags;
-           */
-
-          if (sig13 == 1) {
-            log_println(5, "todo: Handle SIGPIPE signal, terminate child?");
-            child_sig(0);
-            sig13 = 0;
-          }
+ mainloop:
+    if (head_ptr == NULL)
+      log_println(3, "nothing in queue");
+    else
+      log_println(
+          3,
+          "Queue pointer=%d, testing=%d, waiting=%d, mclients=%d, "
+          "zombie_check=%d",
+          head_ptr->pid, testing, waiting, mclients, zombie_check);
+
+    // moved condition from interrupt handler to here
+    /* if ((sig1 > 0) || (sig2 > 0))
+     * 	check_signal_flags;
+     */
 
-          if (sig17 > 0) {
-            log_println(5, "Handle pending SIGCHLD signal, count=%d", sig17);
-            child_sig(0);
-          }
+    if (sig13 == 1) {
+      log_println(5, "todo: Handle SIGPIPE signal, terminate child?");
+      child_sig(0);
+      sig13 = 0;
+    }
 
-          if ((multiple == 1) && (mclients < max_clients)
-              && (waiting >= max_clients)) {
-            // This condition means that there are clients waiting and there
-            // are open slots in the test queue, so dispatch another client.
-            //   RAC 12/11/09
+    if (sig17 > 0) {
+      log_println(5, "Handle pending SIGCHLD signal, count=%d", sig17);
+      child_sig(0);
+    }
 
-            log_println(5, "Empty slot in test queue, find new client to "
-                        "dispatch");
-            /* tmp_ptr = head_ptr; */
-            mchild = head_ptr;
-            i = 0;
-            while (mchild != NULL) {
-              i++;  // Keep count of how many times we go through this loop
-              log_println(
-                  2,
-                  "walking queue look for non-running client current=%d, "
-                  "running=%d, next=0x%x",
-                  mchild->pid, mchild->running, mchild->next);
-              if (mchild->running == 0) {
-                /* mchild = tmp_ptr; */
-                log_println(
-                    6,
-                    "found non-running client %d, update queue and dispatch "
-                    "this client",
-                    mchild->pid);
-                break;
-              }
-              mchild = mchild->next;
-            }
-            if (i > max_clients) {
-              log_println(6,
-                          "walked through running client list, no empty "
-                          "slots!");
-              continue;
-            }
+    if ((multiple == 1) && (mclients < max_clients)
+        && (waiting >= max_clients)) {
+      // This condition means that there are clients waiting and there
+      // are open slots in the test queue, so dispatch another client.
+      //   RAC 12/11/09
+
+      log_println(5, "Empty slot in test queue, find new client to "
+                  "dispatch");
+      /* tmp_ptr = head_ptr; */
+      mchild = head_ptr;
+      i = 0;
+      while (mchild != NULL) {
+        i++;  // Keep count of how many times we go through this loop
+        log_println(2,
+                    "walking queue look for non-running client current=%d, "
+                    "running=%d, next=0x%x",
+                    mchild->pid, mchild->running, mchild->next);
+        if (mchild->running == 0) {
+          /* mchild = tmp_ptr; */
+          log_println(6,
+                      "found non-running client %d, update queue and dispatch "
+                      "this client", mchild->pid);
+          break;
+        }
+        mchild = mchild->next;
+      }
+      if (i > max_clients) {
+        log_println(6, "walked through running client list, no empty slots!");
+        continue;
+      }
 
-            /* if ((mchild->next == NULL) && (mchild->running == 0))
-             *   mchild = tmp_ptr;
-             * if (mchild != head_ptr) {
-             */
-            tmp_ptr = mchild;
-
-            // Update queued clients, send message to client when it moves
-            //  up in the queue enough to get closer to running a test.  This
-            //  happens when the client falls into the next lower maxqueue bin
-            //  RAC 3/21/10
-
-            int rac;
-            if (waiting > (2 * max_clients)) {
-              for (i = max_clients; i <= waiting; i++) {
-                if (tmp_ptr == NULL)
-                  break;
-                if (i == (2 * max_clients)) {
-                  rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "1", 1);
-                  log_println(
-                      6,
-                      "sent 45 sec update message to client %d on fd=%d, "
-                      "send_msg() returned %d",
-                      tmp_ptr->pid, tmp_ptr->ctlsockfd, rac);
-                }
-                if (i == (3 * max_clients)) {
-                  rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "2", 1);
-                  log_println(
-                      6,
-                      "sent 90 sec update message to client %d on fd=%d, "
-                      "send_msg() returned %d",
-                      tmp_ptr->pid, tmp_ptr->ctlsockfd, rac);
-                }
-                tmp_ptr = tmp_ptr->next;
-              }
-            }
-            goto dispatch_client;
-          }
+      /* if ((mchild->next == NULL) && (mchild->running == 0))
+       *   mchild = tmp_ptr;
+       * if (mchild != head_ptr) {
+       */
+      tmp_ptr = mchild;
 
-          if ((waiting < 0) || (mclients < 0)) {
+      // Update queued clients, send message to client when it moves
+      //  up in the queue enough to get closer to running a test.  This
+      //  happens when the client falls into the next lower maxqueue bin
+      //  RAC 3/21/10
+
+      int rac;
+      if (waiting > (2 * max_clients)) {
+        for (i = max_clients; i <= waiting; i++) {
+          if (tmp_ptr == NULL)
+            break;
+          if (i == (2 * max_clients)) {
+            rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "1", 1);
             log_println(
                 6,
-                "Fault: Negative number of clents waiting=%d, mclients=%d, "
-                "nuke them",
-                waiting, mclients);
-            while (head_ptr != NULL) {
-              /* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9933", 4); */
-              // indicate server waiting in queue
-              send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
-              shutdown(head_ptr->ctlsockfd, SHUT_WR);
-              close(head_ptr->ctlsockfd);
-              tpid = head_ptr->pid;
-              child_sig(-1);
-              kill(tpid, SIGTERM);
-              child_sig(tpid);
-            }
-            waiting = 0;
-            mclients = 0;
-            continue;
-          }
-
-          if ((waiting == 0) && (head_ptr != NULL)) {
-            log_println(6,
-                        "Fault: Something [%d] in queue, but no waiting "
-                        "clients", head_ptr->pid);
-            while (head_ptr != NULL) {
-              /* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9977", 4); */
-              send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
-              shutdown(head_ptr->ctlsockfd, SHUT_WR);
-              close(head_ptr->ctlsockfd);
-              tpid = head_ptr->pid;
-              child_sig(-1);
-              kill(tpid, SIGTERM);
-              child_sig(tpid);
-            }
-            waiting = 0;
-            mclients = 0;
-            continue;
+                "sent 45 sec update message to client %d on fd=%d, "
+                "send_msg() returned %d",
+                tmp_ptr->pid, tmp_ptr->ctlsockfd, rac);
           }
-
-          if (head_ptr != NULL) {
-            if ((time(0) - head_ptr->stime) > 70) {  // 70 => WAIT-TIME-THRESH
-              log_println(
-                  6,
-                  "Fault: Something in queue, but child %d (fd=%d) has "
-                  "exceeded wait time", head_ptr->pid, head_ptr->ctlsockfd);
-              // Should send new 9977 'test aborted' signal to client.  Using
-              // this for now
-              // rac 3/26/10
-
-              log_println(6,
-                          "pid=%d, client='%s', stime=%ld, qtime=%ld now=%ld",
-                          head_ptr->pid, head_ptr->addr, head_ptr->stime,
-                          head_ptr->qtime, time(0));
-              log_println(
-                  6,
-                  "pipe-fd=%d, running=%d, ctlsockfd=%d, client-type=%d, "
-                  "tests='%s'",
-                  head_ptr->pipe, head_ptr->running, head_ptr->ctlsockfd,
-                  head_ptr->oldclient, head_ptr->tests);
-              // boot the client
-              send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
-              shutdown(head_ptr->ctlsockfd, SHUT_WR);
-              close(head_ptr->ctlsockfd);
-              tpid = head_ptr->pid;
-              child_sig(-1);
-              kill(tpid, SIGTERM);
-              child_sig(tpid);
-              continue;
-            }
-          }
-
-          if ((multiple == 1) && (mclients > waiting)) {
+          if (i == (3 * max_clients)) {
+            rac = send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, "2", 1);
             log_println(
-                5,
-                "Multi-client mode has uncaught terminated clients mclient=%d, "
-                "waiting=%d", mclients, waiting);
-            while (mclients > waiting) {
-              child_sig(0);
-              mclients--;
-              log_println(5,
-                          "Removed terminated client from count mclients=%d",
-                          mclients);
-            }
+                6,
+                "sent 90 sec update message to client %d on fd=%d, "
+                "send_msg() returned %d",
+                tmp_ptr->pid, tmp_ptr->ctlsockfd, rac);
           }
+          tmp_ptr = tmp_ptr->next;
+        }
+      }
+      goto dispatch_client;
+    }
 
-          FD_ZERO(&rfd);
-          FD_SET(listenfd, &rfd);
-          if (waiting > 0) {  // there are clients waiting
-            sel_tv.tv_sec = 3;  // 3 seconds == WAIT_TIME_SRVR
-            sel_tv.tv_usec = 0;
-            log_println(3, "Waiting for new connection, timer running");
-sel_11: retcode = select(listenfd + 1, &rfd, NULL, NULL, &sel_tv);
-        if ((retcode == -1) && (errno == EINTR))
-          /* continue; */  // a signal caused the select() to exit, re-enter
-          // loop & check
-          goto sel_11;
-        tt = time(0);
-
-          } else {
-            // Nothing is in the queue, so wait forever until a new connection
-            // request arrives
-            log_println(3, "Timer not running, waiting for new connection");
-            mclients = 0;
-sel_12: retcode = select(listenfd + 1, &rfd, NULL, NULL, NULL);
-        if ((retcode == -1) && (errno == EINTR))
-          goto sel_12;
-        // a signal caused the select() to exit, re-enter loop & check
-          }
+    if ((waiting < 0) || (mclients < 0)) {
+      log_println(6,
+                  "Fault: Negative number of clents waiting=%d, mclients=%d, "
+                  "nuke them", waiting, mclients);
+      while (head_ptr != NULL) {
+        /* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9933", 4); */
+        // indicate server waiting in queue
+        send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
+        shutdown(head_ptr->ctlsockfd, SHUT_WR);
+        close(head_ptr->ctlsockfd);
+        tpid = head_ptr->pid;
+        child_sig(-1);
+        kill(tpid, SIGTERM);
+        child_sig(tpid);
+      }
+      waiting = 0;
+      mclients = 0;
+      continue;
+    }
 
-          if (retcode < 0) {
-            // an interrupt or signal caused the select() to exit, go back and
-            // start over
-            log_println(5, "Select exited with return code = %d", retcode);
-            continue;
-          }
+    if ((waiting == 0) && (head_ptr != NULL)) {
+      log_println(6,
+                  "Fault: Something [%d] in queue, but no waiting "
+                  "clients", head_ptr->pid);
+      while (head_ptr != NULL) {
+        /* send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9977", 4); */
+        send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
+        shutdown(head_ptr->ctlsockfd, SHUT_WR);
+        close(head_ptr->ctlsockfd);
+        tpid = head_ptr->pid;
+        child_sig(-1);
+        kill(tpid, SIGTERM);
+        child_sig(tpid);
+      }
+      waiting = 0;
+      mclients = 0;
+      continue;
+    }
 
-          if (retcode == 0) {  // select exited due to timer expiration
-            log_println(3, "Timer expired while waiting for a new connection");
-            /* if ((waiting > 0) && (testing == 0)) */
-            if (multiple == 0) {
-              if ((waiting > 0) && (testing == 0))
-                goto ChldRdy;
-              continue;
-            } else {
-              if (waiting > 0)
-                goto ChldRdy;
-              continue;
-            }
-          } else {
-            log_println(
-                3,
-                "New connection received, waiting for accept() to complete");
-            if ((waiting > 0) && (testing == 0))  // no clients waiting, no test
-                                                  // in progress
-              goto ChldRdy;
-            /* } */
-            clilen = sizeof(cli_addr);
-            memset(&cli_addr, 0, clilen);
-            log_println(6, "Select() found %d clients ready, highest fd=%d",
-                        retcode, listenfd);
-            if (retcode > 1) {
-              for (i = 3; i <= listenfd; i++) {
-                if (FD_ISSET(i, &rfd)) {
-                  listenfd = i;
-                  break;
-                }
-              }
-            }
-            for (i = 0; i < RETRY_COUNT; i++) {
-              ctlsockfd = 0;
-              ctlsockfd = accept(listenfd, (struct sockaddr *) &cli_addr,
-                                 &clilen);
-              // socket interrupted, retry
-              if ((ctlsockfd == -1) && (errno == EINTR))
-                continue;  // sig child
-              size_t tmpstrlen = sizeof(tmpstr);
-              memset(tmpstr, 0, tmpstrlen);
-              // get addr details based on socket info available
-              I2Addr tmp_addr = I2AddrBySockFD(get_errhandle(), ctlsockfd,
-                                               False);
-              I2AddrNodeName(tmp_addr, tmpstr, &tmpstrlen);
-              /* I2AddrFree(tmp_addr); */
-              log_println(4,
-                          "New connection received from 0x%x [%s] sockfd=%d.",
-                          tmp_addr, tmpstr, ctlsockfd);
+    if (head_ptr != NULL) {
+      if ((time(0) - head_ptr->stime) > 70) {  // 70 => WAIT-TIME-THRESH
+        log_println(6,
+                    "Fault: Something in queue, but child %d (fd=%d) has "
+                    "exceeded wait time", head_ptr->pid, head_ptr->ctlsockfd);
+        // Should send new 9977 'test aborted' signal to client.  Using
+        // this for now
+        // rac 3/26/10
+
+        log_println(6,
+                    "pid=%d, client='%s', stime=%ld, qtime=%ld now=%ld",
+                    head_ptr->pid, head_ptr->addr, head_ptr->stime,
+                    head_ptr->qtime, time(0));
+        log_println(6,
+                    "pipe-fd=%d, running=%d, ctlsockfd=%d, client-type=%d, "
+                    "tests='%s'",
+                    head_ptr->pipe, head_ptr->running, head_ptr->ctlsockfd,
+                    head_ptr->oldclient, head_ptr->tests);
+        // boot the client
+        send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "9988", 4);
+        shutdown(head_ptr->ctlsockfd, SHUT_WR);
+        close(head_ptr->ctlsockfd);
+        tpid = head_ptr->pid;
+        child_sig(-1);
+        kill(tpid, SIGTERM);
+        child_sig(tpid);
+        continue;
+      }
+    }
 
-              break;
-            }
+    if ((multiple == 1) && (mclients > waiting)) {
+      log_println(5, "Multi-client mode has uncaught terminated clients "
+                  "mclient=%d, waiting=%d", mclients, waiting);
+      while (mclients > waiting) {
+        child_sig(0);
+        mclients--;
+        log_println(5, "Removed terminated client from count mclients=%d",
+                    mclients);
+      }
+    }
 
-            // verify that accept really worked and don't process connections
-            // that've failed
-            // RAC 2/11/10
-            if (ctlsockfd <= 0) {
-              log_println(4,
-                          "New connection request failed sockfd=%d reason-%d.",
-                          ctlsockfd, errno);
-              continue;
-            } else {  // accept worked, log protocol validation log to indicate
-                      // that client tried connecting
-              procstatusenum = PROCESS_STARTED;
-              proctypeenum = CONNECT_TYPE;
-              protolog_procstatus(getpid(), getCurrentTest(), proctypeenum,
-                                  procstatusenum, ctlsockfd);
-            }
+    FD_ZERO(&rfd);
+    FD_SET(listenfd, &rfd);
+    if (waiting > 0) {  // there are clients waiting
+      sel_tv.tv_sec = 3;  // 3 seconds == WAIT_TIME_SRVR
+      sel_tv.tv_usec = 0;
+      log_println(3, "Waiting for new connection, timer running");
+ sel_11:
+      retcode = select(listenfd + 1, &rfd, NULL, NULL, &sel_tv);
+      if ((retcode == -1) && (errno == EINTR))
+        /* continue; */  // a signal caused the select() to exit, re-enter
+        // loop & check
+        goto sel_11;
+      tt = time(0);
+    } else {
+      // Nothing is in the queue, so wait forever until a new connection
+      // request arrives
+      log_println(3, "Timer not running, waiting for new connection");
+      mclients = 0;
+ sel_12:
+      retcode = select(listenfd + 1, &rfd, NULL, NULL, NULL);
+      if ((retcode == -1) && (errno == EINTR))
+        goto sel_12;
+      // a signal caused the select() to exit, re-enter loop & check
+    }
 
-            // the specially crafted data that kicks off the old clients
-            for (i = 0; i < RETRY_COUNT; i++) {
-              retcode = write(ctlsockfd, "123456 654321", 13);
-              if ((retcode == -1) && (errno == EINTR))  // interrupted, retry
-                continue;
-              if (retcode == 13)  // 13 bytes correctly written, exit
-                break;
-              if (retcode == -1) {  // socket error hindering further retries
-                log_println(1,
-                            "Initial contact with client failed errno=%d",
-                            errno);
-                close(chld_pipe[0]);
-                close(chld_pipe[1]);
-                shutdown(ctlsockfd, SHUT_WR);
-                close(ctlsockfd);
-                goto mainloop;
-              }
+    if (retcode < 0) {
+      // an interrupt or signal caused the select() to exit, go back and
+      // start over
+      log_println(5, "Select exited with return code = %d", retcode);
+      continue;
+    }
 
-              log_println(6, "xxx, calling initialize_tests()");
-              t_opts = initialize_tests(ctlsockfd, &testopt, test_suite,
-                                        sizeof(test_suite));
-
-              if (t_opts < 1) {
-                log_println(
-                    3,
-                    "Invalid test suite string '%s' received, terminate child",
-                    test_suite);
-                close(chld_pipe[0]);
-                close(chld_pipe[1]);
-                shutdown(ctlsockfd, SHUT_WR);
-                close(ctlsockfd);
-
-                /* todo: handle other error contitions */
-              }
-            }
-            new_child = (struct ndtchild *) malloc(sizeof(struct ndtchild));
-            memset(new_child, 0, sizeof(struct ndtchild));
-            tt = time(0);
-            name = tmpstr;
-
-            rmt_host = tmpstr;
-
-            // At this point we have received a connection from a client,
-            // meaning that a test is being requested.  At this point we should
-            // apply any policy or AAA functions to the incoming connection.
-            // If we don't like the client, we can refuse the connection and
-            // loop back to the begining.  There would need to be some
-            // additional logic installed if this AAA test relied on more than
-            // the client's IP address.  The client would also require
-            // modification to allow more credentials to be created/passed
-            // between the user and this application.
+    if (retcode == 0) {  // select exited due to timer expiration
+      log_println(3, "Timer expired while waiting for a new connection");
+      /* if ((waiting > 0) && (testing == 0)) */
+      if (multiple == 0) {
+        if ((waiting > 0) && (testing == 0))
+          goto ChldRdy;
+        continue;
+      } else {
+        if (waiting > 0)
+          goto ChldRdy;
+        continue;
+      }
+    } else {
+      log_println(3,
+                  "New connection received, waiting for accept() to complete");
+      if ((waiting > 0) && (testing == 0))  // no clients waiting, no test
+                                            // in progress
+        goto ChldRdy;
+      /* } */
+      clilen = sizeof(cli_addr);
+      memset(&cli_addr, 0, clilen);
+      log_println(6, "Select() found %d clients ready, highest fd=%d",
+                  retcode, listenfd);
+      if (retcode > 1) {
+        for (i = 3; i <= listenfd; i++) {
+          if (FD_ISSET(i, &rfd)) {
+            listenfd = i;
+            break;
           }
+        }
+      }
+      for (i = 0; i < RETRY_COUNT; i++) {
+        ctlsockfd = 0;
+        ctlsockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilen);
+        // socket interrupted, retry
+        if ((ctlsockfd == -1) && (errno == EINTR))
+          continue;  // sig child
+        size_t tmpstrlen = sizeof(tmpstr);
+        memset(tmpstr, 0, tmpstrlen);
+        // get addr details based on socket info available
+        I2Addr tmp_addr = I2AddrBySockFD(get_errhandle(), ctlsockfd, False);
+        I2AddrNodeName(tmp_addr, tmpstr, &tmpstrlen);
+        /* I2AddrFree(tmp_addr); */
+        log_println(4,
+                    "New connection received from 0x%x [%s] sockfd=%d.",
+                    tmp_addr, tmpstr, ctlsockfd);
 
-          if (pipe(chld_pipe) == -1)
-            log_println(6, "pipe() failed errno=%d", errno);
-          chld_pid = fork();
+        break;
+      }
 
-          switch (chld_pid) {
-            case -1: /* an error occured, log it and quit */
-              log_println(0, "fork() failed, errno = %d", errno);
-              /* todo: handle error and continue */
-              break;
-            default:  // this is the parent process, handle scheduling and
-                      // queuing of multiple incoming clients
-
-              log_println(5, "Parent process spawned child = %d", chld_pid);
-              log_println(5, "Parent thinks pipe() returned fd0=%d, fd1=%d",
-                          chld_pipe[0], chld_pipe[1]);
-
-              close(chld_pipe[0]);
-
-              // Check to see if we have more than max_clients waiting in the
-              // queue
-              //  If so, tell them to go away.
-              //  changed for M-Lab deployment  1/28/09  RAC
-
-              if (((multiple == 0) && (waiting >= (max_clients - 1))) ||
-                  ((multiple == 1) && (waiting >= ((4 * max_clients) - 1)))) {
-                log_println(
-                    0,
-                    "Too many clients/mclients (%d) waiting to be served, "
-                    "Please try again later.", chld_pid);
-                // 9988 = server_BUSY_OR_ERROR
-                snprintf(tmpstr, sizeof(tmpstr), "9988");
-                send_msg(ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
-                close(chld_pipe[0]);
-                close(chld_pipe[1]);
-                shutdown(ctlsockfd, SHUT_WR);
-                close(ctlsockfd);
-                kill(chld_pid, SIGTERM);
-                if (new_child != NULL) {
-                  log_println(6, "Too many clients freeing child=0x%x",
-                              new_child);
-                  free(new_child);
-                }
-                continue;
-              }
+      // verify that accept really worked and don't process connections
+      // that've failed
+      // RAC 2/11/10
+      if (ctlsockfd <= 0) {
+        log_println(4,
+                    "New connection request failed sockfd=%d reason-%d.",
+                    ctlsockfd, errno);
+        continue;
+      } else {  // accept worked, log protocol validation log to indicate
+                // that client tried connecting
+        procstatusenum = PROCESS_STARTED;
+        proctypeenum = CONNECT_TYPE;
+        protolog_procstatus(getpid(), getCurrentTest(), proctypeenum,
+                            procstatusenum, ctlsockfd);
+      }
 
-              t_opts = initialize_tests(ctlsockfd, &testopt, test_suite,
-                                        sizeof(test_suite));
-              if (t_opts < 1) {  // some error in initialization routines
-                log_println(
-                    3,
-                    "Invalid test suite string '%s' received, terminate child",
-                    test_suite);
-                close(chld_pipe[0]);
-                close(chld_pipe[1]);
-                shutdown(ctlsockfd, SHUT_WR);
-                close(ctlsockfd);
-                kill(chld_pid, SIGTERM);
-                if (new_child != NULL) {
-                  log_println(6, "invalid test suite, freeing new_child=0x%x",
-                              new_child);
-                  free(new_child);
-                }
-                continue;
-              }
-              // socket interrupt, retry
-              while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
-                log_println(6, "Waiting for ndtq semaphore to free - 1");
-                continue;
-              }
-              log_println(6, "creating new child - semaphore locked");
-              /*sigprocmask(SIG_BLOCK, &newmask, &oldmask); */
-              new_child->pid = chld_pid;
-              /* strncpy(new_child->addr, rmt_host, strlen(rmt_host));
-                 strncpy(new_child->host, name, strlen(name));*/
-              strlcpy(new_child->addr, rmt_host, sizeof(new_child->addr));
-              strlcpy(new_child->host, name, sizeof(new_child->host));
-
-              // compute start time based in the number of waiting clients
-              // set other properties on this child process
-              if (multiple == 0)
-                new_child->stime = tt + (waiting * 45);
-              else
-                new_child->stime = tt + ((waiting / max_clients) * 45);
-              new_child->qtime = tt;
-              new_child->pipe = chld_pipe[1];
-              new_child->running = 0;
-              new_child->ctlsockfd = ctlsockfd;
-              if (t_opts & TEST_STATUS
-                 )
-                new_child->oldclient = 1;
-              else
-                new_child->oldclient = 0;
-              memset(new_child->tests, 0, sizeof(test_suite));
-              memcpy(new_child->tests, test_suite, strlen(test_suite));
-              new_child->next = NULL;
-              /* sigprocmask(SIG_SETMASK, &oldmask, NULL); */
-              sem_post(&ndtq);
-              log_println(6, "Free'd ndtq semaphore lock - 1");
-              if (multiple == 1)
-                mwaiting++;
-              mchild = new_child;
+      // the specially crafted data that kicks off the old clients
+      for (i = 0; i < RETRY_COUNT; i++) {
+        retcode = write(ctlsockfd, "123456 654321", 13);
+        if ((retcode == -1) && (errno == EINTR))  // interrupted, retry
+          continue;
+        if (retcode == 13)  // 13 bytes correctly written, exit
+          break;
+        if (retcode == -1) {  // socket error hindering further retries
+          log_println(1, "Initial contact with client failed errno=%d", errno);
+          close(chld_pipe[0]);
+          close(chld_pipe[1]);
+          shutdown(ctlsockfd, SHUT_WR);
+          close(ctlsockfd);
+          goto mainloop;
+        }
 
-              log_println(
-                  3,
-                  "initialize_tests returned old/new client = %d, "
-                  "test_suite = %s", new_child->oldclient, new_child->tests);
-
-              close(chld_pipe[0]);
-
-              if ((testing == 1) && (queue == 0)) {
-                log_println(
-                    3,
-                    "queuing disabled and testing in progress, tell client no");
-                /* send_msg(new_child->ctlsockfd, SRV_QUEUE, "9944", 4); */
-                send_msg(new_child->ctlsockfd, SRV_QUEUE, "9988", 4);
-                close(chld_pipe[1]);
-                shutdown(new_child->ctlsockfd, SHUT_WR);
-                close(new_child->ctlsockfd);
-                log_println(6, "no queuing, free new_child=0x%x", new_child);
-                free(new_child);
-                continue;
-              }
+        log_println(6, "xxx, calling initialize_tests()");
+        t_opts = initialize_tests(ctlsockfd, &testopt, test_suite,
+                                  sizeof(test_suite));
+
+        if (t_opts < 1) {
+          log_println(3, "Invalid test suite string '%s' received, terminate ",
+                      "child", test_suite);
+          close(chld_pipe[0]);
+          close(chld_pipe[1]);
+          shutdown(ctlsockfd, SHUT_WR);
+          close(ctlsockfd);
+          /* todo: handle other error contitions */
+        }
+      }
+      new_child = (struct ndtchild *) malloc(sizeof(struct ndtchild));
+      memset(new_child, 0, sizeof(struct ndtchild));
+      tt = time(0);
+      name = tmpstr;
+
+      rmt_host = tmpstr;
+
+      // At this point we have received a connection from a client,
+      // meaning that a test is being requested.  At this point we should
+      // apply any policy or AAA functions to the incoming connection.
+      // If we don't like the client, we can refuse the connection and
+      // loop back to the begining.  There would need to be some
+      // additional logic installed if this AAA test relied on more than
+      // the client's IP address.  The client would also require
+      // modification to allow more credentials to be created/passed
+      // between the user and this application.
+    }
 
-              waiting++;  // new client has arrived and is queue-able.
-                          // increment waiting
-              log_println(5, "Incrementing waiting variable now = %d", waiting);
-              if (head_ptr == NULL) {
-                head_ptr = new_child;
-              } else {
-                log_println(
-                    4,
-                    "New request has arrived, adding request to queue list");
-                while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
-                  log_println(6, "Waiting for ndtq semaphore to free, adding "
-                              "new client 2");
-                  continue;
-                }
-                log_println(6, "Adding new client to fifo queue - "
-                            "semaphore locked");
-                tmp_ptr = head_ptr;
-                while (tmp_ptr->next != NULL)
-                  tmp_ptr = tmp_ptr->next;
-                tmp_ptr->next = new_child;
-                sem_post(&ndtq);
-                log_println(6, "Free'd ndtq semaphore lock - 2");
-
-                if (get_debuglvl() > 3) {
-                  log_println(4, "Walking scheduling queue");
-                  tmp_ptr = head_ptr;
-                  while (tmp_ptr != NULL) {
-                    log_println(4, "\tChild %d, host: %s [%s], next=0x%x",
-                                tmp_ptr->pid, tmp_ptr->host, tmp_ptr->addr,
-                                (u_int64_t) tmp_ptr->next);
-                    if (tmp_ptr->next == NULL)
-                      break;
-                    tmp_ptr = tmp_ptr->next;
-                  }
-                }
-              }
+    if (pipe(chld_pipe) == -1)
+      log_println(6, "pipe() failed errno=%d", errno);
+    chld_pid = fork();
 
-              // At this point send a message to the client via the ctlsockfd
-              //  saying that N clients are waiting in the queue & testing will
-              //   begin within Nx60 seconds.  Only if (waiting > 0)
-              //    Clients who leave will be handled in the run_test routine.
-
-              if ((multiple == 0) && (waiting > 1)) {
-                log_println(
-                    3,
-                    "%d clients waiting, telling client (%d) testing will "
-                    "begin within %d minutes", (waiting - 1), tmp_ptr->pid,
-                    (waiting-1));
-                snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-1));
-                send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
-                continue;
-              }
+    switch (chld_pid) {
+      case -1: /* an error occured, log it and quit */
+        log_println(0, "fork() failed, errno = %d", errno);
+        /* todo: handle error and continue */
+        break;
+      default:  // this is the parent process, handle scheduling and
+                // queuing of multiple incoming clients
+
+        log_println(5, "Parent process spawned child = %d", chld_pid);
+        log_println(5, "Parent thinks pipe() returned fd0=%d, fd1=%d",
+                    chld_pipe[0], chld_pipe[1]);
+
+        close(chld_pipe[0]);
+
+        // Check to see if we have more than max_clients waiting in the
+        // queue
+        //  If so, tell them to go away.
+        //  changed for M-Lab deployment  1/28/09  RAC
+
+        if (((multiple == 0) && (waiting >= (max_clients - 1))) ||
+            ((multiple == 1) && (waiting >= ((4 * max_clients) - 1)))) {
+          log_println(0, "Too many clients/mclients (%d) waiting to be served, "
+                      "Please try again later.", chld_pid);
+          // 9988 = server_BUSY_OR_ERROR
+          snprintf(tmpstr, sizeof(tmpstr), "9988");
+          send_msg(ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
+          close(chld_pipe[0]);
+          close(chld_pipe[1]);
+          shutdown(ctlsockfd, SHUT_WR);
+          close(ctlsockfd);
+          kill(chld_pid, SIGTERM);
+          if (new_child != NULL) {
+            log_println(6, "Too many clients freeing child=0x%x", new_child);
+            free(new_child);
+          }
+          continue;
+        }
 
-              if ((multiple == 1) && (waiting >= max_clients)) {
-                int xx = waiting/max_clients;
-                log_println(3, "%d mclients waiting, tell client (%d) test "
-                            "will begin within %d minutes",
-                            (waiting-max_clients), mchild->pid, xx);
-                snprintf(tmpstr, sizeof(tmpstr), "%d", xx);
-                send_msg(mchild->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
-                continue;
-              }
+        t_opts = initialize_tests(ctlsockfd, &testopt, test_suite,
+                                  sizeof(test_suite));
+        if (t_opts < 1) {  // some error in initialization routines
+          log_println(3, "Invalid test suite string '%s' received, terminate ",
+                      "child", test_suite);
+          close(chld_pipe[0]);
+          close(chld_pipe[1]);
+          shutdown(ctlsockfd, SHUT_WR);
+          close(ctlsockfd);
+          kill(chld_pid, SIGTERM);
+          if (new_child != NULL) {
+            log_println(6, "invalid test suite, freeing new_child=0x%x",
+                        new_child);
+            free(new_child);
+          }
+          continue;
+        }
+        // socket interrupt, retry
+        while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+          log_println(6, "Waiting for ndtq semaphore to free - 1");
+          continue;
+        }
+        log_println(6, "creating new child - semaphore locked");
+        /*sigprocmask(SIG_BLOCK, &newmask, &oldmask); */
+        new_child->pid = chld_pid;
+        /* strncpy(new_child->addr, rmt_host, strlen(rmt_host));
+           strncpy(new_child->host, name, strlen(name));*/
+        strlcpy(new_child->addr, rmt_host, sizeof(new_child->addr));
+        strlcpy(new_child->host, name, sizeof(new_child->host));
+
+        // compute start time based in the number of waiting clients
+        // set other properties on this child process
+        if (multiple == 0)
+          new_child->stime = tt + (waiting * 45);
+        else
+          new_child->stime = tt + ((waiting / max_clients) * 45);
+        new_child->qtime = tt;
+        new_child->pipe = chld_pipe[1];
+        new_child->running = 0;
+        new_child->ctlsockfd = ctlsockfd;
+        if (t_opts & TEST_STATUS)
+          new_child->oldclient = 1;
+        else
+          new_child->oldclient = 0;
+        memset(new_child->tests, 0, sizeof(test_suite));
+        memcpy(new_child->tests, test_suite, strlen(test_suite));
+        new_child->next = NULL;
+        /* sigprocmask(SIG_SETMASK, &oldmask, NULL); */
+        sem_post(&ndtq);
+        log_println(6, "Free'd ndtq semaphore lock - 1");
+        if (multiple == 1)
+          mwaiting++;
+        mchild = new_child;
+
+        log_println(3, "initialize_tests returned old/new client = %d, "
+                    "test_suite = %s", new_child->oldclient, new_child->tests);
+
+        close(chld_pipe[0]);
+
+        if ((testing == 1) && (queue == 0)) {
+          log_println(3, "queuing disabled and testing in progress, tell "
+                      "client no");
+          /* send_msg(new_child->ctlsockfd, SRV_QUEUE, "9944", 4); */
+          send_msg(new_child->ctlsockfd, SRV_QUEUE, "9988", 4);
+          close(chld_pipe[1]);
+          shutdown(new_child->ctlsockfd, SHUT_WR);
+          close(new_child->ctlsockfd);
+          log_println(6, "no queuing, free new_child=0x%x", new_child);
+          free(new_child);
+          continue;
+        }
 
-              /*
-               *       if ((multiple == 0) && (testing == 1)) 
-               *         continue;
-               */
+        waiting++;  // new client has arrived and is queue-able.
+                    // increment waiting
+        log_println(5, "Incrementing waiting variable now = %d", waiting);
+        if (head_ptr == NULL) {
+          head_ptr = new_child;
+        } else {
+          log_println(4,
+                      "New request has arrived, adding request to queue list");
+          while ((retcode = sem_wait(&ndtq)) == -1 && errno == EINTR) {
+            log_println(6, "Waiting for ndtq semaphore to free, adding "
+                        "new client 2");
+            continue;
+          }
+          log_println(6, "Adding new client to fifo queue - semaphore locked");
+          tmp_ptr = head_ptr;
+          while (tmp_ptr->next != NULL)
+            tmp_ptr = tmp_ptr->next;
+          tmp_ptr->next = new_child;
+          sem_post(&ndtq);
+          log_println(6, "Free'd ndtq semaphore lock - 2");
+
+          if (get_debuglvl() > 3) {
+            log_println(4, "Walking scheduling queue");
+            tmp_ptr = head_ptr;
+            while (tmp_ptr != NULL) {
+              log_println(4, "\tChild %d, host: %s [%s], next=0x%x",
+                          tmp_ptr->pid, tmp_ptr->host, tmp_ptr->addr,
+                          (u_int64_t) tmp_ptr->next);
+              if (tmp_ptr->next == NULL)
+                break;
+              tmp_ptr = tmp_ptr->next;
+            }
+          }
+        }
 
-              log_println(3, "Line just before ChldRdy: label, did't get here "
-                          "via the goto statement!");
- ChldRdy:
-              log_println(3, "___-------______  client process is ready for "
-                          "testing!");
+        // At this point send a message to the client via the ctlsockfd
+        //  saying that N clients are waiting in the queue & testing will
+        //   begin within Nx60 seconds.  Only if (waiting > 0)
+        //    Clients who leave will be handled in the run_test routine.
+
+        if ((multiple == 0) && (waiting > 1)) {
+          log_println(3, "%d clients waiting, telling client (%d) testing will "
+                      "begin within %d minutes", (waiting - 1), tmp_ptr->pid,
+                      (waiting-1));
+          snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-1));
+          send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
+          continue;
+        }
 
-              // There are clients waiting in the queue, but if running in
-              // multi-client mode and there are already the max number of
-              // mclients being served, then just continue
-              // 9/2/09 RAC
+        if ((multiple == 1) && (waiting >= max_clients)) {
+          int xx = waiting/max_clients;
+          log_println(3, "%d mclients waiting, tell client (%d) test "
+                      "will begin within %d minutes",
+                      (waiting-max_clients), mchild->pid, xx);
+          snprintf(tmpstr, sizeof(tmpstr), "%d", xx);
+          send_msg(mchild->ctlsockfd, SRV_QUEUE, tmpstr, strlen(tmpstr));
+          continue;
+        }
 
-              if ((multiple ==1) && (mclients >= max_clients))
-                continue;
+        /*
+         *       if ((multiple == 0) && (testing == 1))
+         *         continue;
+         */
 
-              testing = 1;
-
-              // update all the clients so they have some idea that progress
-              // is occurring
-              if ((multiple == 0) && (waiting > 1)) {
-                j = waiting - 1;
-                tmp_ptr = head_ptr->next;
-                if (tmp_ptr == NULL)  // no more clients waiting after the
-                                      // current one
-                  waiting = 1;
-                while (tmp_ptr != NULL) {
-                  log_println(3, "%d clients waiting, updating client %d "
-                              "testing will begin within %d minutes",
-                              (waiting-1), tmp_ptr->pid, (waiting-j));
-
-                  snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-j));
-                  send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
-                           strlen(tmpstr));
-                  tmp_ptr = tmp_ptr->next;
-                  j--;
-                }
-                // more then 5 clients waiting, killing zombies
-                if ((waiting > 5) && (zombie_check == 0)) {
-                  zombie_check = -1;
-                  log_println(4, "More than 5 clients in the queue, "
-                              "remove zombies");
-                  if (pthread_create(&zombieThreadId, NULL, zombieWorker,
-                                     (void *)head_ptr)) {
-                    log_println(0, "Cannot create thread to kill off zombie "
-                                "clients!");
-                    zombie_check = 0;
-                  }
-                  if (zombie_check > 0) {
-                    waiting -= zombie_check;
-                    zombie_check = 0;
-                  }
-                }
-              }
+        log_println(3, "Line just before ChldRdy: label, did't get here "
+                    "via the goto statement!");
+ ChldRdy:
+        log_println(3, "___-------______  client process is ready for "
+                    "testing!");
+
+        // There are clients waiting in the queue, but if running in
+        // multi-client mode and there are already the max number of
+        // mclients being served, then just continue
+        // 9/2/09 RAC
+
+        if ((multiple ==1) && (mclients >= max_clients))
+          continue;
+
+        testing = 1;
+
+        // update all the clients so they have some idea that progress
+        // is occurring
+        if ((multiple == 0) && (waiting > 1)) {
+          j = waiting - 1;
+          tmp_ptr = head_ptr->next;
+          if (tmp_ptr == NULL)  // no more clients waiting after the
+                                // current one
+            waiting = 1;
+          while (tmp_ptr != NULL) {
+            log_println(3, "%d clients waiting, updating client %d "
+                        "testing will begin within %d minutes",
+                        (waiting-1), tmp_ptr->pid, (waiting-j));
+
+            snprintf(tmpstr, sizeof(tmpstr), "%d", (waiting-j));
+            send_msg(tmp_ptr->ctlsockfd, SRV_QUEUE, tmpstr,
+                     strlen(tmpstr));
+            tmp_ptr = tmp_ptr->next;
+            j--;
+          }
+          // more then 5 clients waiting, killing zombies
+          if ((waiting > 5) && (zombie_check == 0)) {
+            zombie_check = -1;
+            log_println(4, "More than 5 clients in the queue, "
+                        "remove zombies");
+            if (pthread_create(&zombieThreadId, NULL, zombieWorker,
+                               (void *)head_ptr)) {
+              log_println(0, "Cannot create thread to kill off zombie "
+                          "clients!");
+              zombie_check = 0;
+            }
+            if (zombie_check > 0) {
+              waiting -= zombie_check;
+              zombie_check = 0;
+            }
+          }
+        }
 
-              /* multi_client: */
-              if ((multiple == 1) && (mclients < max_clients)) {
-                if (mwaiting == 0)
-                  continue;
-                mwaiting--;
-                log_println(3, "Multi-client mode operation, dispatch a new "
-                            "client pid=%d.", mchild->pid);
-              } else {
-                log_println(3, "Telling client %d testing will begin now",
-                            head_ptr->pid);
-              }
+        /* multi_client: */
+        if ((multiple == 1) && (mclients < max_clients)) {
+          if (mwaiting == 0)
+            continue;
+          mwaiting--;
+          log_println(3, "Multi-client mode operation, dispatch a new "
+                      "client pid=%d.", mchild->pid);
+        } else {
+          log_println(3, "Telling client %d testing will begin now",
+                      head_ptr->pid);
+        }
 
-              // at this point we have successfully set everything up and are
-              // ready to start testing.  The write() on the control socket
-              // tells the client that the applet should drop out of the wait
-              // loop and get ready to begin testing.  The write() on the pipe
-              // tells the child process it's at the head of the queue, or it's
-              // in multi-client mode, and its OK for this client process to
-              // wake up and begin testing.
-              //
-              //  This is the point in time where we can/should contact any meta
-              //  scheduler to verify that it is OK to really start a test.  If
-              //  we are sharing the server host with other applications, and we
-              //  want unfettered access to the link, now is the time to make
-              //  this request.
+        // at this point we have successfully set everything up and are
+        // ready to start testing.  The write() on the control socket
+        // tells the client that the applet should drop out of the wait
+        // loop and get ready to begin testing.  The write() on the pipe
+        // tells the child process it's at the head of the queue, or it's
+        // in multi-client mode, and its OK for this client process to
+        // wake up and begin testing.
+        //
+        //  This is the point in time where we can/should contact any meta
+        //  scheduler to verify that it is OK to really start a test.  If
+        //  we are sharing the server host with other applications, and we
+        //  want unfettered access to the link, now is the time to make
+        //  this request.
 
  dispatch_client:
-              memset(tmpstr, 0, sizeof(tmpstr));
-              if (multiple == 1) {
-                if (mchild == NULL)
-                  mchild = head_ptr;
-                if (mchild->running == 1)
-                  continue;
-                log_println(3, "New mclient '%d'(%d) asking for service",
-                            mclients, mchild->pid);
-                mchild->stime = time(0);
-                mchild->running = 1;
-                mclients++;
-                snprintf(tmpstr, sizeof(tmpstr), "go %d %s", t_opts,
-                         mchild->tests);
-                log_println(5, "sending 'GO' signal to client msg='%s'",
-                            tmpstr);
-                // test session starts now
-                send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1);
-                for (i = 0; i < 5; i++) {
-                  retcode = write(mchild->pipe, tmpstr, strlen(tmpstr));
-                  log_println(6, "write(%d) returned %d, errno=%d",
-                              mchild->pid, retcode, errno);
-                  if ((retcode == -1) && (errno == EINTR))
-                    continue;
-                  if (retcode == strlen(tmpstr))
-                    break;
-                  log_println(6, "Failed to write 'GO' message to client %d, "
-                              "reason=%d, errno=%d", mchild->pid, retcode,
-                              errno);
-                  /* TODO: handle other error conditions */
-                  if (retcode == -1) {
-                    log_println(1, "Dispatch multi-client failed because '%s'",
-                                strerror(errno));
-                    shutdown(mchild->ctlsockfd, SHUT_WR);
-                    close(mchild->ctlsockfd);
-                    kill(chld_pid, SIGTERM);
-                    goto mainloop;
-                  }
-                }
-                close(mchild->pipe);
-                close(mchild->ctlsockfd);
-              } else {  // multiple client loop complete
-                head_ptr->stime = time(0);
-                head_ptr->running = 1;
-                snprintf(tmpstr, sizeof(tmpstr), "go %d %s", t_opts,
-                         head_ptr->tests);
-                log_println(5, "sending 'GO' signal to client msg='%s'",
-                            tmpstr);
-                send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1);
-                for (i = 0; i < 5; i++) {
-                  retcode = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
-                  if ((retcode == -1) && (errno == EINTR))
-                    continue;
-                  if (retcode == strlen(tmpstr))
-                    break;
-                  /* TODO: handle other error conditions */
-                  if (retcode == -1) {
-                    log_println(1, "Dispatch multi-client failed because '%s'",
-                                strerror(errno));
-                    shutdown(head_ptr->ctlsockfd, SHUT_WR);
-                    close(head_ptr->ctlsockfd);
-                    kill(chld_pid, SIGTERM);
-                    goto mainloop;
-                  }
-                }
-                close(head_ptr->pipe);
-                close(head_ptr->ctlsockfd);
-              }
+        memset(tmpstr, 0, sizeof(tmpstr));
+        if (multiple == 1) {
+          if (mchild == NULL)
+            mchild = head_ptr;
+          if (mchild->running == 1)
+            continue;
+          log_println(3, "New mclient '%d'(%d) asking for service",
+                      mclients, mchild->pid);
+          mchild->stime = time(0);
+          mchild->running = 1;
+          mclients++;
+          snprintf(tmpstr, sizeof(tmpstr), "go %d %s", t_opts, mchild->tests);
+          log_println(5, "sending 'GO' signal to client msg='%s'", tmpstr);
+          // test session starts now
+          send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1);
+          for (i = 0; i < 5; i++) {
+            retcode = write(mchild->pipe, tmpstr, strlen(tmpstr));
+            log_println(6, "write(%d) returned %d, errno=%d",
+                        mchild->pid, retcode, errno);
+            if ((retcode == -1) && (errno == EINTR))
               continue;
+            if (retcode == strlen(tmpstr))
               break;
-            case 0:  // this is the child process, it handles the testing
-                     // function
-              log_println(4, "Child thinks pipe() returned fd0=%d, fd1=%d for "
-                          "pid=%d", chld_pipe[0], chld_pipe[1], chld_pid);
-              close(listenfd);
-              close(chld_pipe[1]);
-              if ((agent = web100_attach(WEB100_AGENT_TYPE_LOCAL,
-                                         NULL)) == NULL) {
-                web100_perror("web100_attach");
-                return 1;
-              }
+            log_println(6, "Failed to write 'GO' message to client %d, "
+                        "reason=%d, errno=%d", mchild->pid, retcode,
+                        errno);
+            /* TODO: handle other error conditions */
+            if (retcode == -1) {
+              log_println(1, "Dispatch multi-client failed because '%s'",
+                          strerror(errno));
+              shutdown(mchild->ctlsockfd, SHUT_WR);
+              close(mchild->ctlsockfd);
+              kill(chld_pid, SIGTERM);
+              goto mainloop;
+            }
+          }
+          close(mchild->pipe);
+          close(mchild->ctlsockfd);
+        } else {  // multiple client loop complete
+          head_ptr->stime = time(0);
+          head_ptr->running = 1;
+          snprintf(tmpstr, sizeof(tmpstr), "go %d %s", t_opts, head_ptr->tests);
+          log_println(5, "sending 'GO' signal to client msg='%s'", tmpstr);
+          send_msg(head_ptr->ctlsockfd, SRV_QUEUE, "0", 1);
+          for (i = 0; i < 5; i++) {
+            retcode = write(head_ptr->pipe, tmpstr, strlen(tmpstr));
+            if ((retcode == -1) && (errno == EINTR))
+              continue;
+            if (retcode == strlen(tmpstr))
+              break;
+            /* TODO: handle other error conditions */
+            if (retcode == -1) {
+              log_println(1, "Dispatch multi-client failed because '%s'",
+                          strerror(errno));
+              shutdown(head_ptr->ctlsockfd, SHUT_WR);
+              close(head_ptr->ctlsockfd);
+              kill(chld_pid, SIGTERM);
+              goto mainloop;
+            }
+          }
+          close(head_ptr->pipe);
+          close(head_ptr->ctlsockfd);
+        }
+        continue;
+        break;
+      case 0:  // this is the child process, it handles the testing
+               // function
+        log_println(4, "Child thinks pipe() returned fd0=%d, fd1=%d for pid=%d",
+                    chld_pipe[0], chld_pipe[1], chld_pid);
+        close(listenfd);
+        close(chld_pipe[1]);
+        if ((agent = web100_attach(WEB100_AGENT_TYPE_LOCAL, NULL)) == NULL) {
+          web100_perror("web100_attach");
+          return 1;
+        }
 
-              // This is the child process from the above fork().  The parent
-              //  is in control, and will send this child a signal when it gets
-              //  to the head of the testing queue.  Post a read() and simply
-              //  wait for the parent to let us know it's time to move on.
-              //  Rich Carlson 3/11/04
-              for (;;) {
-                memset(buff, 0, sizeof(buff));
-
-                // the read() could return if an interrupt was caught.  This
-                // condition should be checked for and the read() restarted if
-                // necessary
-                // RAC 3/18/10
-                //
-                retcode = read(chld_pipe[0], buff, 32);
-                log_println(6, "Child %d received '%s' from parent", getpid(),
-                            buff);
-                if ((retcode == -1) && (errno == EINTR))
-                  continue;
-                if (strncmp(buff, "go", 2) == 0) {
-                  log_println(6, "Got 'go' signal from parent, ready to start "
-                              "testing %d", getpid());
-                  break;
-                }
-                if (buff[0] == 0) {
-                  log_println(6, "Child %d received 'go' signal, exiting",
-                              getpid());
-                  exit(-1);
-                }
-              }
+        // This is the child process from the above fork().  The parent
+        //  is in control, and will send this child a signal when it gets
+        //  to the head of the testing queue.  Post a read() and simply
+        //  wait for the parent to let us know it's time to move on.
+        //  Rich Carlson 3/11/04
+        for (;;) {
+          memset(buff, 0, sizeof(buff));
+
+          // the read() could return if an interrupt was caught.  This
+          // condition should be checked for and the read() restarted if
+          // necessary
+          // RAC 3/18/10
+          //
+          retcode = read(chld_pipe[0], buff, 32);
+          log_println(6, "Child %d received '%s' from parent", getpid(), buff);
+          if ((retcode == -1) && (errno == EINTR))
+            continue;
+          if (strncmp(buff, "go", 2) == 0) {
+            log_println(6, "Got 'go' signal from parent, ready to start "
+                        "testing %d", getpid());
+            break;
+          }
+          if (buff[0] == 0) {
+            log_println(6, "Child %d received 'go' signal, exiting", getpid());
+            exit(-1);
+          }
+        }
 
-              set_timestamp();
-
-              // The next 3 instructions retrieve the passed in values for the
-              // tests to run.
-              //  t_opts will be the bitmapped version of this data and
-              //  test_suite will be a character string with the same info.
-              //  Note: this assumes that the structure of buff is fixed with
-              //  the character strings starting in these locations.
-              //     RAC 7/8/09
-
-              memset(test_suite, 0, sizeof(test_suite));
-              t_opts = atoi(buff+3);
-              memcpy(test_suite, buff+5, (strlen(buff)-5));
-              /* memcpy(test_suite, buff+6, 7); */
-              log_println(5, "extracting test_suite '%s' and t_opts '%x' from "
-                          "buff '%s'", test_suite, t_opts, buff);
-
-              // construct cputime log folder
-              {
-                I2Addr tmp_addr = I2AddrBySockFD(get_errhandle(), ctlsockfd,
-                                                 False);
-                testPort = I2AddrPort(tmp_addr);
-                meta.ctl_port = testPort;
-                snprintf(testName, sizeof(testName), "%s", name);
-                I2AddrFree(tmp_addr);
-                memset(cputimelog, 0, 256);
-                if (cputime) {
-                  snprintf(dir, sizeof(dir), "%s_%s:%d.cputime",
-                           get_ISOtime(isoTime, sizeof(isoTime)), name,
-                           testPort);
-                  log_println(8, "CPUTIME:suffix=%s", dir);
-                  create_named_logdir(cputimelog, sizeof(cputimelog), dir, 0);
-                  memcpy(meta.CPU_time, dir, strlen(dir));
-                  if (pthread_create(&workerThreadId, NULL, cputimeWorker,
-                                     (void*) cputimelog)) {
-                    log_println(0, "Cannot create worker thread for writing "
-                                "cpu usage!");
-                    workerThreadId = 0;
-                    memset(cputimelog, 0, 256);
-                  }
-                }
-              }
-              // write the incoming connection data into the log file
-              fp = fopen(get_logfile(), "a");
-              if (fp == NULL) {
-                log_println(0, "Unable to open log file '%s', continuing on "
-                            "without logging", get_logfile());
-              } else {
-                fprintf(fp, "%15.15s  %s port %d\n", ctime(&tt)+4, name,
-                        testPort);
-                if (cputime && workerThreadId) {
-                  log_println(1, "cputime trace file: %s\n", cputimelog);
-                  fprintf(fp, "cputime trace file: %s\n", cputimelog);
-                }
-                fclose(fp);
-              }
-              close(chld_pipe[0]);
-
-              // Set test options
-              if (t_opts & TEST_MID)
-                testopt.midopt = TOPT_ENABLED;
-              if (t_opts & TEST_SFW)
-                testopt.sfwopt = TOPT_ENABLED;
-              if (t_opts & TEST_META)
-                testopt.metaopt = TOPT_ENABLED;
-              if (t_opts & TEST_C2S)
-                testopt.c2sopt = TOPT_ENABLED;
-              if (t_opts & TEST_S2C)
-                testopt.s2copt = TOPT_ENABLED;
-              // die in 120 seconds, but only if a test doesn't get started
-              alarm(120);
-              // reset alarm() before every test
-              log_println(6, "setting master alarm() to 120 seconds, tests "
-                          "must start (complete?) before this timer expires");
-
-              // run tests based on options
-              if (strncmp(test_suite, "Invalid", 7) != 0) {
-                log_println(3, "Valid test sequence requested, run test for "
-                            "client=%d", getpid());
-                retcode = run_test(agent, ctlsockfd, &testopt, test_suite);
-              }
+        set_timestamp();
+
+        // The next 3 instructions retrieve the passed in values for the
+        // tests to run.
+        //  t_opts will be the bitmapped version of this data and
+        //  test_suite will be a character string with the same info.
+        //  Note: this assumes that the structure of buff is fixed with
+        //  the character strings starting in these locations.
+        //     RAC 7/8/09
+
+        memset(test_suite, 0, sizeof(test_suite));
+        t_opts = atoi(buff+3);
+        memcpy(test_suite, buff+5, (strlen(buff)-5));
+        /* memcpy(test_suite, buff+6, 7); */
+        log_println(5, "extracting test_suite '%s' and t_opts '%x' from "
+                    "buff '%s'", test_suite, t_opts, buff);
+
+        // construct cputime log folder
+        {
+          I2Addr tmp_addr = I2AddrBySockFD(get_errhandle(), ctlsockfd, False);
+          testPort = I2AddrPort(tmp_addr);
+          meta.ctl_port = testPort;
+          snprintf(testName, sizeof(testName), "%s", name);
+          I2AddrFree(tmp_addr);
+          memset(cputimelog, 0, 256);
+          if (cputime) {
+            snprintf(dir, sizeof(dir), "%s_%s:%d.cputime",
+                     get_ISOtime(isoTime, sizeof(isoTime)), name,
+                     testPort);
+            log_println(8, "CPUTIME:suffix=%s", dir);
+            create_named_logdir(cputimelog, sizeof(cputimelog), dir, 0);
+            memcpy(meta.CPU_time, dir, strlen(dir));
+            if (pthread_create(&workerThreadId, NULL, cputimeWorker,
+                               (void*) cputimelog)) {
+              log_println(0, "Cannot create worker thread for writing "
+                          "cpu usage!");
+              workerThreadId = 0;
+              memset(cputimelog, 0, 256);
+            }
+          }
+        }
+        // write the incoming connection data into the log file
+        fp = fopen(get_logfile(), "a");
+        if (fp == NULL) {
+          log_println(0, "Unable to open log file '%s', continuing on "
+                      "without logging", get_logfile());
+        } else {
+          fprintf(fp, "%15.15s  %s port %d\n", ctime(&tt)+4, name, testPort);
+          if (cputime && workerThreadId) {
+            log_println(1, "cputime trace file: %s\n", cputimelog);
+            fprintf(fp, "cputime trace file: %s\n", cputimelog);
+          }
+          fclose(fp);
+        }
+        close(chld_pipe[0]);
+
+        // Set test options
+        if (t_opts & TEST_MID)
+          testopt.midopt = TOPT_ENABLED;
+        if (t_opts & TEST_SFW)
+          testopt.sfwopt = TOPT_ENABLED;
+        if (t_opts & TEST_META)
+          testopt.metaopt = TOPT_ENABLED;
+        if (t_opts & TEST_C2S)
+          testopt.c2sopt = TOPT_ENABLED;
+        if (t_opts & TEST_S2C)
+          testopt.s2copt = TOPT_ENABLED;
+        // die in 120 seconds, but only if a test doesn't get started
+        alarm(120);
+        // reset alarm() before every test
+        log_println(6, "setting master alarm() to 120 seconds, tests "
+                    "must start (complete?) before this timer expires");
+
+        // run tests based on options
+        if (strncmp(test_suite, "Invalid", 7) != 0) {
+          log_println(3, "Valid test sequence requested, run test for "
+                      "client=%d", getpid());
+          retcode = run_test(agent, ctlsockfd, &testopt, test_suite);
+        }
 
-              // conclude all test runs
-              if (retcode == 0) {
-                log_println(3, "Successfully returned from run_test() routine");
-              } else {
-                log_println(3, "Child %d returned non-zero (%d) from "
-                            "run_test() results some test failed!", getpid(),
-                            retcode);
-                child_sig(0);
-              }
-              close(ctlsockfd);
-              web100_detach(agent);
-              log_free();
+        // conclude all test runs
+        if (retcode == 0) {
+          log_println(3, "Successfully returned from run_test() routine");
+        } else {
+          log_println(3, "Child %d returned non-zero (%d) from "
+                      "run_test() results some test failed!", getpid(),
+                      retcode);
+          child_sig(0);
+        }
+        close(ctlsockfd);
+        web100_detach(agent);
+        log_free();
 
-              if (cputime && workerThreadId) {
-                cputimeworkerLoop = 0;
-                pthread_join(workerThreadId, NULL);
-              }
+        if (cputime && workerThreadId) {
+          cputimeworkerLoop = 0;
+          pthread_join(workerThreadId, NULL);
+        }
 
-              // At this point the tests have been run and we need to clean up
-              // and handle and child processes that might still be lying
-              // around.  If we don't we get zombies. The pkt-pair handling
-              // created 2 childern and we need to get rid of them. To know
-              // what PIDs to look for on 1/19/10 the run_test() routine was
-              // modified to pass around these values. The values are set in
-              // the proper routine in the testoptions.c file.
-              // Then add call to child_sig() routine and pass in these PID's
-              // so we handle each child in sequence
-
-              log_println(6, "remove pkt-pair children c2s=%d, s2c=%d",
-                          testopt.child1, testopt.child2);
-              if (testopt.child1 != 0)
-                child_sig(testopt.child1);
-              if (testopt.child2 != 0)
-                child_sig(testopt.child2);
-              exit(0);
-              break;
-          }
+        // At this point the tests have been run and we need to clean up
+        // and handle and child processes that might still be lying
+        // around.  If we don't we get zombies. The pkt-pair handling
+        // created 2 childern and we need to get rid of them. To know
+        // what PIDs to look for on 1/19/10 the run_test() routine was
+        // modified to pass around these values. The values are set in
+        // the proper routine in the testoptions.c file.
+        // Then add call to child_sig() routine and pass in these PID's
+        // so we handle each child in sequence
+
+        log_println(6, "remove pkt-pair children c2s=%d, s2c=%d",
+                    testopt.child1, testopt.child2);
+        if (testopt.child1 != 0)
+          child_sig(testopt.child1);
+        if (testopt.child2 != 0)
+          child_sig(testopt.child2);
+        exit(0);
+        break;
+    }
   }
 }
 
