Changeset 4684
- Timestamp:
- Jul 31, 2005, 8:04:11 AM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 1 added
- 23 edited
-
include/dvo1.h (modified) (1 diff)
-
include/pclient.h (modified) (1 diff)
-
include/pcontrol.h (modified) (1 diff)
-
include/scheduler.h (modified) (3 diffs)
-
pantasks/CheckJobs.c (modified) (3 diffs)
-
pantasks/CheckTasks.c (modified) (2 diffs)
-
pantasks/ControllerOps.c (modified) (2 diffs)
-
pantasks/JobIDOps.c (added)
-
pantasks/JobOps.c (modified) (11 diffs)
-
pantasks/LocalJob.c (modified) (3 diffs)
-
pantasks/Makefile (modified) (1 diff)
-
pantasks/TaskOps.c (modified) (3 diffs)
-
pantasks/kill.c (modified) (1 diff)
-
pantasks/scheduler.c (modified) (2 diffs)
-
pantasks/status.c (modified) (1 diff)
-
pantasks/task.c (modified) (4 diffs)
-
pantasks/task_command.c (modified) (2 diffs)
-
pantasks/task_host.c (modified) (1 diff)
-
pantasks/task_macros.c (modified) (2 diffs)
-
pantasks/task_nmax.c (modified) (1 diff)
-
pantasks/task_periods.c (modified) (2 diffs)
-
pantasks/task_trange.c (modified) (2 diffs)
-
pcontrol/delete.c (modified) (1 diff)
-
pcontrol/kill.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/dvo1.h
r4606 r4684 1 # include "external.h" 2 # include "shell.h" 3 # include "dvomath.h" 4 # include "convert.h" 5 # include "display.h" 1 # include "opihi.h" 6 2 # include "data.h" 7 3 -
trunk/Ohana/src/opihi/include/pclient.h
r3211 r4684 1 # include "external.h" 2 # include "shell.h" 3 # include "dvomath.h" 4 # include "convert.h" 5 # include "display.h" 1 # include "opihi.h" 6 2 # include <sys/types.h> 7 3 # include <sys/wait.h> -
trunk/Ohana/src/opihi/include/pcontrol.h
r4573 r4684 1 # include "external.h" 2 # include "shell.h" 3 # include "dvomath.h" 4 # include "convert.h" 5 # include "display.h" 1 # include "opihi.h" 6 2 # include <sys/types.h> 7 3 # include <sys/wait.h> -
trunk/Ohana/src/opihi/include/scheduler.h
r4603 r4684 1 # include "external.h" 2 # include "shell.h" 3 # include "dvomath.h" 4 # include "convert.h" 5 # include "display.h" 1 # include "opihi.h" 6 2 # include <sys/types.h> 7 3 # include <sys/wait.h> … … 11 7 JOB_BUSY, 12 8 JOB_EXIT, 9 JOB_HUNG, 13 10 JOB_CRASH, 14 11 JOB_PENDING, … … 113 110 114 111 /* scheduler prototypes */ 115 void InitTasks (); 116 void ListTasks (); 117 Task *FindTask (char *name); 118 Task *CreateTask (char *name); 119 void SetCurrentTask (char *name); 120 char *GetCurrentTask (); 121 int DeleteTask (Task *task); 122 Task *NextTask (); 123 int TaskHash (char *input); 124 int ShowTask (char *name); 112 125 113 char *memstr (char *m1, char *m2, int n); 126 114 115 void InitTasks (); 116 Task *NextTask (); 117 Task *FindTask (char *name); 118 void ListTasks (int verbose); 119 int ShowTask (char *name); 120 int FreeTask (Task *task); 121 Task *CreateTask (char *name); 122 int ValidateTask (Task *task); 123 int RegisterNewTask (); 124 int DeleteNewTask (); 125 Task *GetNewTask (); 126 void SetTaskTimer (struct timeval *timer); 127 double GetTaskTimer (struct timeval start); 128 void InitTaskTimers (); 129 int TaskHash (char *input); 130 131 int NextJobID (); 132 int InitJobIDs (); 133 int FreeJobID (int ID); 134 135 void InitJobs (); 127 136 Job *NextJob (); 128 void InitJobs (); 129 int NextJobID (); 137 Job *FindJob (int JobID); 130 138 void ListJobs (); 131 Job *FindJob (int JobID);132 139 Job *CreateJob (Task *task); 133 void SetCurrentJob (char *name);134 char *GetCurrentJob ();135 140 int SubmitJob (Job *job); 136 141 int CheckJob (Job *job); 137 142 int DeleteJob (Job *job); 138 143 void FreeJob (Job *job); 139 void SetTaskTimer (struct timeval *timer);140 double GetTaskTimer (struct timeval start);141 144 142 145 int CheckJobs (); -
trunk/Ohana/src/opihi/pantasks/CheckJobs.c
r4602 r4684 12 12 while ((job = NextJob ()) != NULL) { 13 13 14 /* check for timeout - only local jobs timeout here */ 15 if ((job[0].mode == JOB_LOCAL) && (GetTaskTimer(job[0].start) >= job[0].task[0].timeout_period)) { 16 if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name); 17 /* run task[0].timeout macro, if it exists */ 18 if (job[0].task[0].timeout != NULL) { 19 exec_loop (job[0].task[0].timeout); 20 } 21 DeleteJob (job); 22 continue; 23 } 24 25 /* check poll period (ready to run again?) */ 14 /* check poll period (ready to ask for status?) */ 26 15 if (GetTaskTimer(job[0].last) < job[0].task[0].poll_period) continue; 27 16 … … 74 63 } 75 64 65 /* check for timeout - (local jobs only) 66 we only check timeout after a poll (forces at least one poll) 67 */ 68 if (job[0].mode == JOB_LOCAL) { 69 if (GetTaskTimer(job[0].start) < job[0].task[0].timeout_period) continue; 70 if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name); 71 if (!KillLocalJob (job)) { 72 job[0].state = JOB_HUNG; 73 if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid); 74 continue; 75 } 76 /* run task[0].timeout macro, if it exists */ 77 if (job[0].task[0].timeout != NULL) { 78 exec_loop (job[0].task[0].timeout); 79 } 80 DeleteJob (job); 81 continue; 82 } 83 76 84 /* reset polling clock */ 77 85 SetTaskTimer (&job[0].last); … … 79 87 return (TRUE); 80 88 } 89 90 /* 91 92 job / task timeline: 93 94 task: 95 0 exec 96 start create 97 task clock new job 98 99 job: 100 0 1xpoll 2xpoll 3xpoll 101 start check check check 102 job clock status status status 103 104 . . . timeout 105 run 106 timeout 107 108 must be at least one poll before timeout 109 (timeout >= poll) 110 */ -
trunk/Ohana/src/opihi/pantasks/CheckTasks.c
r4603 r4684 19 19 if (task[0].Nmax && (task[0].Njobs >= task[0].Nmax)) continue; 20 20 21 SetCurrentTask (task[0].name);22 23 21 /* ready to run? : run task.exec macro */ 24 22 if (task[0].exec != NULL) { … … 26 24 if (!status) continue; 27 25 } 28 29 /* is task valid? check state of task.(argc, argv) */30 /*** ADD CODE HERE ***/31 26 32 27 /* construct job from task */ -
trunk/Ohana/src/opihi/pantasks/ControllerOps.c
r4602 r4684 58 58 if (p != NULL) { 59 59 fprintf (stderr, "unknown job %d\n", job[0].pid); 60 FreeIOBuffer (&buffer); 60 61 return (FALSE); 61 62 } … … 384 385 385 386 387 int KillControllerJob (Job *job) { 388 389 int status; 390 char cmd[128]; 391 IOBuffer buffer; 392 393 sprintf (cmd, "kill %d", job[0].pid); 394 InitIOBuffer (&buffer, 0x100); 395 status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer); 396 397 /** need to interpret output message & free things **/ 398 FreeIOBuffer (&buffer); 399 return (TRUE); 400 } 401 386 402 /* memstr returns a view, not an allocated string : don't free */ -
trunk/Ohana/src/opihi/pantasks/JobOps.c
r4450 r4684 1 1 # include "scheduler.h" 2 2 3 # define MAX_N_JOBS 1000 4 static char *JobIDList;5 static int JobIDPtr = 0;3 static Job **jobs; 4 static int Njobs; 5 static int NJOBS; 6 6 7 static char dot[] = "."; 7 /* counter marking job being visited by the run loop */ 8 static int ActiveJob; 8 9 9 static Job *jobs; 10 static int Njobs; 11 static int NJOBS; 12 13 static char *JobName = dot; 14 static int CurrentJob = 0; 10 /* set up the jobs list */ 11 void InitJobs () { 12 NJOBS = 20; 13 Njobs = 0; 14 ALLOCATE (jobs, Job *, NJOBS); 15 ActiveJob = -1; 16 } 15 17 16 18 /* provide a mechanism to loop over the list of jobs */ … … 19 21 Job *job; 20 22 21 if (CurrentJob >= Njobs) { 22 CurrentJob = 0; 23 ActiveJob ++; 24 if (ActiveJob < 0) ActiveJob = 0; 25 if (ActiveJob >= Njobs) { 26 ActiveJob = -1; 23 27 return (NULL); 24 28 } 25 26 job = &jobs[CurrentJob]; 27 CurrentJob ++; 29 job = jobs[ActiveJob]; 28 30 return (job); 29 }30 31 void InitJobs () {32 NJOBS = 20;33 Njobs = 0;34 ALLOCATE (jobs, Job, NJOBS);35 JobName = dot;36 37 ALLOCATE (JobIDList, char, MAX_N_JOBS);38 bzero (JobIDList, MAX_N_JOBS*sizeof(char));39 }40 41 /* return next unique ID, recycle every MAX_N_JOBS */42 int NextJobID () {43 44 int Ntry;45 46 JobIDPtr ++;47 if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;48 49 Ntry = 0;50 while (JobIDList[JobIDPtr]) {51 Ntry ++;52 JobIDPtr ++;53 if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;54 if (Ntry == MAX_N_JOBS) return (-1);55 }56 JobIDList[JobIDPtr] = TRUE;57 return (JobIDPtr);58 }59 60 /* list known jobs */61 void ListJobs () {62 63 int i;64 65 for (i = 0; i < Njobs; i++) {66 fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task[0].name, jobs[i].JobID, jobs[i].argv[0], jobs[i].argv);67 }68 return;69 31 } 70 32 … … 76 38 /* return job with matching JobID */ 77 39 for (i = 0; i < Njobs; i++) { 78 if (jobs[i] .JobID == JobID) {79 return ( &jobs[i]);40 if (jobs[i][0].JobID == JobID) { 41 return (jobs[i]); 80 42 } 81 43 } … … 83 45 } 84 46 47 /* list known jobs */ 48 void ListJobs () { 49 50 int i; 51 52 if (Njobs == 0) { 53 fprintf (stderr, "no defined jobs\n"); 54 return; 55 } 56 57 for (i = 0; i < Njobs; i++) { 58 fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i][0].task[0].name, jobs[i][0].JobID, jobs[i][0].argv[0], jobs[i][0].argv); 59 } 60 return; 61 } 62 85 63 /* make a new job from a task */ 86 64 Job *CreateJob (Task *task) { 87 65 88 66 int i; 67 Job *job; 68 69 ALLOCATE (job, Job, 1); 89 70 90 job s[Njobs].JobID = NextJobID ();91 job s[Njobs].pid = 0;92 job s[Njobs].mode = JOB_LOCAL;71 job[0].JobID = NextJobID (); 72 job[0].pid = 0; 73 job[0].mode = JOB_LOCAL; 93 74 if (task[0].host != NULL) { 94 job s[Njobs].mode = JOB_CONTROLLER;75 job[0].mode = JOB_CONTROLLER; 95 76 } 96 77 … … 99 80 * we allocate one extra element, with value 0 to be passed to execvp 100 81 */ 101 job s[Njobs].argc = task[0].argc;102 ALLOCATE (job s[Njobs].argv, char *, MAX (task[0].argc + 1, 1));82 job[0].argc = task[0].argc; 83 ALLOCATE (job[0].argv, char *, MAX (task[0].argc + 1, 1)); 103 84 for (i = 0; i < task[0].argc; i++) { 104 job s[Njobs].argv[i] = strcreate (task[0].argv[i]);85 job[0].argv[i] = strcreate (task[0].argv[i]); 105 86 } 106 job s[Njobs].argv[i] = 0;87 job[0].argv[i] = 0; 107 88 108 89 /* other data from the task is needed by the job … … 111 92 be applied to the existing jobs */ 112 93 113 job s[Njobs].task = task;94 job[0].task = task; 114 95 115 96 /* if we decide we need to be able to dynamically set task qualities … … 117 98 entries to these quantites in the job structure */ 118 99 100 jobs[Njobs] = job; 119 101 Njobs ++; 120 102 if (Njobs == NJOBS) { 121 103 NJOBS += 20; 122 REALLOCATE (jobs, Job , NJOBS);104 REALLOCATE (jobs, Job *, NJOBS); 123 105 } 124 return ( &jobs[Njobs-1]);106 return (jobs[Njobs-1]); 125 107 } 126 108 … … 130 112 131 113 if (job == NULL) return; 132 133 if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) { 134 JobIDList[job[0].JobID] = FALSE; 135 } 114 115 FreeJobID (job[0].JobID); 136 116 137 117 for (i = 0; i < job[0].argc; i++) { … … 142 122 } 143 123 144 void SetCurrentJob (char *name) { 145 JobName = name; 146 } 147 148 char *GetCurrentJob () { 149 return (JobName); 150 } 151 124 /** are we deleting the active job?? **/ 152 125 int DeleteJob (Job *job) { 153 126 … … 156 129 Nm = -1; 157 130 for (i = 0; i < Njobs; i++) { 158 if (job == &jobs[i]) {131 if (job == jobs[i]) { 159 132 Nm = i; 160 133 break; … … 166 139 } 167 140 168 FreeJob ( &jobs[Nm]);141 FreeJob (jobs[Nm]); 169 142 for (i = Nm + 1; i < Njobs; i++) 170 143 jobs[i - 1] = jobs[i]; 171 144 Njobs --; 172 145 173 CurrentJob --; 174 CurrentJob = MAX (CurrentJob, 0); 175 146 /* adjust active job number */ 147 if (ActiveJob >= Nm) { 148 ActiveJob --; 149 } 176 150 return (TRUE); 177 151 } -
trunk/Ohana/src/opihi/pantasks/LocalJob.c
r4602 r4684 102 102 int result, waitstatus; 103 103 104 fprintf (stderr, "checking on %d\n", job[0].pid); 105 104 106 /* check local job status */ 105 107 result = waitpid (job[0].pid, &waitstatus, WNOHANG); … … 135 137 exit (1); 136 138 } 139 fprintf (stderr, "waited for %d\n", result); 137 140 138 141 if (WIFEXITED(waitstatus)) { … … 151 154 return; 152 155 } 156 157 int KillLocalJob (Job *job) { 158 159 int i, result, waitstatus; 160 161 if (job[0].state != JOB_BUSY) return (TRUE); 162 163 /* send SIGTERM signal to job */ 164 kill (job[0].pid, SIGTERM); 165 result = 0; 166 for (i = 0; (i < 10) && (result == 0); i++) { 167 usleep (10000); /* 10 ms is min */ 168 result = waitpid (job[0].pid, &waitstatus, WNOHANG); 169 } 170 if (result) return (TRUE); 171 172 /* send SIGKILL signal to job */ 173 kill (job[0].pid, SIGKILL); 174 result = 0; 175 for (i = 0; (i < 10) && (result == 0); i++) { 176 usleep (10000); /* 10 ms is min */ 177 result = waitpid (job[0].pid, &waitstatus, WNOHANG); 178 } 179 if (result) return (TRUE); 180 181 /* total failure, don't reset */ 182 return (FALSE); 183 } 184 -
trunk/Ohana/src/opihi/pantasks/Makefile
r4603 r4684 35 35 $(SDIR)/LocalJob.$(ARCH).o \ 36 36 $(SDIR)/JobOps.$(ARCH).o \ 37 $(SDIR)/JobIDOps.$(ARCH).o \ 37 38 $(SDIR)/TaskOps.$(ARCH).o \ 38 39 $(SDIR)/IOBufferOps.$(ARCH).o \ -
trunk/Ohana/src/opihi/pantasks/TaskOps.c
r4603 r4684 1 # include "opihi.h"2 1 # include "scheduler.h" 3 2 4 static char dot[] = "."; 5 6 static Task *tasks; 7 static int Ntasks; 8 static int NTASKS; 9 10 static char *TaskName = dot; 11 12 static int CurrentTask = 0; 13 14 /* provide a mechanism to loop over the list of tasks */ 15 Task *NextTask () { 16 17 Task *task; 18 19 if (CurrentTask >= Ntasks) { 20 CurrentTask = 0; 21 return (NULL); 22 } 23 24 task = &tasks[CurrentTask]; 25 CurrentTask ++; 26 return (task); 27 } 28 3 static Task **tasks; 4 static int Ntasks; 5 static int NTASKS; 6 7 /* counter marking task being visited by the run loop */ 8 static int ActiveTask; 9 10 /* temporary holder for a new task */ 11 static Task *NewTask = NULL; 12 13 /* set up the task list system */ 29 14 void InitTasks () { 30 15 NTASKS = 20; 31 16 Ntasks = 0; 32 ALLOCATE (tasks, Task, NTASKS); 33 TaskName = dot; 34 } 17 ALLOCATE (tasks, Task *, NTASKS); 18 ActiveTask = -1; 19 } 20 21 /* provide a mechanism to loop over the list of tasks */ 22 Task *NextTask () { 23 24 Task *task; 25 26 /* move to the next task and return it */ 27 ActiveTask ++; 28 if (ActiveTask < 0) ActiveTask = 0; 29 if (ActiveTask >= Ntasks) { 30 ActiveTask = -1; 31 return (NULL); 32 } 33 task = tasks[ActiveTask]; 34 return (task); 35 } 36 37 /* return task with given name */ 38 Task *FindTask (char *name) { 39 40 int i; 41 42 /* try for an exact match first */ 43 for (i = 0; i < Ntasks; i++) { 44 if (!strcmp (tasks[i][0].name, name)) { 45 return (tasks[i]); 46 } 47 } 48 return (NULL); 49 } 35 50 36 51 /* list known tasks */ 37 void ListTasks ( ) {52 void ListTasks (int verbose) { 38 53 39 54 int i, valid; 40 55 56 if (Ntasks == 0) { 57 fprintf (stderr, "no defined tasks\n"); 58 return; 59 } 60 61 fprintf (stderr, "Task Status\n"); 62 fprintf (stderr, " name Njobs command\n"); 41 63 for (i = 0; i < Ntasks; i++) { 42 valid = CheckTimeRanges (tasks[i] .ranges, tasks[i].Nranges);64 valid = CheckTimeRanges (tasks[i][0].ranges, tasks[i][0].Nranges); 43 65 if (valid) { 44 66 fprintf (stderr, "+ "); … … 46 68 fprintf (stderr, "- "); 47 69 } 48 fprintf (stderr, "%-15s %4d %20s\n", tasks[i].name, tasks[i].Njobs, tasks[i].argv[0]); 70 fprintf (stderr, "%-15s %4d %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]); 71 if (verbose) { 72 fprintf (stderr, " spawn period: %f, polling period: %f, timeout period: %f\n", 73 tasks[i][0].poll_period, tasks[i][0].poll_period, tasks[i][0].poll_period); 74 if (tasks[i][0].host != NULL) { 75 if (tasks[i][0].host_required) { 76 fprintf (stderr, " host %s (required)\n", tasks[i][0].host); 77 } else { 78 fprintf (stderr, " host %s (desired)\n", tasks[i][0].host); 79 } 80 } else { 81 fprintf (stderr, " task runs locally\n"); 82 } 83 } 49 84 } 50 85 return; … … 94 129 } 95 130 96 /* return task with given name*/97 Task *FindTask (char *name) {98 131 /* make a new named task */ 132 int FreeTask (Task *task) { 133 99 134 int i; 100 135 101 /* try for an exact match first */ 102 for (i = 0; i < Ntasks; i++) { 103 if (!strcmp (tasks[i].name, name)) { 104 return (&tasks[i]); 105 } 106 } 107 return (NULL); 108 } 136 if (task == NULL) return (FALSE); 137 138 if (task[0].name != NULL) free (task[0].name); 139 if (task[0].host != NULL) free (task[0].host); 140 if (task[0].argv != NULL) { 141 for (i = 0; i < task[0].argc; i++) { 142 free (task[0].argv[i]); 143 } 144 free (task[0].argv); 145 } 146 if (task[0].exec != NULL) { 147 FreeMacro (task[0].exec); 148 free (task[0].exec); 149 } 150 if (task[0].crash != NULL) { 151 FreeMacro (task[0].crash); 152 free (task[0].crash); 153 } 154 if (task[0].timeout != NULL) { 155 FreeMacro (task[0].timeout); 156 free (task[0].timeout); 157 } 158 for (i = 0; i < task[0].Nexit; i++) { 159 if (task[0].exit[i] != NULL) { 160 FreeMacro (task[0].exit[i]); 161 } 162 free (task[0].exit[i]); 163 } 164 free (task[0].exit); 165 166 if (task[0].ranges != NULL) { 167 free (task[0].ranges); 168 } 169 return (TRUE); 170 } 171 172 /**** new task functions ***/ 109 173 110 174 /* make a new named task */ 111 175 Task *CreateTask (char *name) { 112 176 113 tasks[Ntasks].name = strcreate (name);; 114 115 tasks[Ntasks].host = NULL; 116 tasks[Ntasks].host_required = FALSE; 117 118 tasks[Ntasks].argc = 0; 119 tasks[Ntasks].argv = NULL; 120 121 tasks[Ntasks].exec = NULL; 122 tasks[Ntasks].crash = NULL; 123 tasks[Ntasks].timeout = NULL; 124 125 tasks[Ntasks].Nexit = 0; 126 tasks[Ntasks].NEXIT = 10; 127 ALLOCATE (tasks[Ntasks].exit, Macro *, tasks[Ntasks].NEXIT); 177 ALLOCATE (NewTask, Task, 1); 178 179 NewTask[0].name = strcreate (name);; 180 181 NewTask[0].host = NULL; 182 NewTask[0].host_required = FALSE; 183 184 NewTask[0].argc = 0; 185 NewTask[0].argv = NULL; 186 187 NewTask[0].exec = NULL; 188 NewTask[0].crash = NULL; 189 NewTask[0].timeout = NULL; 190 191 NewTask[0].Nexit = 0; 192 NewTask[0].NEXIT = 10; 193 ALLOCATE (NewTask[0].exit, Macro *, NewTask[0].NEXIT); 128 194 /* don't free tasks[0].exit, keep at least 1 allocated */ 129 195 130 tasks[Ntasks].exec_period = 1.0;131 tasks[Ntasks].poll_period = 1.0;132 tasks[Ntasks].timeout_period = 1.0;133 134 tasks[Ntasks].Nranges = 0;135 ALLOCATE ( tasks[Ntasks].ranges, TimeRange, 1);196 NewTask[0].exec_period = 1.0; 197 NewTask[0].poll_period = 1.0; 198 NewTask[0].timeout_period = 1.0; 199 200 NewTask[0].Nranges = 0; 201 ALLOCATE (NewTask[0].ranges, TimeRange, 1); 136 202 137 203 /* init task timer (is reset by 'run') */ 138 gettimeofday (&tasks[Ntasks].last, (void *) NULL); 139 tasks[Ntasks].Njobs = 0; 140 tasks[Ntasks].Nmax = 0; /* default value means 'no limit' */ 141 204 gettimeofday (&NewTask[0].last, (void *) NULL); 205 NewTask[0].Njobs = 0; 206 NewTask[0].Nmax = 0; /* default value means 'no limit' */ 207 208 return (NewTask); 209 } 210 211 int ValidateTask (Task *task) { 212 213 if (task[0].argc == 0) { 214 fprintf (stderr, "task command not defined\n"); 215 return (FALSE); 216 } 217 if (task[0].argv == NULL) { 218 fprintf (stderr, "task command arguments not defined (programming error)\n"); 219 return (FALSE); 220 } 221 return (TRUE); 222 } 223 224 int RegisterNewTask () { 225 226 int N; 227 228 N = Ntasks; 142 229 Ntasks ++; 143 230 if (Ntasks == NTASKS) { 144 231 NTASKS += 20; 145 REALLOCATE (tasks, Task, NTASKS); 146 } 147 return (&tasks[Ntasks-1]); 148 } 149 150 void SetCurrentTask (char *name) { 151 TaskName = name; 152 } 153 154 char *GetCurrentTask () { 155 return (TaskName); 156 } 232 REALLOCATE (tasks, Task *, NTASKS); 233 } 234 tasks[N] = NewTask; 235 NewTask = NULL; 236 return (TRUE); 237 } 238 239 int DeleteNewTask () { 240 if (NewTask != NULL) { 241 FreeTask (NewTask); 242 free (NewTask); 243 NewTask = NULL; 244 } 245 return (TRUE); 246 } 247 248 Task *GetNewTask () { 249 return (NewTask); 250 } 251 252 /*** task timer functions ***/ 157 253 158 254 double GetTaskTimer (struct timeval start) { -
trunk/Ohana/src/opihi/pantasks/kill.c
r4552 r4684 12 12 JobID = atoi (argv[1]); 13 13 14 /* not yet implemented */14 job = FindJob (JobID); 15 15 16 if (job[0].mode == JOB_LOCAL) { 17 if (!KillLocalJob (job)) { 18 job[0].state = JOB_HUNG; 19 if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid); 20 return (FALSE); 21 } 22 } else { 23 if (!KillControllerJob (job)) { 24 job[0].state = JOB_HUNG; 25 if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid); 26 return (FALSE); 27 } 28 } 29 16 30 fprintf (stderr, "this function is not yet implemented\n"); 17 31 return (TRUE); -
trunk/Ohana/src/opihi/pantasks/scheduler.c
r4450 r4684 1 # include "opihi.h"2 1 # include "scheduler.h" 3 2 … … 46 45 InitTasks (); 47 46 InitJobs (); 47 InitJobIDs (); 48 48 49 49 rl_readline_name = opihi_name; -
trunk/Ohana/src/opihi/pantasks/status.c
r4602 r4684 8 8 fprintf (stderr, "scheduler is running\n"); 9 9 } 10 ListTasks ( );10 ListTasks (FALSE); 11 11 ListJobs (); 12 12 -
trunk/Ohana/src/opihi/pantasks/task.c
r4602 r4684 14 14 if (N = get_argument (argc, argv, "-list")) { 15 15 remove_argument (N, &argc, argv); 16 ListTasks (); 16 ListTasks (FALSE); 17 return (TRUE); 18 } 19 20 if (N = get_argument (argc, argv, "-longlist")) { 21 remove_argument (N, &argc, argv); 22 ListTasks (TRUE); 17 23 return (TRUE); 18 24 } … … 34 40 task = CreateTask (argv[1]); 35 41 } 36 SetCurrentTask (argv[1]); 42 /* temporary task is saved statically 43 add to list after definition is complete */ 37 44 38 45 /* read in task from appropriate source (keyboard or list) until end */ … … 71 78 have been defined. delete the task if not */ 72 79 free (input); 80 /* validate the new task: all mandatory elements defined? */ 81 if (!ValidateTask (task)) { 82 DeleteNewTask (); 83 return (FALSE); 84 } 85 RegisterNewTask (); 73 86 return (TRUE); 74 87 break; … … 92 105 } 93 106 } 94 return (TRUE); 107 /* cannot ever reach here */ 108 return (FALSE); 95 109 } 96 110 -
trunk/Ohana/src/opihi/pantasks/task_command.c
r4451 r4684 4 4 5 5 int i; 6 char *taskname;7 6 Task *task; 8 7 … … 13 12 } 14 13 15 task name = GetCurrentTask ();16 if (task name== NULL) {14 task = GetNewTask (); 15 if (task == NULL) { 17 16 fprintf (stderr, "ERROR: not defining or running a task\n"); 18 return (FALSE);19 }20 task = FindTask (taskname);21 if (task == NULL) {22 fprintf (stderr, "ERROR: current task not found??\n");23 17 return (FALSE); 24 18 } -
trunk/Ohana/src/opihi/pantasks/task_host.c
r4451 r4684 22 22 } 23 23 24 task name = GetCurrentTask ();25 if (task name== NULL) {24 task = GetNewTask (); 25 if (task == NULL) { 26 26 fprintf (stderr, "ERROR: not defining or running a task\n"); 27 return (FALSE);28 }29 task = FindTask (taskname);30 if (task == NULL) {31 fprintf (stderr, "ERROR: current task not found??\n");32 27 return (FALSE); 33 28 } -
trunk/Ohana/src/opihi/pantasks/task_macros.c
r4451 r4684 6 6 7 7 int i, N, NLINES, done, depth, ThisList; 8 char * taskname, *input;8 char *input; 9 9 Macro *macro; 10 10 Task *task; … … 22 22 } 23 23 24 task name = GetCurrentTask ();25 if (task name== NULL) {24 task = GetNewTask (); 25 if (task == NULL) { 26 26 fprintf (stderr, "ERROR: not defining or running a task\n"); 27 return (FALSE);28 }29 task = FindTask (taskname);30 if (task == NULL) {31 fprintf (stderr, "ERROR: current task not found??\n");32 27 return (FALSE); 33 28 } -
trunk/Ohana/src/opihi/pantasks/task_nmax.c
r4603 r4684 4 4 5 5 Task *task; 6 char *taskname;7 6 8 7 if (argc != 2) goto usage; 9 8 10 task name = GetCurrentTask ();11 if (task name== NULL) {9 task = GetNewTask (); 10 if (task == NULL) { 12 11 fprintf (stderr, "ERROR: not defining or running a task\n"); 13 return (FALSE);14 }15 task = FindTask (taskname);16 if (task == NULL) {17 fprintf (stderr, "ERROR: current task not found??\n");18 12 return (FALSE); 19 13 } -
trunk/Ohana/src/opihi/pantasks/task_periods.c
r4451 r4684 5 5 int N, Poll, Exec, Timeout; 6 6 float PollValue, ExecValue, TimeoutValue; 7 char *taskname;8 7 Task *task; 9 8 … … 38 37 } 39 38 40 task name = GetCurrentTask ();41 if (task name== NULL) {39 task = GetNewTask (); 40 if (task == NULL) { 42 41 fprintf (stderr, "ERROR: not defining or running a task\n"); 43 return (FALSE);44 }45 task = FindTask (taskname);46 if (task == NULL) {47 fprintf (stderr, "ERROR: current task not found??\n");48 42 return (FALSE); 49 43 } -
trunk/Ohana/src/opihi/pantasks/task_trange.c
r4602 r4684 6 6 Task *task; 7 7 TimeRange range; 8 char *taskname;9 8 10 9 /* add a -reset option? … … 24 23 if (argc != 3) goto usage; 25 24 26 task name = GetCurrentTask ();27 if (task name== NULL) {25 task = GetNewTask (); 26 if (task == NULL) { 28 27 fprintf (stderr, "ERROR: not defining or running a task\n"); 29 return (FALSE);30 }31 task = FindTask (taskname);32 if (task == NULL) {33 fprintf (stderr, "ERROR: current task not found??\n");34 28 return (FALSE); 35 29 } -
trunk/Ohana/src/opihi/pcontrol/delete.c
r4450 r4684 39 39 return (TRUE); 40 40 } 41 42 /**** at the moment, this function requires the job to be in the correct state 43 to be deleted. This should be changed to kill, then delete job if it is 44 not in the correct state 45 ****/ -
trunk/Ohana/src/opihi/pcontrol/kill.c
r4450 r4684 12 12 JobID = atoi (argv[1]); 13 13 14 /* XXX this function should only fail if a process is hung */ 14 15 job = PullJob (JobID, PCONTROL_JOB_BUSY); 15 16 if (job == NULL) { 16 17 fprintf (stderr, "job %s not BUSY\n", argv[1]); 18 /* make output message more readable by scheduler */ 17 19 return (FALSE); 18 20 } 21 22 /* XXX - check on success / failure of kill */ 19 23 KillJob (job); 24 20 25 return (TRUE); 21 26 }
Note:
See TracChangeset
for help on using the changeset viewer.
