Changeset 4705
- Timestamp:
- Aug 3, 2005, 5:50:08 PM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 3 added
- 31 edited
-
include/pcontrol.h (modified) (3 diffs)
-
include/psched.h (modified) (3 diffs)
-
lib.data/IOBufferOps.c (modified) (2 diffs)
-
lib.shell/MacroOps.c (modified) (1 diff)
-
lib.shell/memstr.c (modified) (2 diffs)
-
pantasks/CheckJobs.c (modified) (2 diffs)
-
pantasks/ControllerOps.c (modified) (15 diffs)
-
pantasks/JobOps.c (modified) (5 diffs)
-
pantasks/Makefile (modified) (1 diff)
-
pantasks/TaskOps.c (modified) (5 diffs)
-
pantasks/controller_check.c (modified) (2 diffs)
-
pantasks/controller_host.c (modified) (3 diffs)
-
pantasks/controller_status.c (modified) (2 diffs)
-
pantasks/init.c (modified) (2 diffs)
-
pantasks/psched.c (modified) (1 diff)
-
pantasks/pulse.c (added)
-
pantasks/run.c (modified) (1 diff)
-
pantasks/status.c (modified) (1 diff)
-
pantasks/stop.c (modified) (1 diff)
-
pantasks/task.c (modified) (1 diff)
-
pantasks/task_command.c (modified) (1 diff)
-
pantasks/task_host.c (modified) (3 diffs)
-
pantasks/task_macros.c (modified) (1 diff)
-
pcontrol/CheckIdleHost.c (modified) (1 diff)
-
pcontrol/CheckSystem.c (modified) (2 diffs)
-
pcontrol/GetJobOutput.c (modified) (1 diff)
-
pcontrol/HostOps.c (modified) (2 diffs)
-
pcontrol/JobOps.c (modified) (1 diff)
-
pcontrol/StartHost.c (modified) (3 diffs)
-
pcontrol/host.c (modified) (2 diffs)
-
pcontrol/pclient.c (modified) (1 diff)
-
pcontrol/rconnect.c (modified) (4 diffs)
-
scripts/psched.pro (added)
-
scripts/queuetests (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/pcontrol.h
r4693 r4705 83 83 int pid; 84 84 HostStat stack; 85 Ptime start; 85 struct timeval lasttry; 86 struct timeval nexttry; 86 87 Ptime accum; 87 88 Ptime timer; … … 101 102 # define FREE(X) if (X != NULL) { free (X); } 102 103 # define CLOSE(FD) { if (FD) close (FD); FD = 0; } 104 # define DTIME(A,B) ((A.tv_sec - B.tv_sec) + 1e-6*(A.tv_usec - B.tv_usec)) 105 # define ZTIME(A) ((A.tv_sec == 0) && (A.tv_usec == 0)) 103 106 104 107 void InitPcontrol (); … … 113 116 Host *FindHostPtr (IDtype HostID, int StackID); 114 117 Host *FindHostStack (IDtype HostID); 118 int FindNamedHostStack (char *name); 115 119 Host *PullHost (IDtype HostID, int StackID); 116 120 int FindNamedHost (char *name, int StackID); -
trunk/Ohana/src/opihi/include/psched.h
r4697 r4705 49 49 Macro *crash; /* name is 'crash' */ 50 50 Macro *timeout; 51 Macro *def ;51 Macro *defexit; 52 52 53 53 int NEXIT; … … 115 115 116 116 void InitPsched (); 117 118 117 void InitTasks (); 119 118 Task *NextTask (); … … 132 131 void InitTaskTimers (); 133 132 int TaskHash (char *input); 133 int RemoveTask (Task *task); 134 Task *SetNewTask (Task *task); 134 135 135 136 int NextJobID (); -
trunk/Ohana/src/opihi/lib.data/IOBufferOps.c
r4697 r4705 19 19 buffer[0].Nalloc = buffer[0].Nreset; 20 20 REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc); 21 bzero (buffer[0].buffer, buffer[0].Nalloc); 21 22 22 23 return (TRUE); … … 37 38 REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc); 38 39 Nfree = buffer[0].Nalloc - buffer[0].Nbuffer; 40 bzero (buffer[0].buffer + buffer[0].Nbuffer, Nfree); 39 41 } 40 42 -
trunk/Ohana/src/opihi/lib.shell/MacroOps.c
r3907 r4705 53 53 } 54 54 for (i = 0; i < macro[0].Nlines; i++) { 55 fprintf (stderr, " %s\n", macro[0].line[i]);55 fprintf (stderr, " %s\n", macro[0].line[i]); 56 56 } 57 57 return; -
trunk/Ohana/src/opihi/lib.shell/memstr.c
r4689 r4705 1 1 # include "shell.h" 2 2 3 /* memstr returns a view, not an allocated string : don't free */ 3 4 /* returns pointer to start of m2 in m1, or NULL if failure */ 4 5 char *memstr (char *m1, char *m2, int n) { … … 12 13 13 14 } 15 16 /* formatted write statement, with intelligent allocation */ 17 int write_fmt (int fd, char *format, ...) { 18 19 int Nbyte, status; 20 char tmp, *line; 21 va_list argp; 22 23 va_start (argp, format); 24 Nbyte = vsnprintf (&tmp, 0, format, argp); 25 va_end (argp); 26 27 va_start (argp, format); 28 ALLOCATE (line, char, Nbyte + 1); 29 vsnprintf (line, Nbyte + 1, format, argp); 30 status = write (fd, line, strlen(line)); 31 va_end (argp); 32 33 free (line); 34 return (status); 35 } -
trunk/Ohana/src/opihi/pantasks/CheckJobs.c
r4697 r4705 26 26 case JOB_CRASH: 27 27 /* run task[0].crash macro, if it exists */ 28 /* set the stdout and stderr variables with job.stdout, job.stderr */ 29 /* XXX this will break on 0 values in output streams */ 28 /* push output buffer data to the stdout and stderr queues */ 30 29 if (VerboseMode()) fprintf (stderr, "job %s (%d) crash\n", job[0].task[0].name, job[0].JobID); 31 30 PushNamedQueue ("stdout", job[0].stdout.buffer); 32 31 PushNamedQueue ("stderr", job[0].stderr.buffer); 32 /* XXX this will break on 0 values in output streams */ 33 /* perhaps define PushNamedQueueBuffer */ 33 34 if (job[0].task[0].crash != NULL) { 34 35 exec_loop (job[0].task[0].crash); … … 43 44 PushNamedQueue ("stderr", job[0].stderr.buffer); 44 45 /* run corresponding task[0].exit macro, if it exists */ 45 macro = job[0].task[0].def ;46 macro = job[0].task[0].defexit; 46 47 for (i = 0; i < job[0].task[0].Nexit; i++) { 47 48 if (job[0].exit_status == atoi(job[0].task[0].exit[i][0].name)) { -
trunk/Ohana/src/opihi/pantasks/ControllerOps.c
r4697 r4705 1 1 # include "psched.h" 2 # define CONTROLLER_TIMEOUT 20 2 /* adding a new host can delay controller up to a second or so */ 3 # define CONTROLLER_TIMEOUT 200 3 4 # define CONNECT_TIMEOUT 300 4 5 5 6 /* local static variables to hold the connection to the controller */ 6 static int status = FALSE;7 static int ControllerStatus = FALSE; 7 8 static int stdin_cntl, stdout_cntl, stderr_cntl; 8 9 static IOBuffer stdout_buffer; 9 10 static IOBuffer stderr_buffer; 11 static int ControllerPID = 0; 10 12 11 13 /* test if the controller is running */ 12 14 int CheckControllerStatus () { 13 return ( status);15 return (ControllerStatus); 14 16 } 15 17 … … 29 31 int CheckControllerJobStatus (Job *job) { 30 32 31 int outstate ;33 int outstate, status; 32 34 char cmd[128], status_string[64]; 33 35 char *p; … … 41 43 switch (status) { 42 44 case CONTROLLER_DOWN: 43 fprintf (stderr, "controller is down\n");45 if (VerboseMode()) fprintf (stderr, "controller is down\n"); 44 46 FreeIOBuffer (&buffer); 45 47 return (FALSE); 46 48 47 49 case CONTROLLER_HUNG: 48 fprintf (stderr, "controller is not responding\n");50 if (VerboseMode()) fprintf (stderr, "controller is not responding\n"); 49 51 FreeIOBuffer (&buffer); 50 52 return (FALSE); 51 53 52 54 case CONTROLLER_GOOD: 53 fprintf (stderr, "message received (CheckControllerJobStatus)\n");55 if (VerboseMode()) fprintf (stderr, "message received (CheckControllerJobStatus)\n"); 54 56 break; 55 57 56 58 default: 57 fprintf (stderr, "unknown status for controller command: programming error\n");59 if (VerboseMode()) fprintf (stderr, "unknown status for controller command: programming error\n"); 58 60 exit (1); 59 61 } … … 105 107 106 108 /* send command to get appropriate channel */ 107 ALLOCATE (line, char, MAX (1, strlen(cmd) + 15)); 108 sprintf (line, "%s %d\n", cmd, pid); 109 status = write (stdin_cntl, line, strlen(line)); 110 free (line); 109 status = write_fmt (stdin_cntl, "%s %d\n", cmd, pid); 111 110 112 111 /* is pipe still open? */ … … 126 125 if (status == -1) return (CONTROLLER_HUNG); 127 126 128 fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd);127 if (VerboseMode()) fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 129 128 /* drop extra bytes from pcontrol (not pclient:job) */ 130 129 buffer[0].Nbuffer = Nstart + Nbytes; … … 161 160 162 161 /* construct the controller command portion */ 163 if (!strc mp (job[0].task[0].host, "NONE")) {162 if (!strcasecmp (job[0].task[0].host, "ANYHOST")) { 164 163 sprintf (cmd, "job"); 165 164 } else { … … 177 176 } 178 177 179 fprintf (stderr, "sending command to controller: %s\n", cmd);180 178 InitIOBuffer (&buffer, 0x100); 181 179 ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer); 182 180 free (cmd); 183 184 fprintf (stderr, "response from controller: %s\n", buffer.buffer);185 181 186 182 /* extract the job PID from the controller response */ … … 203 199 char *p; 204 200 char **argv, cmd[128]; 205 int i, pid ;201 int i, pid, status; 206 202 int stdin_fd[2], stdout_fd[2], stderr_fd[2]; 207 203 IOBuffer buffer; 208 204 209 if ( status) return (TRUE);205 if (ControllerStatus) return (TRUE); 210 206 211 207 if (VarConfig ("CONTROLLER", "%s", cmd) == NULL) strcpy (cmd, "pcontrol"); … … 262 258 263 259 /* send handshake command */ 264 sprintf (cmd, "echo CONNECTED\n"); 265 status = write (stdin_fd[1], cmd, strlen(cmd)); 260 status = write_fmt (stdin_fd[1], "echo CONNECTED\n"); 266 261 if ((status == -1) && (errno == EPIPE)) goto pipe_error; 267 262 … … 286 281 InitIOBuffer (&stderr_buffer, 0x100); 287 282 283 ControllerPID = pid; 284 ControllerStatus = TRUE; 288 285 fprintf (stderr, "Connected\n"); 289 286 return (TRUE); … … 316 313 FlushIOBuffer (buffer); 317 314 318 fprintf (stderr, "send: %s\n", cmd); 319 320 /* send command to client (adding on \n) */ 321 ALLOCATE (line, char, MAX (1, strlen(cmd))); 322 sprintf (line, "%s\n", cmd); 323 status = write (stdin_cntl, line, strlen(line)); 324 free (line); 325 326 /* is pipe still open? */ 315 if (VerboseMode()) fprintf (stderr, "send: %s\n", cmd); 316 317 /* send command, is pipe still open? */ 318 status = write_fmt (stdin_cntl, "%s\n", cmd); 327 319 if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN); 328 320 … … 335 327 if (status == -1) usleep (10000); 336 328 } 337 if (status == 0) return (CONTROLLER_DOWN); 329 if (status == 0) { 330 ControllerStatus = FALSE; 331 return (CONTROLLER_DOWN); 332 } 338 333 if (status == -1) return (CONTROLLER_HUNG); 339 /* fprintf (stderr, "buffer.buffer: %s\n", buffer[0].buffer); */ 334 335 /* need to strip off the prompt */ 336 line = memstr (buffer[0].buffer, response, buffer[0].Nbuffer); 337 if (line != NULL) { 338 buffer[0].Nbuffer = line - buffer[0].buffer; 339 bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer); 340 } 340 341 return (CONTROLLER_GOOD); 341 342 } … … 345 346 int Nread; 346 347 347 if (! status) return (TRUE);348 if (!ControllerStatus) return (TRUE); 348 349 349 350 /* read stdout buffer */ … … 390 391 IOBuffer buffer; 391 392 392 if (!C heckControllerStatus()) return (TRUE);393 if (!ControllerStatus) return (TRUE); 393 394 394 395 sprintf (cmd, "kill %d", job[0].pid); … … 403 404 int QuitController () { 404 405 405 int status;406 int i, status, waitstatus, result; 406 407 char cmd[128]; 407 408 IOBuffer buffer; 408 409 409 if (!C heckControllerStatus()) return (TRUE);410 if (!ControllerStatus) return (TRUE); 410 411 411 412 sprintf (cmd, "quit"); 412 413 InitIOBuffer (&buffer, 0x100); 413 414 status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer); 414 return (TRUE); 415 } 416 417 /* memstr returns a view, not an allocated string : don't free */ 415 ControllerStatus = FALSE; 416 result = waitpid (ControllerPID, &waitstatus, WNOHANG); 417 for (i = 0; (i < 10) && (result == 0); i++) { 418 usleep (10000); /* 10 ms is min */ 419 result = waitpid (ControllerPID, &waitstatus, WNOHANG); 420 } 421 ControllerPID = 0; 422 close (stdin_cntl); 423 close (stdout_cntl); 424 close (stderr_cntl); 425 426 return (TRUE); 427 } -
trunk/Ohana/src/opihi/pantasks/JobOps.c
r4693 r4705 50 50 int i; 51 51 52 fprintf (stderr, "\n"); 52 53 if (Njobs == 0) { 53 fprintf (stderr, " no defined jobs\n");54 fprintf (stderr, " no defined jobs\n"); 54 55 return; 55 56 } 56 57 58 fprintf (stderr, " Jobs\n"); 57 59 for (i = 0; i < Njobs; i++) { 58 fprintf (stderr, " %d: %-15s %5d %20s (%lx)\n", Njobs, jobs[i][0].task[0].name, jobs[i][0].JobID, jobs[i][0].argv[0], (long) jobs[i][0].argv);60 fprintf (stderr, " %d: %-15s %5d %20s (%lx)\n", Njobs, jobs[i][0].task[0].name, jobs[i][0].JobID, jobs[i][0].argv[0], (long) jobs[i][0].argv); 59 61 } 60 62 return; … … 76 78 } 77 79 78 /* we need our own copy of task[0].argv 79 * argc is the number of valid args, like the usual command line. 80 * we allocate one extra element, with value 0 to be passed to execvp 80 /* we need our own copy of task[0].argv argc is the number of valid args, like the usual command line. we 81 * allocate one extra element, with value 0 to be passed to execvp 81 82 */ 82 83 job[0].argc = task[0].argc; … … 87 88 job[0].argv[i] = 0; 88 89 89 /* other data from the task is needed by the job 90 we carry a pointer back to the task. this means we 91 cannot modify the task once a job is created, or the changes will 92 be applied to the existing jobs */ 90 /* Other data from the task is needed by the job. We carry a pointer back to the task. Changes to an 91 executing task are applied to the existing jobs (exit macros, poll_period, timeout) */ 93 92 94 93 job[0].task = task; 95 94 96 /* if we decide we need to be able to dynamically set task qualities 97 (like host, timeouts, etc), the we will need to have matched 98 entries to these quantites in the job structure */ 95 /* if we decide we need to be able to dynamically set task qualities (like host, timeouts, etc), the we will 96 need to have matched entries to these quantites in the job structure */ 99 97 100 98 jobs[Njobs] = job; … … 122 120 } 123 121 124 /* * are we deleting the active job?? **/122 /* delete the job from the job list & adjust ActiveJob counter */ 125 123 int DeleteJob (Job *job) { 126 124 … … 140 138 141 139 FreeJob (jobs[Nm]); 142 for (i = Nm + 1; i < Njobs; i++) 143 jobs[i - 1] = jobs[i]; 140 for (i = Nm; i < Njobs - 1; i++) { 141 jobs[i] = jobs[i + 1]; 142 } 144 143 Njobs --; 145 144 -
trunk/Ohana/src/opihi/pantasks/Makefile
r4693 r4705 41 41 $(SDIR)/run.$(ARCH).o \ 42 42 $(SDIR)/stop.$(ARCH).o \ 43 $(SDIR)/pulse.$(ARCH).o \ 43 44 $(SDIR)/status.$(ARCH).o \ 44 45 $(SDIR)/kill.$(ARCH).o \ -
trunk/Ohana/src/opihi/pantasks/TaskOps.c
r4697 r4705 54 54 int i, valid; 55 55 56 fprintf (stderr, "\n"); 56 57 if (Ntasks == 0) { 57 fprintf (stderr, " no defined tasks\n");58 fprintf (stderr, " no defined tasks\n"); 58 59 return; 59 60 } 60 61 61 fprintf (stderr, " Task Status\n");62 fprintf (stderr, " name Njobs command\n");62 fprintf (stderr, " Task Status\n"); 63 fprintf (stderr, " * Name Njobs Command\n"); 63 64 for (i = 0; i < Ntasks; i++) { 64 65 valid = CheckTimeRanges (tasks[i][0].ranges, tasks[i][0].Nranges); 66 if (verbose) fprintf (stderr, "\n"); 65 67 if (valid) { 66 fprintf (stderr, " + ");68 fprintf (stderr, " + "); 67 69 } else { 68 fprintf (stderr, " - ");70 fprintf (stderr, " - "); 69 71 } 70 72 if (tasks[i][0].argv == NULL) { 71 fprintf (stderr, "%-15s % 4d %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, "dynamic");73 fprintf (stderr, "%-15s %5d %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, "(dynamic)"); 72 74 } else { 73 fprintf (stderr, "%-15s % 4d%-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]);75 fprintf (stderr, "%-15s %5d %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]); 74 76 } 75 77 if (verbose) { 76 78 fprintf (stderr, " spawn period: %f, polling period: %f, timeout period: %f\n", 77 tasks[i][0].poll_period, tasks[i][0].poll_period, tasks[i][0].poll_period); 78 if (tasks[i][0].host != NULL) { 79 if (tasks[i][0].host_required) { 80 fprintf (stderr, " host %s (required)\n", tasks[i][0].host); 81 } else { 82 fprintf (stderr, " host %s (desired)\n", tasks[i][0].host); 83 } 79 tasks[i][0].exec_period, tasks[i][0].poll_period, tasks[i][0].timeout_period); 80 if (tasks[i][0].host == NULL) { 81 fprintf (stderr, " task runs locally\n"); 82 continue; 83 } 84 if (!strcasecmp(tasks[i][0].host, "ANYHOST")) { 85 fprintf (stderr, " task host selected by controller\n"); 86 continue; 87 } 88 if (tasks[i][0].host_required) { 89 fprintf (stderr, " host %s (required)\n", tasks[i][0].host); 84 90 } else { 85 fprintf (stderr, " task runs locally\n");86 } 91 fprintf (stderr, " host %s (desired)\n", tasks[i][0].host); 92 } 87 93 } 88 94 } … … 102 108 } 103 109 104 fprintf (stderr, " macro %s\n", task[0].name);105 106 fprintf (stderr, " command: ");110 fprintf (stderr, "\n macro %s\n", task[0].name); 111 112 fprintf (stderr, "\n command: "); 107 113 for (i = 0; i < task[0].argc; i++) { 108 114 fprintf (stderr, "%s ", task[0].argv[i]); 109 115 } 110 111 fprintf (stderr, "host: %s\n", task[0].host); 112 fprintf (stderr, "time periods: exec: %f poll: %f timeout: %f\n", 116 fprintf (stderr, "\n\n"); 117 118 if (task[0].host == NULL) { 119 fprintf (stderr, " task runs locally\n"); 120 goto periods; 121 } 122 if (!strcasecmp(task[0].host, "ANYHOST")) { 123 fprintf (stderr, " task host selected by controller\n"); 124 goto periods; 125 } 126 if (task[0].host_required) { 127 fprintf (stderr, " host %s (required)\n", task[0].host); 128 } else { 129 fprintf (stderr, " host %s (desired)\n", task[0].host); 130 } 131 132 periods: 133 fprintf (stderr, " time periods: exec: %f poll: %f timeout: %f\n", 113 134 task[0].exec_period, task[0].poll_period, task[0].timeout_period); 114 135 115 fprintf (stderr, " pre-execute macro\n");136 fprintf (stderr, "\n pre-execute macro\n"); 116 137 ListMacro (task[0].exec); 117 138 118 fprintf (stderr, " timeout macro\n");139 fprintf (stderr, "\n timeout macro\n"); 119 140 ListMacro (task[0].timeout); 120 141 121 fprintf (stderr, " crash macro\n");142 fprintf (stderr, "\n crash macro\n"); 122 143 ListMacro (task[0].crash); 123 144 124 fprintf (stderr, " default exit macro\n");125 ListMacro (task[0].def );145 fprintf (stderr, "\n default exit macro\n"); 146 ListMacro (task[0].defexit); 126 147 127 148 for (i = 0; i < task[0].Nexit; i++) { 128 fprintf (stderr, " exit macro (status == %d)\n", atoi(task[0].exit[i][0].name));149 fprintf (stderr, "\n exit macro (status == %d)\n", atoi(task[0].exit[i][0].name)); 129 150 ListMacro (task[0].exit[i]); 130 151 } … … 192 213 NewTask[0].crash = NULL; 193 214 NewTask[0].timeout = NULL; 215 NewTask[0].defexit = NULL; 194 216 195 217 NewTask[0].Nexit = 0; … … 211 233 212 234 return (NewTask); 235 } 236 237 /* remove the task from the task list */ 238 int RemoveTask (Task *task) { 239 240 int i, Nt; 241 242 /* find task in task list */ 243 Nt = -1; 244 for (i = 0; i < Ntasks; i++) { 245 if (task == tasks[i]) { 246 Nt = i; 247 break; 248 } 249 } 250 if (Nt == -1) { 251 fprintf (stderr, "programming error: task not found\n"); 252 return (FALSE); 253 } 254 for (i = Nt; i < Ntasks - 1; i++) { 255 tasks[i] = tasks[i+1]; 256 } 257 Ntasks --; 258 return (TRUE); 213 259 } 214 260 … … 263 309 } 264 310 return (TRUE); 311 } 312 313 Task *SetNewTask (Task *task) { 314 NewTask = task; 315 return (task); 265 316 } 266 317 -
trunk/Ohana/src/opihi/pantasks/controller_check.c
r4693 r4705 21 21 InitIOBuffer (&buffer, 0x100); 22 22 status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer); 23 if (VerboseMode()) { 24 fprintf (stderr, "controller command sent\n"); 25 fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr); 26 fprintf (stderr, "\n Nbytes received: %d\n", buffer.Nbuffer); 27 } 23 28 FreeIOBuffer (&buffer); 24 29 … … 34 39 35 40 case CONTROLLER_GOOD: 36 fprintf (stderr, "controller command sent\n");37 fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);38 41 return (TRUE); 39 42 -
trunk/Ohana/src/opihi/pantasks/controller_host.c
r4693 r4705 7 7 IOBuffer buffer; 8 8 9 if (argc != 2) {10 fprintf (stderr, "USAGE: controller host ( hostname)\n");9 if (argc != 3) { 10 fprintf (stderr, "USAGE: controller host (command) (hostname)\n"); 11 11 return (FALSE); 12 12 } … … 15 15 StartController (); 16 16 17 sprintf (command, "host %s ", argv[1]);17 sprintf (command, "host %s %s", argv[1], argv[2]); 18 18 InitIOBuffer (&buffer, 0x100); 19 19 status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer); 20 fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr); 20 21 FreeIOBuffer (&buffer); 21 22 … … 31 32 32 33 case CONTROLLER_GOOD: 33 fprintf (stderr, "controller command sent\n");34 fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);35 fprintf (stderr, "\n Nbytes received: %d\n", buffer.Nbuffer);36 34 return (TRUE); 37 35 -
trunk/Ohana/src/opihi/pantasks/controller_status.c
r4693 r4705 22 22 InitIOBuffer (&buffer, 0x100); 23 23 status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer); 24 FreeIOBuffer (&buffer);25 24 26 25 /* check on success of controller command */ … … 28 27 case CONTROLLER_DOWN: 29 28 fprintf (stderr, "controller is down\n"); 29 FreeIOBuffer (&buffer); 30 30 return (FALSE); 31 31 32 32 case CONTROLLER_HUNG: 33 33 fprintf (stderr, "controller is not responding\n"); 34 FreeIOBuffer (&buffer); 34 35 return (FALSE); 35 36 36 37 case CONTROLLER_GOOD: 37 fprintf (stderr, "controller command sent\n");38 38 fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr); 39 fprintf (stderr, "\n Nbytes received: %d\n", buffer.Nbuffer);39 FreeIOBuffer (&buffer); 40 40 return (TRUE); 41 41 -
trunk/Ohana/src/opihi/pantasks/init.c
r4693 r4705 11 11 int run PROTO((int, char **)); 12 12 int stop PROTO((int, char **)); 13 int pulse PROTO((int, char **)); 13 14 int status_sys PROTO((int, char **)); 14 15 int kill_job PROTO((int, char **)); … … 28 29 {"run", run, "run the scheduler"}, 29 30 {"stop", stop, "stop the scheduler"}, 31 {"pulse", pulse, "set the scheduler update period"}, 30 32 {"status", status_sys, "get system status"}, 31 33 {"kill", kill_job, "kill job"}, -
trunk/Ohana/src/opihi/pantasks/psched.c
r4693 r4705 39 39 rl_attempted_completion_function = command_completer; 40 40 rl_event_hook = NULL; 41 rl_set_keyboard_input_timeout (100000 0);41 rl_set_keyboard_input_timeout (100000); 42 42 43 43 set_str_variable ("HISTORY", opihi_history); -
trunk/Ohana/src/opihi/pantasks/run.c
r4693 r4705 10 10 InitTaskTimers (); 11 11 rl_event_hook = CheckSystem; 12 rl_set_keyboard_input_timeout (1000000);13 12 14 13 return (TRUE); -
trunk/Ohana/src/opihi/pantasks/status.c
r4693 r4705 3 3 int status_sys (int argc, char **argv) { 4 4 5 fprintf (stderr, "\n"); 5 6 if (rl_event_hook == NULL) { 6 fprintf (stderr, " scheduler is stopped\n");7 fprintf (stderr, " Scheduler is stopped\n"); 7 8 } else { 8 fprintf (stderr, "scheduler is running\n"); 9 fprintf (stderr, " Scheduler is running\n"); 10 } 11 if (CheckControllerStatus ()) { 12 fprintf (stderr, " Controller is running\n"); 13 } else { 14 fprintf (stderr, " Controller is stopped\n"); 9 15 } 10 16 ListTasks (FALSE); -
trunk/Ohana/src/opihi/pantasks/stop.c
r4693 r4705 9 9 10 10 rl_event_hook = NULL; 11 rl_set_keyboard_input_timeout (1000000);12 11 13 12 return (TRUE); -
trunk/Ohana/src/opihi/pantasks/task.c
r4697 r4705 36 36 if (task == NULL) { /**** new task ****/ 37 37 task = CreateTask (argv[1]); 38 } else { 39 RemoveTask (task); 40 SetNewTask (task); 38 41 } 39 /* temporary task is saved statically 40 add to list after definition is complete */ 42 /* While a task is being defined, it is removed from the task list. The new task is added to the task list 43 when the definition process is complete. 44 XXX If an outstanding job has a task deleted, it will not be able to complete... */ 41 45 42 46 /* read in task from appropriate source (keyboard or list) until end */ 43 47 44 /* allowed tokens: command, host, stderr, periods, end */48 /* allowed tokens: command, host, stderr, periods, trange, nmax, task.exit, task.exec, end */ 45 49 46 50 ThisList = Nlists; -
trunk/Ohana/src/opihi/pantasks/task_command.c
r4697 r4705 8 8 if (argc < 2) { 9 9 fprintf (stderr, "USAGE: command <command> <arg>. ..\n"); 10 fprintf (stderr, " (define command machine for this task (or 'none'))\n");10 fprintf (stderr, " (define command for this task)\n"); 11 11 return (FALSE); 12 12 } -
trunk/Ohana/src/opihi/pantasks/task_host.c
r4693 r4705 17 17 fprintf (stderr, " -required flags indicates controller must use this host\n"); 18 18 fprintf (stderr, " value of 'local' for host indicates process not using controller\n"); 19 fprintf (stderr, " value of ' none' for host indicates controller may assign at will\n");19 fprintf (stderr, " value of 'anyhost' for host indicates controller may assign at will\n"); 20 20 return (FALSE); 21 21 } … … 23 23 task = GetNewTask (); 24 24 if (task == NULL) { 25 fprintf (stderr, "ERROR: not defining or running a task\n"); 26 return (FALSE); 25 task = GetActiveTask (); 26 if (task == NULL) { 27 fprintf (stderr, "ERROR: not defining or running a task\n"); 28 return (FALSE); 29 } 27 30 } 28 31 task[0].host_required = RequiredHost; … … 36 39 return (TRUE); 37 40 } 41 42 /* apparently, local is the default! */ -
trunk/Ohana/src/opihi/pantasks/task_macros.c
r4693 r4705 62 62 } 63 63 if (!strcmp (argv[0], "task.exit") && !strcmp (argv[1], "default")) { 64 if (task[0].def != NULL) {65 FreeMacro (task[0].def );66 free (task[0].def );64 if (task[0].defexit != NULL) { 65 FreeMacro (task[0].defexit); 66 free (task[0].defexit); 67 67 } 68 ALLOCATE (task[0].def , Macro, 1);69 macro = task[0].def ;68 ALLOCATE (task[0].defexit, Macro, 1); 69 macro = task[0].defexit; 70 70 macro[0].name = strcreate ("default"); 71 71 goto found; -
trunk/Ohana/src/opihi/pcontrol/CheckIdleHost.c
r4689 r4705 45 45 return (TRUE); 46 46 } 47 /* no jobs for host, but back on IDLE stack */ 48 PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM); 47 49 return (TRUE); 48 50 } -
trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
r4689 r4705 93 93 Stack *stack; 94 94 Host *host; 95 struct timeval now; 96 float delta; 97 98 gettimeofday (&now, (void *) NULL); 95 99 96 100 stack = GetHostStack (PCONTROL_HOST_DOWN); … … 99 103 for (i = 0; i < Nobject; i++) { 100 104 host = GetStack (stack, STACK_TOP); 101 StartHost (host); 105 delta = DTIME (host[0].nexttry, now); 106 if (delta > 0) { 107 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 108 } else { 109 StartHost (host); 110 } 102 111 } 103 112 return (TRUE); -
trunk/Ohana/src/opihi/pcontrol/GetJobOutput.c
r4575 r4705 14 14 15 15 /* send cmd (stdout / stderr) */ 16 ALLOCATE (line, char, MAX (1, strlen(cmd) + 1)); 17 sprintf (line, "%s\n", cmd); 18 status = write (host[0].stdin, line, strlen(line)); 19 free (line); 16 status = write_fmt (host[0].stdin, "%s\n", cmd); 20 17 21 18 /* is pipe still open? */ -
trunk/Ohana/src/opihi/pcontrol/HostOps.c
r4573 r4705 57 57 } 58 58 59 int FindNamedHostStack (char *name) { 60 61 int N; 62 63 N = FindNamedHost (name, PCONTROL_HOST_IDLE); 64 if (N > 0) return (PCONTROL_HOST_IDLE); 65 66 N = FindNamedHost (name, PCONTROL_HOST_DOWN); 67 if (N > 0) return (PCONTROL_HOST_DOWN); 68 69 N = FindNamedHost (name, PCONTROL_HOST_DONE); 70 if (N > 0) return (PCONTROL_HOST_DONE); 71 72 N = FindNamedHost (name, PCONTROL_HOST_BUSY); 73 if (N > 0) return (PCONTROL_HOST_BUSY); 74 75 N = FindNamedHost (name, PCONTROL_HOST_OFF); 76 if (N > 0) return (PCONTROL_HOST_OFF); 77 78 return (-1); 79 } 80 59 81 int PutHost (Host *host, int StackID, int where) { 60 82 … … 165 187 host[0].HostID = NextHostID(); 166 188 189 host[0].lasttry.tv_sec = 0; 190 host[0].lasttry.tv_usec = 0; 191 host[0].nexttry.tv_sec = 0; 192 host[0].nexttry.tv_usec = 0; 193 167 194 host[0].markoff = FALSE; 168 195 host[0].job = NULL; -
trunk/Ohana/src/opihi/pcontrol/JobOps.c
r4689 r4705 161 161 162 162 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 163 fprintf (stderr, "added new job\n"); 163 164 return (job[0].JobID); 164 165 } -
trunk/Ohana/src/opihi/pcontrol/StartHost.c
r4689 r4705 1 1 # include "pcontrol.h" 2 # define RETRY_BASE 1.0 2 3 3 4 int StartHost (Host *host) { … … 6 7 int stdio[3]; 7 8 char command[64], shell[64]; 8 9 /* pid = rconnect (CONNECT, host[0].hostname, PCLIENT, stdio); */9 struct timeval now; 10 float delta; 10 11 11 12 /* perhaps change the name of these config variables... */ … … 14 15 15 16 pid = rconnect (command, host[0].hostname, shell, stdio); 16 if (!pid) { /** failure to start **/ 17 if (!pid) { 18 /** failure to start: extend retry period **/ 17 19 if (VerboseMode()) fprintf (stderr, "failure to start %s\n", host[0].hostname); 20 gettimeofday (&now, (void *) NULL); 21 if (ZTIME(host[0].nexttry) || ZTIME(host[0].lasttry)) { 22 /* reset retry period if either is zero */ 23 delta = RETRY_BASE; 24 } else { 25 delta = 2*DTIME (host[0].nexttry, host[0].lasttry); 26 } 27 host[0].nexttry.tv_sec = now.tv_sec + delta; 28 host[0].nexttry.tv_usec = now.tv_usec; 29 host[0].lasttry.tv_sec = now.tv_sec; 30 host[0].lasttry.tv_usec = now.tv_usec; 18 31 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 19 32 return (FALSE); 20 33 } 34 host[0].nexttry.tv_sec = 0; 35 host[0].nexttry.tv_usec = 0; 36 host[0].lasttry.tv_sec = 0; 37 host[0].lasttry.tv_usec = 0; 38 21 39 host[0].stdin = stdio[0]; 22 40 host[0].stdout = stdio[1]; -
trunk/Ohana/src/opihi/pcontrol/host.c
r4689 r4705 3 3 int host (int argc, char **argv) { 4 4 5 int N, Ns; 5 6 IDtype HostID; 6 int N, Delete, Off, On, Start, Stop, Check;7 7 Host *host; 8 8 9 /* this section needs some help: find the specified host in the stacks */ 10 Delete = FALSE; 11 if ((N = get_argument (argc, argv, "-delete"))) { 12 remove_argument (N, &argc, argv); 13 Delete = TRUE; 9 if (argc != 3) { 10 fprintf (stdout, "USAGE: host (command) (hostname)\n"); 11 return (FALSE); 14 12 } 15 16 /* this section needs some help: find the specified host in the stacks */ 17 Off = FALSE; 18 if ((N = get_argument (argc, argv, "-off"))) { 19 if (Delete) { 20 fprintf (stdout, "-delete and -off incompatible\n"); 13 14 if (!strcasecmp (argv[1], "ADD")) { 15 HostID = AddHost (argv[2]); 16 fprintf (stdout, "HostID: %d\n", (int) HostID); 17 return (TRUE); 18 } 19 if (!strcasecmp (argv[1], "ON")) { 20 N = FindNamedHost (argv[2], PCONTROL_HOST_OFF); 21 if (N < 0) { 22 fprintf (stdout, "host %s is not OFF\n", argv[2]); 21 23 return (FALSE); 22 24 } 23 remove_argument (N, &argc, argv); 24 Off = TRUE; 25 host = GetHost (PCONTROL_HOST_OFF, N); 26 DownHost (host); 27 return (TRUE); 25 28 } 26 27 /* this section needs some help: find the specified host in the stacks */ 28 On = FALSE; 29 if ((N = get_argument (argc, argv, "-on"))) { 30 if (Delete || Off) { 31 fprintf (stdout, "only one of -delete, -off, -on\n"); 29 if (!strcasecmp (argv[1], "RETRY")) { 30 N = FindNamedHost (argv[2], PCONTROL_HOST_DOWN); 31 if (N < 0) { 32 fprintf (stdout, "host %s is not DOWN\n", argv[2]); 32 33 return (FALSE); 33 34 } 34 remove_argument (N, &argc, argv); 35 On = TRUE; 35 host = GetHost (PCONTROL_HOST_DOWN, N); 36 host[0].nexttry.tv_sec = 0; 37 host[0].nexttry.tv_usec = 0; 38 host[0].lasttry.tv_sec = 0; 39 host[0].lasttry.tv_usec = 0; 40 StartHost (host); 41 return (TRUE); 36 42 } 37 38 /* this section needs some help: find the specified host in the stacks */ 39 Start = FALSE; 40 if ((N = get_argument (argc, argv, "-start"))) { 41 remove_argument (N, &argc, argv); 42 Start = TRUE; 43 } 44 45 /* this section needs some help: find the specified host in the stacks */ 46 Check = FALSE; 47 if ((N = get_argument (argc, argv, "-check"))) { 48 remove_argument (N, &argc, argv); 49 Check = TRUE; 50 } 51 52 /* this section needs some help: find the specified host in the stacks */ 53 Stop = FALSE; 54 if ((N = get_argument (argc, argv, "-stop"))) { 55 remove_argument (N, &argc, argv); 56 Stop = TRUE; 57 } 58 59 if (argc != 2) { 60 fprintf (stdout, "USAGE: host (hostname) [-delete]\n"); 43 if (!strcasecmp (argv[1], "CHECK")) { 44 Ns = FindNamedHostStack (argv[2]); 45 switch (Ns) { 46 case PCONTROL_HOST_IDLE: 47 case PCONTROL_HOST_BUSY: 48 case PCONTROL_HOST_DONE: 49 N = FindNamedHost (argv[2], Ns); 50 host = GetHost (Ns, N); 51 CheckHost (host); 52 return (TRUE); 53 case PCONTROL_HOST_DOWN: 54 fprintf (stdout, "host %s is DOWN\n", argv[2]); 55 return (TRUE); 56 case PCONTROL_HOST_OFF: 57 fprintf (stdout, "host %s is OFF\n", argv[2]); 58 return (TRUE); 59 default: 60 fprintf (stdout, "host %s not found\n", argv[2]); 61 return (FALSE); 62 } 61 63 return (FALSE); 62 64 } 63 64 if (Delete) { 65 N = FindNamedHost (argv[1], PCONTROL_HOST_OFF); 65 if (!strcasecmp (argv[1], "OFF")) { 66 N = FindNamedHost (argv[2], PCONTROL_HOST_IDLE); 67 if (N >= 0) { 68 host = GetHost (PCONTROL_HOST_IDLE, N); 69 StopHost (host); 70 OffHost (host); 71 return (TRUE); 72 } 73 N = FindNamedHost (argv[2], PCONTROL_HOST_DOWN); 74 if (N >= 0) { 75 host = GetHost (PCONTROL_HOST_DOWN, N); 76 OffHost (host); 77 return (TRUE); 78 } 79 N = FindNamedHost (argv[2], PCONTROL_HOST_BUSY); 80 if (N >= 0) { 81 host = GetHost (PCONTROL_HOST_BUSY, N); 82 host[0].markoff = TRUE; 83 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 84 return (TRUE); 85 } 86 fprintf (stdout, "host %s is not BUSY, IDLE, or DOWN\n", argv[2]); 87 return (FALSE); 88 } 89 if (!strcasecmp (argv[1], "DELETE")) { 90 N = FindNamedHost (argv[2], PCONTROL_HOST_OFF); 66 91 if (N < 0) { 67 fprintf (stdout, "host %s is not OFF\n", argv[ 1]);92 fprintf (stdout, "host %s is not OFF\n", argv[2]); 68 93 return (FALSE); 69 94 } … … 72 97 return (TRUE); 73 98 } 74 75 if (On) { 76 N = FindNamedHost (argv[1], PCONTROL_HOST_OFF); 77 if (N < 0) { 78 fprintf (stdout, "host %s is not OFF\n", argv[1]); 79 return (FALSE); 80 } 81 host = GetHost (PCONTROL_HOST_OFF, N); 82 DownHost (host); 83 return (TRUE); 84 } 85 86 if (Check) { 87 N = FindNamedHost (argv[1], PCONTROL_HOST_IDLE); 88 if (N >= 0) { 89 host = GetHost (PCONTROL_HOST_IDLE, N); 90 CheckHost (host); 91 return (TRUE); 92 } 93 N = FindNamedHost (argv[1], PCONTROL_HOST_BUSY); 94 if (N >= 0) { 95 host = GetHost (PCONTROL_HOST_BUSY, N); 96 CheckHost (host); 97 return (TRUE); 98 } 99 fprintf (stdout, "host %s is not BUSY or IDLE\n", argv[1]); 100 return (FALSE); 101 } 102 103 if (Start) { 104 N = FindNamedHost (argv[1], PCONTROL_HOST_DOWN); 105 if (N < 0) { 106 fprintf (stdout, "host %s is not DOWN\n", argv[1]); 107 return (FALSE); 108 } 109 host = GetHost (PCONTROL_HOST_DOWN, N); 110 StartHost (host); 111 return (TRUE); 112 } 113 if (Stop) { 114 N = FindNamedHost (argv[1], PCONTROL_HOST_IDLE); 115 if (N < 0) { 116 fprintf (stdout, "host %s is not IDLE\n", argv[1]); 117 return (FALSE); 118 } 119 host = GetHost (PCONTROL_HOST_IDLE, N); 120 StopHost (host); 121 DownHost (host); 122 return (TRUE); 123 } 124 125 if (Off) { 126 N = FindNamedHost (argv[1], PCONTROL_HOST_IDLE); 127 if (N >= 0) { 128 host = GetHost (PCONTROL_HOST_IDLE, N); 129 StopHost (host); 130 OffHost (host); 131 return (TRUE); 132 } 133 N = FindNamedHost (argv[1], PCONTROL_HOST_DOWN); 134 if (N >= 0) { 135 host = GetHost (PCONTROL_HOST_DOWN, N); 136 OffHost (host); 137 return (TRUE); 138 } 139 N = FindNamedHost (argv[1], PCONTROL_HOST_BUSY); 140 if (N >= 0) { 141 host = GetHost (PCONTROL_HOST_BUSY, N); 142 host[0].markoff = TRUE; 143 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 144 return (TRUE); 145 } 146 fprintf (stdout, "host %s is not BUSY, IDLE, or DOWN\n", argv[1]); 147 return (FALSE); 148 } 149 150 HostID = AddHost (argv[1]); 151 fprintf (stdout, "HostID: %d\n", (int) HostID); 152 return (TRUE); 99 100 fprintf (stderr, "unknown host command %s\n", argv[1]); 101 fprintf (stderr, "valid options: xxx\n"); 102 return (FALSE); 153 103 } -
trunk/Ohana/src/opihi/pcontrol/pclient.c
r4573 r4705 12 12 13 13 /* send command to client (adding on \n) */ 14 /* fprintf (stderr, "send: %s (%d)\n", command, buffer[0].Nbuffer); */ 15 ALLOCATE (line, char, MAX (1, strlen(command) + 1)); 16 sprintf (line, "%s\n", command); 17 status = write (host[0].stdin, line, strlen(line)); 18 free (line); 14 status = write_fmt (host[0].stdin, "%s\n", command); 19 15 20 16 /* is pipe still open? */ -
trunk/Ohana/src/opihi/pcontrol/rconnect.c
r4689 r4705 10 10 11 11 int i, stdin_fd[2], stdout_fd[2], stderr_fd[2], status; 12 int result, waitstatus; 12 13 pid_t pid; 13 14 char *p; … … 69 70 70 71 /* send handshake command */ 71 sprintf (command, "echo CONNECTED\n"); 72 status = write (stdin_fd[1], command, strlen(command)); 73 if ((status == -1) && (errno == EPIPE)) goto pipe_error; 72 status = write_fmt (stdin_fd[1], "echo CONNECTED\n"); 73 if ((status == -1) && (errno == EPIPE)) goto connect_error; 74 74 75 75 /* try to get evidence connection is alive - wait upto a few seconds */ … … 81 81 usleep (20000); 82 82 } 83 if (status == 0) goto connect_error; 84 if (status == -1) goto connect_error; 83 85 if (VerboseMode()) fprintf (stderr, "%d cycles to connect\n", i); 84 if (status == 0) goto pipe_error;85 if (status == -1) goto io_error;86 86 FreeIOBuffer (&buffer); 87 87 … … 98 98 goto close_pipes; 99 99 100 io_error: 101 if (VerboseMode()) fprintf (stderr, "timeout while connecting\n"); 102 goto close_pipes; 100 connect_error: 101 if (VerboseMode()) fprintf (stderr, "error while connecting\n"); 102 103 /* harvest the child process: kill & wait (< 100 ms) for exit */ 104 kill (pid, SIGKILL); 105 result = waitpid (pid, &waitstatus, WNOHANG); 106 for (i = 0; (i < 10) && (result == 0); i++) { 107 usleep (10000); /* 10 ms is min */ 108 result = waitpid (pid, &waitstatus, WNOHANG); 109 } 110 111 if ((result == -1) && (errno != ECHILD)) { 112 fprintf (stderr, "unexpected error from waitpid (%d): programming error\n", errno); 113 exit (1); 114 } 115 if (result == 0) { 116 if (VerboseMode()) fprintf (stderr, "child did not exit??"); 117 } 118 if (result > 0) { 119 if (result != pid) { 120 fprintf (stderr, "waitpid error: mis-matched PID (%d vs %d). programming error\n", result, pid); 121 exit (1); 122 } 123 if (WIFSTOPPED(waitstatus)) { 124 fprintf (stderr, "waitpid returns 'stopped': programming error\n"); 125 exit (1); 126 } 127 } 103 128 104 129 close_pipes:
Note:
See TracChangeset
for help on using the changeset viewer.
