{"action":"created","comment":{"url":"https://api.github.com/repos/m-lab/ndt/pulls/comments/33049299","id":33049299,"diff_hunk":"@@ -1366,90 +1266,64 @@ void process_parent_message(int parent_message, Connection *ctl,\n  */\n void child_process(int parent_pipe, SSL_CTX *ssl_context, int ctlsockfd) {\n   FILE *fp;\n-  int parent_message;\n   time_t tt;\n   char isoTime[64], dir[256];\n-  char ssl_error[255];\n-  unsigned long ssl_err;\n   int t_opts = 0;\n-  int retcode;\n-  char buff[32];\n-  int msg_type = 0;\n-  int msg_len = 0;\n-  char test_suite[16];\n+  int retcode = 0, parent_message;\n+  char test_suite[256];\n   tcp_stat_agent *agent;\n   Connection ctl = {0, NULL};\n   ctl.socket = ctlsockfd;\n   // this is the child process, it handles the connection with the client and\n   // runs the actual tests.\n-  log_println(4, \"Child thinks pipe() returned fd0=%d, fd1=%d for pid=%d\",\n-              chld_pipe[0], chld_pipe[1], chld_pid);\n-  close(listenfd);\n-  close(chld_pipe[1]);\n+  // First, start the watchdog timer\n+  alarm(300);\n+\n+  // Set up the connection with the client (with optional SSL and websockets)\n+  if (options.tls) {\n+    if (setup_SSL_connection(&ctl, ssl_context) != 0) {\n+      log_println(1, \"setup_SSL_connection failed\");\n+      exit(-1);\n+    }\n+  }\n+\n+  // Read the login message and send the kickoff message (if applicable)\n+  t_opts = initialize_tests(&ctl, &testopt, test_suite, sizeof(test_suite));\n+  if (t_opts < 1) {  // some error in initialization routines\n+    log_println(3, \"Invalid test suite received, terminate child\");\n+    exit(-1);\n+  }\n+\n #if USE_WEB100\n   if ((agent = web100_attach(WEB100_AGENT_TYPE_LOCAL, NULL)) == NULL) {\n     web100_perror(\"web100_attach\");\n-    return 1;\n+    exit(1);\n   }\n #elif USE_WEB10G\n   if (estats_nl_client_init(&agent) != NULL) {\n-    log_println(0,\n-                  \"Error: estats_client_init failed.\"\n-                  \"Unable to use web10g.\");\n-    return 1;\n+    log_println(0, \"Error: estats_client_init failed. Unable to use web10g.\");\n+    exit(1);\n   }\n #endif\n-  // This is the child process from the above fork().  The parent\n-  //  is in control, and will send this child a signal when it gets\n-  //  to the head of the testing queue.  Post a read() and simply\n-  //  wait for the parent to let us know it's time to move on.\n-  //  Rich Carlson 3/11/04\n-  for (;;) {\n-    memset(buff, 0, sizeof(buff));\n-\n-    // the read() could return if an interrupt was caught.  This\n-    // condition should be checked for and the read() restarted if\n-    // necessary\n-    // RAC 3/18/10\n-    //\n-    retcode = read(chld_pipe[0], buff, 32);\n-    log_println(6, \"Child %d received '%s' from parent\", getpid(),\n-                buff);\n-    if ((retcode == -1) && (errno == EINTR))\n-      continue;\n-    if (strncmp(buff, \"go\", 2) == 0) {\n-      log_println(6, \"Got 'go' signal from parent, ready to start \"\n-                  \"testing %d\", getpid());\n-      break;\n-    }\n-    if (buff[0] == 0) {\n-      log_println(6, \"Child %d received 'go' signal, exiting\",\n-                  getpid());\n-      exit(-1);\n-    }\n+  // Wait in the queue until the child process is told to start\n+  while ((parent_message = read_from_parent(parent_pipe)) !=\n+         SRV_QUEUE_TEST_STARTS_NOW) {\n+    process_parent_message(parent_message, &ctl, &testopt, t_opts);\n   }\n \n-  set_timestamp();\n+  // Tell the client the test is about to start\n+  if (send_json_message_any(&ctl, SRV_QUEUE, SRV_QUEUE_TEST_STARTS_NOW_STR,\n+                            strlen(SRV_QUEUE_TEST_STARTS_NOW_STR),\n+                            testopt.connection_flags, JSON_SINGLE_VALUE) != 0) {\n+    log_println(1, \"Error when sending SRV_QUEUE_TEST_STARTS_NOW to client\");\n+    exit(-1);\n+  }","path":"src/web100srv.c","position":897,"original_position":897,"commit_id":"2aa3e0906cf7dd9c5cdfb6c33baf24cad26ad46d","original_commit_id":"2aa3e0906cf7dd9c5cdfb6c33baf24cad26ad46d","user":{"login":"mtlynch","id":7783288,"avatar_url":"https://avatars.githubusercontent.com/u/7783288?v=3","gravatar_id":"","url":"https://api.github.com/users/mtlynch","html_url":"https://github.com/mtlynch","followers_url":"https://api.github.com/users/mtlynch/followers","following_url":"https://api.github.com/users/mtlynch/following{/other_user}","gists_url":"https://api.github.com/users/mtlynch/gists{/gist_id}","starred_url":"https://api.github.com/users/mtlynch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtlynch/subscriptions","organizations_url":"https://api.github.com/users/mtlynch/orgs","repos_url":"https://api.github.com/users/mtlynch/repos","events_url":"https://api.github.com/users/mtlynch/events{/privacy}","received_events_url":"https://api.github.com/users/mtlynch/received_events","type":"User","site_admin":false},"body":"Can we refactor these queueing messages into a helper function so that this:\r\n\r\n```\r\n    char serialized_parent_message[256];\r\n    sprintf(serialized_parent_message, \"%d\", parent_message);\r\n    if (send_json_message_any(ctl, SRV_QUEUE, serialized_parent_message,\r\n                              strlen(serialized_parent_message),\r\n                              testopt->connection_flags,\r\n                              JSON_SINGLE_VALUE) != 0) {\r\n      log_println(1, \"Client failed to send message\");\r\n      exit(0);\r\n    }\r\n```\r\n\r\nCan become this:\r\n\r\n```\r\n    send_queue_message(ctl, parent_message, testopt->connection_flags);\r\n```\r\n\r\nAnd then we can get rid of those `SRV_QUEUE_*_STR` constants that I've had it in for the whole review.","created_at":"2015-06-23T14:51:50Z","updated_at":"2015-06-23T14:51:50Z","html_url":"https://github.com/m-lab/ndt/pull/12#discussion_r33049299","pull_request_url":"https://api.github.com/repos/m-lab/ndt/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/comments/33049299"},"html":{"href":"https://github.com/m-lab/ndt/pull/12#discussion_r33049299"},"pull_request":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/m-lab/ndt/pulls/12","id":35435987,"html_url":"https://github.com/m-lab/ndt/pull/12","diff_url":"https://github.com/m-lab/ndt/pull/12.diff","patch_url":"https://github.com/m-lab/ndt/pull/12.patch","issue_url":"https://api.github.com/repos/m-lab/ndt/issues/12","number":12,"state":"open","locked":false,"title":"Make the pull requests look right","user":{"login":"pboothe","id":143798,"avatar_url":"https://avatars.githubusercontent.com/u/143798?v=3","gravatar_id":"","url":"https://api.github.com/users/pboothe","html_url":"https://github.com/pboothe","followers_url":"https://api.github.com/users/pboothe/followers","following_url":"https://api.github.com/users/pboothe/following{/other_user}","gists_url":"https://api.github.com/users/pboothe/gists{/gist_id}","starred_url":"https://api.github.com/users/pboothe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pboothe/subscriptions","organizations_url":"https://api.github.com/users/pboothe/orgs","repos_url":"https://api.github.com/users/pboothe/repos","events_url":"https://api.github.com/users/pboothe/events{/privacy}","received_events_url":"https://api.github.com/users/pboothe/received_events","type":"User","site_admin":false},"body":"Second one.","created_at":"2015-05-14T16:13:33Z","updated_at":"2015-06-23T14:51:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ec358841d538477f2150684e5bb579223813f965","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/m-lab/ndt/pulls/12/commits","review_comments_url":"https://api.github.com/repos/m-lab/ndt/pulls/12/comments","review_comment_url":"https://api.github.com/repos/m-lab/ndt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m-lab/ndt/issues/12/comments","statuses_url":"https://api.github.com/repos/m-lab/ndt/statuses/2aa3e0906cf7dd9c5cdfb6c33baf24cad26ad46d","head":{"label":"m-lab:imaginary_middle2","ref":"imaginary_middle2","sha":"2aa3e0906cf7dd9c5cdfb6c33baf24cad26ad46d","user":{"login":"m-lab","id":3496264,"avatar_url":"https://avatars.githubusercontent.com/u/3496264?v=3","gravatar_id":"","url":"https://api.github.com/users/m-lab","html_url":"https://github.com/m-lab","followers_url":"https://api.github.com/users/m-lab/followers","following_url":"https://api.github.com/users/m-lab/following{/other_user}","gists_url":"https://api.github.com/users/m-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/m-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-lab/subscriptions","organizations_url":"https://api.github.com/users/m-lab/orgs","repos_url":"https://api.github.com/users/m-lab/repos","events_url":"https://api.github.com/users/m-lab/events{/privacy}","received_events_url":"https://api.github.com/users/m-lab/received_events","type":"Organization","site_admin":false},"repo":{"id":33625942,"name":"ndt","full_name":"m-lab/ndt","owner":{"login":"m-lab","id":3496264,"avatar_url":"https://avatars.githubusercontent.com/u/3496264?v=3","gravatar_id":"","url":"https://api.github.com/users/m-lab","html_url":"https://github.com/m-lab","followers_url":"https://api.github.com/users/m-lab/followers","following_url":"https://api.github.com/users/m-lab/following{/other_user}","gists_url":"https://api.github.com/users/m-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/m-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-lab/subscriptions","organizations_url":"https://api.github.com/users/m-lab/orgs","repos_url":"https://api.github.com/users/m-lab/repos","events_url":"https://api.github.com/users/m-lab/events{/privacy}","received_events_url":"https://api.github.com/users/m-lab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m-lab/ndt","description":"Network Diagnostic Tool","fork":true,"url":"https://api.github.com/repos/m-lab/ndt","forks_url":"https://api.github.com/repos/m-lab/ndt/forks","keys_url":"https://api.github.com/repos/m-lab/ndt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m-lab/ndt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m-lab/ndt/teams","hooks_url":"https://api.github.com/repos/m-lab/ndt/hooks","issue_events_url":"https://api.github.com/repos/m-lab/ndt/issues/events{/number}","events_url":"https://api.github.com/repos/m-lab/ndt/events","assignees_url":"https://api.github.com/repos/m-lab/ndt/assignees{/user}","branches_url":"https://api.github.com/repos/m-lab/ndt/branches{/branch}","tags_url":"https://api.github.com/repos/m-lab/ndt/tags","blobs_url":"https://api.github.com/repos/m-lab/ndt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m-lab/ndt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m-lab/ndt/git/refs{/sha}","trees_url":"https://api.github.com/repos/m-lab/ndt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m-lab/ndt/statuses/{sha}","languages_url":"https://api.github.com/repos/m-lab/ndt/languages","stargazers_url":"https://api.github.com/repos/m-lab/ndt/stargazers","contributors_url":"https://api.github.com/repos/m-lab/ndt/contributors","subscribers_url":"https://api.github.com/repos/m-lab/ndt/subscribers","subscription_url":"https://api.github.com/repos/m-lab/ndt/subscription","commits_url":"https://api.github.com/repos/m-lab/ndt/commits{/sha}","git_commits_url":"https://api.github.com/repos/m-lab/ndt/git/commits{/sha}","comments_url":"https://api.github.com/repos/m-lab/ndt/comments{/number}","issue_comment_url":"https://api.github.com/repos/m-lab/ndt/issues/comments{/number}","contents_url":"https://api.github.com/repos/m-lab/ndt/contents/{+path}","compare_url":"https://api.github.com/repos/m-lab/ndt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m-lab/ndt/merges","archive_url":"https://api.github.com/repos/m-lab/ndt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m-lab/ndt/downloads","issues_url":"https://api.github.com/repos/m-lab/ndt/issues{/number}","pulls_url":"https://api.github.com/repos/m-lab/ndt/pulls{/number}","milestones_url":"https://api.github.com/repos/m-lab/ndt/milestones{/number}","notifications_url":"https://api.github.com/repos/m-lab/ndt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m-lab/ndt/labels{/name}","releases_url":"https://api.github.com/repos/m-lab/ndt/releases{/id}","created_at":"2015-04-08T18:54:07Z","updated_at":"2015-05-06T21:54:03Z","pushed_at":"2015-06-22T21:46:35Z","git_url":"git://github.com/m-lab/ndt.git","ssh_url":"git@github.com:m-lab/ndt.git","clone_url":"https://github.com/m-lab/ndt.git","svn_url":"https://github.com/m-lab/ndt","homepage":null,"size":4248,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"m-lab:imaginary_middle","ref":"imaginary_middle","sha":"af38a34f3005ff6b961e481809a0b62e7377d530","user":{"login":"m-lab","id":3496264,"avatar_url":"https://avatars.githubusercontent.com/u/3496264?v=3","gravatar_id":"","url":"https://api.github.com/users/m-lab","html_url":"https://github.com/m-lab","followers_url":"https://api.github.com/users/m-lab/followers","following_url":"https://api.github.com/users/m-lab/following{/other_user}","gists_url":"https://api.github.com/users/m-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/m-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-lab/subscriptions","organizations_url":"https://api.github.com/users/m-lab/orgs","repos_url":"https://api.github.com/users/m-lab/repos","events_url":"https://api.github.com/users/m-lab/events{/privacy}","received_events_url":"https://api.github.com/users/m-lab/received_events","type":"Organization","site_admin":false},"repo":{"id":33625942,"name":"ndt","full_name":"m-lab/ndt","owner":{"login":"m-lab","id":3496264,"avatar_url":"https://avatars.githubusercontent.com/u/3496264?v=3","gravatar_id":"","url":"https://api.github.com/users/m-lab","html_url":"https://github.com/m-lab","followers_url":"https://api.github.com/users/m-lab/followers","following_url":"https://api.github.com/users/m-lab/following{/other_user}","gists_url":"https://api.github.com/users/m-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/m-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-lab/subscriptions","organizations_url":"https://api.github.com/users/m-lab/orgs","repos_url":"https://api.github.com/users/m-lab/repos","events_url":"https://api.github.com/users/m-lab/events{/privacy}","received_events_url":"https://api.github.com/users/m-lab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m-lab/ndt","description":"Network Diagnostic Tool","fork":true,"url":"https://api.github.com/repos/m-lab/ndt","forks_url":"https://api.github.com/repos/m-lab/ndt/forks","keys_url":"https://api.github.com/repos/m-lab/ndt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m-lab/ndt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m-lab/ndt/teams","hooks_url":"https://api.github.com/repos/m-lab/ndt/hooks","issue_events_url":"https://api.github.com/repos/m-lab/ndt/issues/events{/number}","events_url":"https://api.github.com/repos/m-lab/ndt/events","assignees_url":"https://api.github.com/repos/m-lab/ndt/assignees{/user}","branches_url":"https://api.github.com/repos/m-lab/ndt/branches{/branch}","tags_url":"https://api.github.com/repos/m-lab/ndt/tags","blobs_url":"https://api.github.com/repos/m-lab/ndt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m-lab/ndt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m-lab/ndt/git/refs{/sha}","trees_url":"https://api.github.com/repos/m-lab/ndt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m-lab/ndt/statuses/{sha}","languages_url":"https://api.github.com/repos/m-lab/ndt/languages","stargazers_url":"https://api.github.com/repos/m-lab/ndt/stargazers","contributors_url":"https://api.github.com/repos/m-lab/ndt/contributors","subscribers_url":"https://api.github.com/repos/m-lab/ndt/subscribers","subscription_url":"https://api.github.com/repos/m-lab/ndt/subscription","commits_url":"https://api.github.com/repos/m-lab/ndt/commits{/sha}","git_commits_url":"https://api.github.com/repos/m-lab/ndt/git/commits{/sha}","comments_url":"https://api.github.com/repos/m-lab/ndt/comments{/number}","issue_comment_url":"https://api.github.com/repos/m-lab/ndt/issues/comments{/number}","contents_url":"https://api.github.com/repos/m-lab/ndt/contents/{+path}","compare_url":"https://api.github.com/repos/m-lab/ndt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m-lab/ndt/merges","archive_url":"https://api.github.com/repos/m-lab/ndt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m-lab/ndt/downloads","issues_url":"https://api.github.com/repos/m-lab/ndt/issues{/number}","pulls_url":"https://api.github.com/repos/m-lab/ndt/pulls{/number}","milestones_url":"https://api.github.com/repos/m-lab/ndt/milestones{/number}","notifications_url":"https://api.github.com/repos/m-lab/ndt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m-lab/ndt/labels{/name}","releases_url":"https://api.github.com/repos/m-lab/ndt/releases{/id}","created_at":"2015-04-08T18:54:07Z","updated_at":"2015-05-06T21:54:03Z","pushed_at":"2015-06-22T21:46:35Z","git_url":"git://github.com/m-lab/ndt.git","ssh_url":"git@github.com:m-lab/ndt.git","clone_url":"https://github.com/m-lab/ndt.git","svn_url":"https://github.com/m-lab/ndt","homepage":null,"size":4248,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/12"},"html":{"href":"https://github.com/m-lab/ndt/pull/12"},"issue":{"href":"https://api.github.com/repos/m-lab/ndt/issues/12"},"comments":{"href":"https://api.github.com/repos/m-lab/ndt/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m-lab/ndt/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/m-lab/ndt/statuses/2aa3e0906cf7dd9c5cdfb6c33baf24cad26ad46d"}}}}