Changeset 19125 for trunk/Ohana/src/opihi/pantasks/ControllerOps.c
- Timestamp:
- Aug 19, 2008, 12:29:10 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pantasks/ControllerOps.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pantasks/ControllerOps.c
r18085 r19125 10 10 static IOBuffer stderr_buffer; 11 11 static int ControllerPID = 0; 12 13 /* local static variables to track the controller host properties */ 14 static Host *hosts = NULL; 15 static int Nhosts = 0; 16 static int NHOSTS = 0; 17 18 int AddHost (char *hostname, int max_threads) { 19 20 int N; 21 22 N = Nhosts; 23 Nhosts ++; 24 25 CHECK_REALLOCATE (hosts, Host, NHOSTS, Nhosts, 16); 26 27 hosts[N].hostname = strcreate (hostname); 28 hosts[N].max_threads = max_threads; 29 30 return (TRUE); 31 } 32 33 int DeleteHost (char *hostname) { 34 35 int i, j; 36 37 for (i = 0; i < Nhosts; i++) { 38 if (strcmp (hosts[i].hostname, hostname)) continue; 39 40 // delete this one 41 free (hosts[i].hostname); 42 for (j = i; j < Nhosts - 1; j++) { 43 hosts[j].hostname = hosts[j+1].hostname; 44 hosts[j].max_threads = hosts[j+1].max_threads; 45 } 46 Nhosts --; 47 return (TRUE); 48 } 49 return (FALSE); 50 } 12 51 13 52 /* test if the controller is running */ … … 146 185 147 186 /* is pipe still open? */ 148 if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN); 187 // XXX call StopController() here? 188 if ((status == -1) && (errno == EPIPE)) { 189 StopController (); 190 return (CONTROLLER_DOWN); 191 } 149 192 150 193 /* read at least Nbytes, then watch for CONTROLLER_PROMPT */ … … 158 201 if (status == -1) nanosleep (&request, &remain); 159 202 } 160 if (status == 0) return (CONTROLLER_DOWN); 203 if (status == 0) { 204 StopController (); 205 return (CONTROLLER_DOWN); 206 } 161 207 if (status == -1) return (CONTROLLER_HUNG); 162 208 … … 245 291 if (VarConfig ("CONTROLLER", "%s", cmd) == NULL) strcpy (cmd, "pcontrol"); 246 292 293 if (hosts == NULL) { 294 NHOSTS = 16; 295 ALLOCATE (hosts, Host, NHOSTS); 296 } 297 247 298 bzero (stdin_fd, 2*sizeof(int)); 248 299 bzero (stdout_fd, 2*sizeof(int)); … … 360 411 if ((status == -1) && (errno == EPIPE)) { 361 412 StopController (); 362 gprint (GP_ERR, "controller is down\n"); 413 gprint (GP_ERR, "controller is down, restarting\n"); 414 if (!RestartController ()) { 415 return (FALSE); 416 } 363 417 return (FALSE); 364 418 } … … 509 563 return (TRUE); 510 564 } 565 566 int RestartController () { 567 568 int i, status; 569 char command[256]; 570 IOBuffer buffer; 571 572 gprint (GP_ERR, "controller is down, restarting\n"); 573 if (!StartController ()) { 574 gprint (GP_ERR, "failure to re-start pcontrol\n"); 575 return (FALSE); 576 } 577 578 InitIOBuffer (&buffer, 0x100); 579 580 // XXX lock the host table? SerialThreadLock (); 581 fprintf (stderr, "controller is down, restarting\n"); 582 for (i = 0; i < Nhosts; i++) { 583 fprintf (stderr, "controller host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads); 584 snprintf (command, 256, "host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads); 585 status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer); 586 } 587 // SerialThreadUnlock (); 588 589 if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG); 590 591 FreeIOBuffer (&buffer); 592 593 return (TRUE); 594 }
Note:
See TracChangeset
for help on using the changeset viewer.
