Changeset 4452 for trunk/Ohana/src/opihi/pantasks/ControllerOps.c
- Timestamp:
- Jul 5, 2005, 7:12:22 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pantasks/ControllerOps.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pantasks/ControllerOps.c
r4451 r4452 5 5 int status = FALSE; 6 6 int stdin_cntl, stdout_cntl, stderr_cntl; 7 8 /* we read Nbytes from the host, then watch for the prompt */9 int GetJobOutput (char *cmd, int pid, IOBuffer *buffer, int Nbytes) {10 11 int i, status, Nstart;12 char *line;13 14 /* flush any earlier messages */15 ReadtoIOBuffer (buffer, stdout_cntl);16 FlushIOBuffer (buffer);17 Nstart = buffer[0].Nbuffer;18 19 /* send command to get appropriate channel */20 ALLOCATE (line, char, MAX (1, strlen(cmd) + 15));21 sprintf (line, "%s %d\n", cmd, pid);22 status = write (stdin_cntl, line, strlen(line));23 free (line);24 25 /* is pipe still open? */26 if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN);27 28 /* read at least Nbytes, then watch for CONTROLLER_PROMPT */29 line = NULL;30 status = -1;31 for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) {32 status = ReadtoIOBuffer (buffer, stdout_cntl);33 if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {34 line = memstr (buffer[0].buffer, CONTROLLER_PROMPT, buffer[0].Nbuffer);35 }36 if (status == -1) usleep (10000);37 }38 if (status == 0) return (CONTROLLER_DOWN);39 if (status == -1) return (CONTROLLER_HUNG);40 41 fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd);42 /* drop extra bytes from pcontrol (not pclient:job) */43 buffer[0].Nbuffer = Nstart + Nbytes;44 if (buffer[0].Nalloc > buffer[0].Nbuffer) {45 bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);46 }47 return (CONTROLLER_GOOD);48 }49 7 50 8 int CheckControllerJob (Job *job) { … … 123 81 } 124 82 83 /* we read Nbytes from the host, then watch for the prompt */ 84 int GetJobOutput (char *cmd, int pid, IOBuffer *buffer, int Nbytes) { 85 86 int i, status, Nstart; 87 char *line; 88 89 /* flush any earlier messages */ 90 ReadtoIOBuffer (buffer, stdout_cntl); 91 FlushIOBuffer (buffer); 92 Nstart = buffer[0].Nbuffer; 93 94 /* send command to get appropriate channel */ 95 ALLOCATE (line, char, MAX (1, strlen(cmd) + 15)); 96 sprintf (line, "%s %d\n", cmd, pid); 97 status = write (stdin_cntl, line, strlen(line)); 98 free (line); 99 100 /* is pipe still open? */ 101 if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN); 102 103 /* read at least Nbytes, then watch for CONTROLLER_PROMPT */ 104 line = NULL; 105 status = -1; 106 for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) { 107 status = ReadtoIOBuffer (buffer, stdout_cntl); 108 if ((buffer[0].Nbuffer - Nstart) >= Nbytes) { 109 line = memstr (buffer[0].buffer, CONTROLLER_PROMPT, buffer[0].Nbuffer); 110 } 111 if (status == -1) usleep (10000); 112 } 113 if (status == 0) return (CONTROLLER_DOWN); 114 if (status == -1) return (CONTROLLER_HUNG); 115 116 fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 117 /* drop extra bytes from pcontrol (not pclient:job) */ 118 buffer[0].Nbuffer = Nstart + Nbytes; 119 if (buffer[0].Nalloc > buffer[0].Nbuffer) { 120 bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer); 121 } 122 return (CONTROLLER_GOOD); 123 } 124 125 125 /* submitting a job to the controller automatically starts controller */ 126 126 int SubmitControllerJob (Job *job) { … … 165 165 } 166 166 167 fprintf (stderr, "sending command to controller: %s\n", cmd); 167 168 InitIOBuffer (&buffer, 0x100); 168 169 ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer); 169 170 free (cmd); 170 171 172 fprintf (stderr, "response from controller: %s\n", buffer.buffer); 173 171 174 /* extract the job PID from the controller response */ 172 p = memstr (buffer.buffer, " STATUS", buffer.Nbuffer);175 p = memstr (buffer.buffer, "JobID", buffer.Nbuffer); 173 176 if (p == NULL) { 174 177 fprintf (stderr, "missing PID in pcontrol message : programming error\n"); … … 298 301 FlushIOBuffer (buffer); 299 302 303 fprintf (stderr, "send: %s\n", cmd); 304 300 305 /* send command to client (adding on \n) */ 301 /* fprintf (stderr, "send: %s (%d)\n", command, buffer[0].Nbuffer); */302 306 ALLOCATE (line, char, MAX (1, strlen(cmd))); 303 307 sprintf (line, "%s\n", cmd);
Note:
See TracChangeset
for help on using the changeset viewer.
