Changeset 8296
- Timestamp:
- Aug 11, 2006, 4:51:50 PM (20 years ago)
- Location:
- trunk/Ohana/src/opihi/pcontrol
- Files:
-
- 3 added
- 20 edited
-
CheckBusyJob.c (modified) (3 diffs)
-
CheckDoneJob.c (modified) (1 diff)
-
CheckIdleHost.c (modified) (6 diffs)
-
CheckSystem.c (modified) (15 diffs)
-
HostOps.c (modified) (3 diffs)
-
IDops.c (added)
-
JobOps.c (modified) (10 diffs)
-
KillJob.c (modified) (3 diffs)
-
Makefile (modified) (2 diffs)
-
StackOps.c (added)
-
StartHost.c (modified) (1 diff)
-
StopHosts.c (modified) (4 diffs)
-
check.c (modified) (5 diffs)
-
delete.c (modified) (1 diff)
-
host.c (modified) (3 diffs)
-
hoststack.c (added)
-
init.c (modified) (3 diffs)
-
job.c (modified) (2 diffs)
-
jobstack.c (modified) (2 diffs)
-
kill.c (modified) (2 diffs)
-
run.c (modified) (1 diff)
-
status.c (modified) (6 diffs)
-
stdout.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/CheckBusyJob.c
r7917 r8296 9 9 IOBuffer buffer; 10 10 Host *host; 11 12 /* we are checking a job which is currently busy. it has been pulled from the 13 JOB_BUSY stack, and is linked to a host in the HOST_BUSY stack. 14 XXX need to check on state of HOST on return */ 11 15 12 16 /** must have a valid host : if not? **/ … … 28 32 29 33 case PCLIENT_HUNG: 30 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 31 job[0].state = PCONTROL_JOB_HUNG; 34 PutJobSetState (job, PCONTROL_JOB_BUSY, STACK_BOTTOM, PCONTROL_JOB_HUNG); 32 35 FreeIOBuffer (&buffer); 33 36 return (TRUE); … … 78 81 79 82 /** job has exited : move to DONE stack (host still BUSY) **/ 80 PutJob (job, PCONTROL_JOB_DONE, STACK_BOTTOM); 81 job[0].state = outstate; 83 PutJobSetState (job, PCONTROL_JOB_DONE, STACK_BOTTOM, outstate); 82 84 FreeIOBuffer (&buffer); 83 85 return (TRUE); -
trunk/Ohana/src/opihi/pcontrol/CheckDoneJob.c
r4450 r8296 16 16 } 17 17 18 /* job's state is either EXIT or CRASH (verify?) */ 18 19 host = UnlinkJobAndHost (job); 19 20 PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM); 20 21 PutJob (job, job[0].state, STACK_BOTTOM); 21 /* job's state is either EXIT or CRASH (verify?) */22 22 23 23 return (TRUE); -
trunk/Ohana/src/opihi/pcontrol/CheckIdleHost.c
r7917 r8296 1 1 # include "pcontrol.h" 2 2 3 /* the supplied host is not on a stack: it cannot be taken by the other thread */ 3 4 int CheckIdleHost (Host *host) { 4 5 … … 7 8 Job *job; 8 9 10 /* search the JOB_PENDING stack for an appropriate job */ 9 11 stack = GetJobStack (PCONTROL_JOB_PENDING); 12 LockStack (stack); 10 13 11 14 /* look for first NEEDHOST matching this host */ … … 18 21 } 19 22 if (strcasecmp (job[0].hostname, host[0].hostname)) continue; 20 LinkJobAndHost (job, host); 23 24 /* we have found an appropriate job; link it to the host and send to StartJob */ 25 job[0].host = (struct Host *) host; 26 host[0].job = (struct Job *) job; 27 28 /* take the job off the stack and unlock the stack */ 29 RemoveStackEntry (stack, i); 30 UnlockStack (stack); 21 31 StartJob (job); 22 32 return (TRUE); … … 26 36 for (i = 0; i < stack[0].Nobject; i++) { 27 37 job = (Job *) stack[0].object[i]; 28 /*** this currently never runs WANTHOST jobs on any other machines ***/29 38 if (job[0].mode != PCONTROL_JOB_WANTHOST) continue; 30 39 if (job[0].hostname == NULL) { … … 33 42 } 34 43 if (strcasecmp (job[0].hostname, host[0].hostname)) continue; 35 LinkJobAndHost (job, host); 44 45 /* we have found an appropriate job; link it to the host and send to StartJob */ 46 job[0].host = (struct Host *) host; 47 host[0].job = (struct Job *) job; 48 49 /* take the job off the stack and unlock the stack */ 50 RemoveStackEntry (stack, i); 51 UnlockStack (stack); 36 52 StartJob (job); 37 53 return (TRUE); … … 42 58 job = (Job *) stack[0].object[i]; 43 59 if (job[0].mode != PCONTROL_JOB_ANYHOST) continue; 44 LinkJobAndHost (job, host); 60 61 /* we have found an appropriate job; link it to the host and send to StartJob */ 62 job[0].host = (struct Host *) host; 63 host[0].job = (struct Job *) job; 64 65 /* take the job off the stack and unlock the stack */ 66 RemoveStackEntry (stack, i); 67 UnlockStack (stack); 45 68 StartJob (job); 46 return (TRUE);69 return (TRUE); 47 70 } 48 /* no jobs for host, but back on IDLE stack */ 71 72 /* no ANYHOST entry, look for first WANTHOST with old time */ 73 /* XXX perhaps I should add this to the conditions for ANYHOST instead of 74 running a separate loop? ie, WANTHOST && time > X == ANYHOST */ 75 for (i = 0; i < stack[0].Nobject; i++) { 76 job = (Job *) stack[0].object[i]; 77 if (job[0].mode != PCONTROL_JOB_WANTHOST) continue; 78 // test the job age and skip if too young 79 80 /* we have found an appropriate job; link it to the host and send to StartJob */ 81 job[0].host = (struct Host *) host; 82 host[0].job = (struct Job *) job; 83 84 /* take the job off the stack and unlock the stack */ 85 RemoveStackEntry (stack, i); 86 UnlockStack (stack); 87 StartJob (job); 88 return (TRUE); 89 } 90 UnlockStack (stack); 91 92 /* no jobs for host, put it back on IDLE stack */ 49 93 PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM); 50 94 return (TRUE); -
trunk/Ohana/src/opihi/pcontrol/CheckSystem.c
r7917 r8296 13 13 CheckBusyJobs(0.020); /* get job status */ 14 14 CheckDoneJobs(0.020); /* harvest job stdout/stderr */ 15 CheckKillJobs(0.020); /* harvest job stdout/stderr */ 15 16 16 17 CheckDoneHosts(0.020); /* reset the host */ … … 51 52 float dtime; 52 53 53 stack = GetJobStack (PCONTROL_JOB_BUSY); 54 Nobject = stack[0].Nobject; 55 56 /* always allow at least one test */ 57 gettimeofday (&start, (void *) NULL); 58 dtime = 0.0; 59 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 60 job = GetStack (stack, STACK_TOP); 54 /* Loop through objects on the stack, no more than once. Note that it is not important if the 55 stack size is modified by other threads or is changed by any of the actions performed during 56 this loop: the Nobject value is only used to get a rough number for the number of iterations. 57 */ 58 59 hoststack = GetHostStack (PCONTROL_HOST_BUSY); 60 jobstack = GetJobStack (PCONTROL_JOB_BUSY); 61 Nobject = jobstack[0].Nobject; 62 63 /* always allow at least one test */ 64 gettimeofday (&start, (void *) NULL); 65 dtime = 0.0; 66 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 67 /* pull both job and host from their stacks */ 68 /* XXX is the subject to the Dangerous Embrace? */ 69 LockStack (hoststack); 70 job = PullStackByLocation (jobstack, STACK_TOP); 71 if (job == NULL) { 72 UnlockStack (hoststack); 73 break; 74 } 75 host = RemoveStackByID (hoststack, job[0].host[0].HostID); 76 UnlockStack (hoststack); 77 61 78 CheckBusyJob (job); 62 79 gettimeofday (&stop, (void *) NULL); … … 75 92 float dtime; 76 93 94 /* Loop through objects on the stack, no more than once. see note above */ 77 95 stack = GetJobStack (PCONTROL_JOB_DONE); 78 96 Nobject = stack[0].Nobject; … … 82 100 dtime = 0.0; 83 101 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 84 job = GetStack (stack, STACK_TOP); 102 job = PullStackByLocation (stack, STACK_TOP); 103 if (job == NULL) break; 85 104 CheckDoneJob (job); 86 105 gettimeofday (&stop, (void *) NULL); … … 91 110 } 92 111 112 int CheckKillJobs (float MaxDelay) { 113 114 struct timeval start, stop; 115 int i, Nobject; 116 Stack *stack; 117 Job *job; 118 float dtime; 119 120 /* Loop through objects on the stack, no more than once. see note above */ 121 stack = GetJobStack (PCONTROL_JOB_KILL); 122 Nobject = stack[0].Nobject; 123 124 /* always allow at least one test */ 125 gettimeofday (&start, (void *) NULL); 126 dtime = 0.0; 127 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 128 job = PullStackByLocation (stack, STACK_TOP); 129 if (job == NULL) break; 130 KillJob (job); 131 gettimeofday (&stop, (void *) NULL); 132 dtime = DTIME (stop, start); 133 } 134 if (0 && (Nobject > 0)) gprint (GP_ERR, "checked %d of %d jobs\n", i, Nobject); 135 return (TRUE); 136 } 137 93 138 int CheckDoneHosts (float MaxDelay) { 94 139 … … 99 144 float dtime; 100 145 146 /* Loop through objects on the stack, no more than once. see note above */ 101 147 stack = GetHostStack (PCONTROL_HOST_DONE); 102 148 Nobject = stack[0].Nobject; … … 106 152 dtime = 0.0; 107 153 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 108 host = GetStack (stack, STACK_TOP); 154 host = PullStackByLocation (stack, STACK_TOP); 155 if (host == NULL) break; 109 156 CheckDoneHost (host); 110 157 gettimeofday (&stop, (void *) NULL); … … 123 170 float dtime; 124 171 172 /* Loop through objects on the stack, no more than once. see note above */ 125 173 stack = GetHostStack (PCONTROL_HOST_DOWN); 126 174 Nobject = stack[0].Nobject; … … 130 178 dtime = 0.0; 131 179 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 132 host = GetStack (stack, STACK_TOP); 180 host = PullStackByLocation (stack, STACK_TOP); 181 if (host == NULL) break; 133 182 dtime = DTIME (host[0].nexttry, start); 134 183 if (dtime > 0) { … … 156 205 if (!stack[0].Nobject) return (TRUE); 157 206 207 /* Loop through objects on the stack, no more than once. see note above */ 158 208 stack = GetHostStack (PCONTROL_HOST_IDLE); 159 209 Nobject = stack[0].Nobject; … … 163 213 dtime = 0.0; 164 214 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 165 host = GetStack (stack, STACK_TOP); 215 host = PullStackByLocation (stack, STACK_TOP); 216 if (host == NULL) break; 166 217 CheckIdleHost (host); 167 218 gettimeofday (&stop, (void *) NULL); … … 181 232 float dtime; 182 233 234 /* Loop through objects on the stack, no more than once. see note above */ 183 235 stack = GetHostStack (PCONTROL_HOST_IDLE); 184 236 Nobject = stack[0].Nobject; … … 188 240 dtime = 0.0; 189 241 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 190 host = GetStack (stack, STACK_TOP); 242 host = PullStackByLocation (stack, STACK_TOP); 243 if (host == NULL) break; 191 244 CheckHost (host); 192 245 gettimeofday (&stop, (void *) NULL); … … 195 248 if (0) gprint (GP_ERR, "checked %d idle hosts\n", i); 196 249 250 /* Loop through objects on the stack, no more than once. see note above */ 197 251 stack = GetHostStack (PCONTROL_HOST_BUSY); 198 252 Nobject = stack[0].Nobject; … … 200 254 dtime = 0.0; 201 255 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 202 host = GetStack (stack, STACK_TOP); 256 host = PullStackByLocation (stack, STACK_TOP); 257 if (host == NULL) break; 203 258 CheckHost (host); 204 259 gettimeofday (&stop, (void *) NULL); -
trunk/Ohana/src/opihi/pcontrol/HostOps.c
r8183 r8296 12 12 HostPool_Done = InitStack (); 13 13 HostPool_Down = InitStack (); 14 HostPool_Off = InitStack ();14 HostPool_Off = InitStack (); 15 15 } 16 16 … … 35 35 } 36 36 37 Host *FindHostStack (IDtype HostID) { 38 39 Host *host; 40 41 host = FindHostPtr (HostID, PCONTROL_HOST_IDLE); 42 if (host != NULL) return (host); 43 44 host = FindHostPtr (HostID, PCONTROL_HOST_DOWN); 45 if (host != NULL) return (host); 46 47 host = FindHostPtr (HostID, PCONTROL_HOST_DONE); 48 if (host != NULL) return (host); 49 50 host = FindHostPtr (HostID, PCONTROL_HOST_BUSY); 51 if (host != NULL) return (host); 52 53 host = FindHostPtr (HostID, PCONTROL_HOST_OFF); 54 if (host != NULL) return (host); 55 56 return (NULL); 57 } 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 37 Stack *GetHostStackByName (char *name) { 38 if (!strcasecmp (name, "idle")) return (HostPool_Idle); 39 if (!strcasecmp (name, "down")) return (HostPool_Down); 40 if (!strcasecmp (name, "done")) return (HostPool_Done); 41 if (!strcasecmp (name, "busy")) return (HostPool_Busy); 42 if (!strcasecmp (name, "off")) return (HostPool_Off); 43 return (NULL); 44 } 45 46 /* add host to position in stack */ 81 47 int PutHost (Host *host, int StackID, int where) { 82 48 … … 88 54 89 55 host[0].stack = StackID; 90 stat = Pu tStack (stack, where, host);91 / * status (0, NULL); */56 stat = PushStack (stack, where, host, host[0].HostID, host[0].hostname); 57 // XXX need to handle the error conditions, or we drop the host & leak memory 92 58 return (stat); 93 59 } 94 60 95 Host *GetHost (int StackID, int where) { 96 97 Host *host; 98 Stack *stack; 99 100 stack = GetHostStack (StackID); 101 if (stack == NULL) return (NULL); 102 103 host = GetStack (stack, where); 104 return (host); 105 } 106 107 int FindHost (IDtype HostID, int StackID) { 108 109 int i; 110 Host *host; 111 Stack *stack; 112 113 stack = GetHostStack (StackID); 114 if (stack == NULL) return (-2); 115 116 for (i = 0; i < stack[0].Nobject; i++) { 117 host = (Host *) stack[0].object[i]; 118 if (host[0].HostID == HostID) { 119 return (i); 120 } 121 } 122 return (-1); 123 } 124 125 Host *FindHostPtr (IDtype HostID, int StackID) { 126 127 int i; 128 Host *host; 129 Stack *stack; 130 131 stack = GetHostStack (StackID); 132 if (stack == NULL) return (NULL); 133 134 for (i = 0; i < stack[0].Nobject; i++) { 135 host = (Host *) stack[0].object[i]; 136 if (host[0].HostID == HostID) { 137 return (host); 138 } 139 } 140 return (NULL); 141 } 142 143 Host *PullHost (IDtype HostID, int StackID) { 144 145 int N; 146 Host *host; 147 148 N = FindHost (HostID, StackID); 149 if (N < 0) return (NULL); 150 151 host = GetHost (StackID, N); 152 if (host == NULL) { 153 gprint (GP_ERR, "programming error! host missing from stack\n"); 154 exit (1); 155 } 156 return (host); 157 } 158 159 int FindNamedHost (char *name, int StackID) { 160 161 int i; 162 Host *host; 163 Stack *stack; 164 165 stack = GetHostStack (StackID); 166 if (stack == NULL) return (-2); 167 168 for (i = 0; i < stack[0].Nobject; i++) { 169 host = (Host *) stack[0].object[i]; 170 if (!strcasecmp (host[0].hostname, name)) { 171 return (i); 172 } 173 } 174 return (-1); 175 } 61 /* find the host by ID in the defined host stacks */ 62 Host *PullHostByID (IDtype HostID, int *StackID) { 63 64 Host *host; 65 66 *StackID = PCONTROL_HOST_IDLE; 67 host = PullHostFromStackByID (*StackID, HostID); 68 if (host != NULL) return (host); 69 70 *StackID = PCONTROL_HOST_DOWN; 71 host = PullHostFromStackByID (*StackID, HostID); 72 if (host != NULL) return (host); 73 74 *StackID = PCONTROL_HOST_DONE; 75 host = PullHostFromStackByID (*StackID, HostID); 76 if (host != NULL) return (host); 77 78 *StackID = PCONTROL_HOST_BUSY; 79 host = PullHostFromStackByID (*StackID, HostID); 80 if (host != NULL) return (host); 81 82 *StackID = PCONTROL_HOST_OFF; 83 host = PullHostFromStackByID (*StackID, HostID); 84 if (host != NULL) return (host); 85 86 *StackID = -1; 87 return (NULL); 88 } 89 90 /* find the host by ID in the defined host stacks */ 91 Host *PullHostByName (char *name, int *StackID) { 92 93 Host *host; 94 95 *StackID = PCONTROL_HOST_IDLE; 96 host = PullHostFromStackByName (*StackID, name); 97 if (host != NULL) return (host); 98 99 *StackID = PCONTROL_HOST_DOWN; 100 host = PullHostFromStackByName (*StackID, name); 101 if (host != NULL) return (host); 102 103 *StackID = PCONTROL_HOST_DONE; 104 host = PullHostFromStackByName (*StackID, name); 105 if (host != NULL) return (host); 106 107 *StackID = PCONTROL_HOST_BUSY; 108 host = PullHostFromStackByName (*StackID, name); 109 if (host != NULL) return (host); 110 111 *StackID = PCONTROL_HOST_OFF; 112 host = PullHostFromStackByName (*StackID, name); 113 if (host != NULL) return (host); 114 115 *StackID = -1; 116 return (NULL); 117 } 118 119 Host *PullHostFromStackByID (int StackID, IDtype ID) { 120 121 Host *host; 122 Stack *stack; 123 124 stack = GetHostStack (StackID); 125 if (stack == NULL) return (NULL); 126 127 host = PullStackByID (stack, ID); 128 return (host); 129 } 130 131 Host *PullHostFromStackByName (int StackID, char *name) { 132 133 Host *host; 134 Stack *stack; 135 136 stack = GetHostStack (StackID); 137 if (stack == NULL) return (NULL); 138 139 host = PullStackByName (stack, name); 140 return (host); 141 } 142 143 /* find the host by ID in the defined host stacks (don't pull off stack) */ 144 /* the Find functions are not thread-safe: DROP */ 145 # if (0) 146 Host *FindHostByID (IDtype HostID, int *StackID) { 147 148 Host *host; 149 150 *StackID = PCONTROL_HOST_IDLE; 151 host = FindHostInStackByID (*StackID, HostID); 152 if (host != NULL) return (host); 153 154 *StackID = PCONTROL_HOST_DOWN; 155 host = FindHostInStackByID (*StackID, HostID); 156 if (host != NULL) return (host); 157 158 *StackID = PCONTROL_HOST_DONE; 159 host = FindHostInStackByID (*StackID, HostID); 160 if (host != NULL) return (host); 161 162 *StackID = PCONTROL_HOST_BUSY; 163 host = FindHostInStackByID (*StackID, HostID); 164 if (host != NULL) return (host); 165 166 *StackID = PCONTROL_HOST_OFF; 167 host = FindHostInStackByID (*StackID, HostID); 168 if (host != NULL) return (host); 169 170 *StackID = -1; 171 return (NULL); 172 } 173 174 /* find the host by Name in the defined host stacks (don't pull off stack) */ 175 Host *FindHostByName (char *name, int *StackID) { 176 177 Host *host; 178 179 *StackID = PCONTROL_HOST_IDLE; 180 host = FindHostInStackByName (*StackID, name); 181 if (host != NULL) return (host); 182 183 *StackID = PCONTROL_HOST_DOWN; 184 host = FindHostInStackByName (*StackID, name); 185 if (host != NULL) return (host); 186 187 *StackID = PCONTROL_HOST_DONE; 188 host = FindHostInStackByName (*StackID, name); 189 if (host != NULL) return (host); 190 191 *StackID = PCONTROL_HOST_BUSY; 192 host = FindHostInStackByName (*StackID, name); 193 if (host != NULL) return (host); 194 195 *StackID = PCONTROL_HOST_OFF; 196 host = FindHostInStackByName (*StackID, name); 197 if (host != NULL) return (host); 198 199 *StackID = -1; 200 return (NULL); 201 } 202 203 Host *FindHostInStackByID (int StackID, IDtype ID) { 204 205 Host *host; 206 Stack *stack; 207 208 stack = GetHostStack (StackID); 209 if (stack == NULL) return (NULL); 210 211 host = FindStackByID (stack, ID); 212 return (host); 213 } 214 215 Host *FindHostInStackByName (int StackID, char *name) { 216 217 Host *host; 218 Stack *stack; 219 220 stack = GetHostStack (StackID); 221 if (stack == NULL) return (NULL); 222 223 host = FindStackByName (stack, name); 224 return (host); 225 } 226 # endif 176 227 177 228 IDtype AddHost (char *hostname) { -
trunk/Ohana/src/opihi/pcontrol/JobOps.c
r7917 r8296 4 4 Stack *JobPool_Busy; 5 5 Stack *JobPool_Done; 6 Stack *JobPool_Kill; 6 7 Stack *JobPool_Exit; 7 8 Stack *JobPool_Crash; … … 9 10 void InitJobStacks () { 10 11 JobPool_Pending = InitStack (); 11 JobPool_Busy = InitStack (); 12 JobPool_Done = InitStack (); 13 JobPool_Exit = InitStack (); 14 JobPool_Crash = InitStack (); 12 JobPool_Busy = InitStack (); 13 JobPool_Done = InitStack (); 14 JobPool_Kill = InitStack (); 15 JobPool_Exit = InitStack (); 16 JobPool_Crash = InitStack (); 15 17 } 16 18 … … 23 25 case PCONTROL_JOB_DONE: 24 26 return (JobPool_Done); 27 case PCONTROL_JOB_KILL: 28 return (JobPool_Kill); 25 29 case PCONTROL_JOB_EXIT: 26 30 return (JobPool_Exit); … … 37 41 Stack *GetJobStackByName (char *name) { 38 42 39 if (!strcasecmp (name, "pending")) 40 return (JobPool_Pending); 41 if (!strcasecmp (name, "busy")) 42 return (JobPool_Busy); 43 if (!strcasecmp (name, "done")) 44 return (JobPool_Done); 45 if (!strcasecmp (name, "exit")) 46 return (JobPool_Exit); 47 if (!strcasecmp (name, "crash")) 48 return (JobPool_Crash); 43 if (!strcasecmp (name, "pending")) return (JobPool_Pending); 44 if (!strcasecmp (name, "busy")) return (JobPool_Busy); 45 if (!strcasecmp (name, "done")) return (JobPool_Done); 46 if (!strcasecmp (name, "exit")) return (JobPool_Exit); 47 if (!strcasecmp (name, "crash")) return (JobPool_Crash); 49 48 return (NULL); 50 49 } 51 50 52 Job *FindJobStack (IDtype JobID) { 53 54 Job *job; 55 56 job = FindJobPtr (JobID, PCONTROL_JOB_PENDING); 57 if (job != NULL) return (job); 58 59 job = FindJobPtr (JobID, PCONTROL_JOB_BUSY); 60 if (job != NULL) return (job); 61 62 job = FindJobPtr (JobID, PCONTROL_JOB_EXIT); 63 if (job != NULL) return (job); 64 65 job = FindJobPtr (JobID, PCONTROL_JOB_CRASH); 66 if (job != NULL) return (job); 67 68 job = FindJobPtr (JobID, PCONTROL_JOB_DONE); 69 if (job != NULL) return (job); 70 71 return (NULL); 72 } 73 74 /* add job to position in stack */ 51 /* add job to position in stack, use StackID as default state */ 75 52 int PutJob (Job *job, int StackID, int where) { 76 53 … … 81 58 if (stack == NULL) return (FALSE); 82 59 83 /* b e default, these are both the same - to override, set state after PutJob*/60 /* by default, these are both the same - to override, use PutJobSetState */ 84 61 job[0].state = StackID; 85 62 job[0].stack = StackID; 86 stat = Pu tStack (stack, where, job);87 / * status (0, NULL); */63 stat = PushStack (stack, where, job, job[0].JobID, job[0].argv[0]); 64 // XXX need to handle the error conditions, or we drop the host & leak memory 88 65 return (stat); 89 66 } 90 67 68 /* add job to position in stack. set state to 'state' */ 69 int PutJobSetState (Job *job, int StackID, int where, int state) { 70 71 int stat; 72 Stack *stack; 73 74 stack = GetJobStack (StackID); 75 if (stack == NULL) return (FALSE); 76 77 /* alternate state specified by user */ 78 job[0].state = state; 79 job[0].stack = StackID; 80 stat = PushStack (stack, where, job, job[0].JobID, job[0].argv[0]); 81 // XXX need to handle the error conditions, or we drop the host & leak memory 82 return (stat); 83 } 84 85 Job *PullJobByID (IDtype JobID, int *StackID) { 86 87 Job *job; 88 89 *StackID = PCONTROL_JOB_PENDING; 90 job = PullJobFromStackByID (*StackID, JobID); 91 if (job != NULL) return (job); 92 93 *StackID = PCONTROL_JOB_BUSY; 94 job = PullJobFromStackByID (*StackID, JobID); 95 if (job != NULL) return (job); 96 97 *StackID = PCONTROL_JOB_EXIT; 98 job = PullJobFromStackByID (*StackID, JobID); 99 if (job != NULL) return (job); 100 101 *StackID = PCONTROL_JOB_CRASH; 102 job = PullJobFromStackByID (*StackID, JobID); 103 if (job != NULL) return (job); 104 105 *StackID = PCONTROL_JOB_DONE; 106 job = PullJobFromStackByID (*StackID, JobID); 107 if (job != NULL) return (job); 108 109 *StackID = PCONTROL_JOB_KILL; 110 job = PullJobFromStackByID (*StackID, JobID); 111 if (job != NULL) return (job); 112 113 return (NULL); 114 } 115 91 116 /* remove job from position in stack */ 92 Job * GetJob (int StackID, int where) {117 Job *PullJobFromStackByID (int StackID, int ID) { 93 118 94 119 Job *job; … … 98 123 if (stack == NULL) return (NULL); 99 124 100 job = GetStack (stack, where);125 job = PullStackByID (stack, ID); 101 126 return (job); 102 127 } 103 128 104 /* return stack position of job */ 105 int FindJob (IDtype JobID, int StackID) { 106 107 int i; 108 Job *job; 109 Stack *stack; 110 111 stack = GetJobStack (StackID); 112 if (stack == NULL) return (-2); 113 114 for (i = 0; i < stack[0].Nobject; i++) { 115 job = (Job *) stack[0].object[i]; 116 if (job[0].JobID == JobID) { 117 return (i); 118 } 119 } 120 return (-1); 121 } 122 123 /* return pointer to job */ 124 Job *FindJobPtr (IDtype JobID, int StackID) { 125 126 int i; 129 /* the Find functions are not thread-safe: DROP */ 130 # if (0) 131 Job *FindJobByID (IDtype JobID, int *StackID) { 132 133 Job *job; 134 135 *StackID = PCONTROL_JOB_PENDING; 136 job = FindJobInStackByID (*StackID, JobID); 137 if (job != NULL) return (job); 138 139 *StackID = PCONTROL_JOB_BUSY; 140 job = FindJobInStackByID (*StackID, JobID); 141 if (job != NULL) return (job); 142 143 *StackID = PCONTROL_JOB_EXIT; 144 job = FindJobInStackByID (*StackID, JobID); 145 if (job != NULL) return (job); 146 147 *StackID = PCONTROL_JOB_CRASH; 148 job = FindJobInStackByID (*StackID, JobID); 149 if (job != NULL) return (job); 150 151 *StackID = PCONTROL_JOB_DONE; 152 job = FindJobInStackByID (*StackID, JobID); 153 if (job != NULL) return (job); 154 155 return (NULL); 156 } 157 158 /* remove job from position in stack */ 159 Job *FindJobInStackByID (int StackID, int ID) { 160 127 161 Job *job; 128 162 Stack *stack; … … 131 165 if (stack == NULL) return (NULL); 132 166 133 for (i = 0; i < stack[0].Nobject; i++) { 134 job = (Job *) stack[0].object[i]; 135 if (job[0].JobID == JobID) { 136 return (job); 137 } 138 } 139 return (NULL); 140 } 141 142 /* remove job from stack, return pointer */ 143 Job *PullJob (IDtype JobID, int StackID) { 144 145 int N; 146 Job *job; 147 148 N = FindJob (JobID, StackID); 149 if (N < 0) return (NULL); 150 151 job = GetJob (StackID, N); 152 if (job == NULL) { 153 gprint (GP_ERR, "programming error! job missing from stack\n"); 154 exit (1); 155 } 167 job = FindStackByID (stack, ID); 156 168 return (job); 157 169 } 170 # endif 158 171 159 172 IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) { 160 173 174 int JobID; 161 175 Job *job; 162 176 … … 175 189 InitIOBuffer (&job[0].stderr, 0x1000); 176 190 191 JobID = job[0].JobID; 177 192 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 178 193 gprint (GP_ERR, "added new job\n"); 179 return ( job[0].JobID);194 return (JobID); 180 195 } 181 196 … … 212 227 213 228 /* remove host from correct stack */ 214 if (PullHost (host[0].HostID, host[0].stack) == NULL) { 229 XXXX does this step asuume the host is in this stack?? 230 if (PullHostFromStackByID (host[0].stack, host[0].HostID) == NULL) { 215 231 gprint (GP_ERR, "programming error: host is not found in current stack\n"); 216 232 exit (2); … … 218 234 return (host); 219 235 } 220 221 void LinkJobAndHost (Job *job, Host *host) {222 223 job[0].host = (struct Host *) host;224 host[0].job = (struct Job *) job;225 226 /* remove job from correct stack */227 if (PullJob (job[0].JobID, job[0].stack) == NULL) {228 gprint (GP_ERR, "programming error: job is not found in current stack\n");229 exit (2);230 }231 } -
trunk/Ohana/src/opihi/pcontrol/KillJob.c
r7917 r8296 26 26 27 27 case PCLIENT_HUNG: 28 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 29 job[0].state = PCONTROL_JOB_HUNG; 28 PutJobSetState (job, PCONTROL_JOB_BUSY, STACK_BOTTOM, PCONTROL_JOB_HUNG); 30 29 FreeIOBuffer (&buffer); 31 30 return (TRUE); … … 61 60 return (FALSE); 62 61 case 1: 63 PutJob (job, PCONTROL_JOB_DONE, STACK_BOTTOM); 64 job[0].state = PCONTROL_JOB_CRASH; 65 /* this overrides the default assigned by PutJob */ 62 PutJobSetState (job, PCONTROL_JOB_DONE, STACK_BOTTOM, PCONTROL_JOB_CRASH); 66 63 return (TRUE); 67 64 case 2: … … 73 70 exit (1); 74 71 } 72 73 /** XXX need to do something appropriate with host? ***/ -
trunk/Ohana/src/opihi/pcontrol/Makefile
r6678 r8296 38 38 $(SDIR)/GetJobOutput.$(ARCH).o \ 39 39 $(SDIR)/HostOps.$(ARCH).o \ 40 $(SDIR)/ JobID.$(ARCH).o \40 $(SDIR)/IDops.$(ARCH).o \ 41 41 $(SDIR)/JobOps.$(ARCH).o \ 42 $(SDIR)/ QueueOps.$(ARCH).o \42 $(SDIR)/StackOps.$(ARCH).o \ 43 43 $(SDIR)/ResetJob.$(ARCH).o \ 44 44 $(SDIR)/StartHost.$(ARCH).o \ … … 53 53 $(SDIR)/job.$(ARCH).o \ 54 54 $(SDIR)/jobstack.$(ARCH).o \ 55 $(SDIR)/hoststack.$(ARCH).o \ 55 56 $(SDIR)/kill.$(ARCH).o \ 56 57 $(SDIR)/pulse.$(ARCH).o \ -
trunk/Ohana/src/opihi/pcontrol/StartHost.c
r7917 r8296 1 1 # include "pcontrol.h" 2 # define RETRY_BASE 1 .02 # define RETRY_BASE 10.0 3 3 4 4 int StartHost (Host *host) { -
trunk/Ohana/src/opihi/pcontrol/StopHosts.c
r7917 r8296 1 1 # include "pcontrol.h" 2 3 void DownHost (Host *host) { 4 CLOSE (host[0].stdin); 5 CLOSE (host[0].stdout); 6 CLOSE (host[0].stderr); 7 host[0].job = NULL; 8 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 9 } 10 11 void OffHost (Host *host) { 12 CLOSE (host[0].stdin); 13 CLOSE (host[0].stdout); 14 CLOSE (host[0].stderr); 15 host[0].job = NULL; 16 PutHost (host, PCONTROL_HOST_OFF, STACK_BOTTOM); 17 } 2 18 3 19 int DownHosts () { … … 8 24 9 25 stack = GetHostStack (PCONTROL_HOST_IDLE); 10 Nobject = stack[0].Nobject; 11 12 for (i = 0; i < Nobject; i++) { 13 host = GetStack (stack, STACK_TOP); 26 while ((host = PullStackByLocation (stack, STACK_BOTTOM)) != NULL) { 14 27 StopHost (host); 15 28 DownHost (host); … … 17 30 18 31 stack = GetHostStack (PCONTROL_HOST_BUSY); 19 Nobject = stack[0].Nobject; 20 21 for (i = 0; i < Nobject; i++) { 22 host = GetStack (stack, STACK_TOP); 32 while ((host = PullStackByLocation (stack, STACK_BOTTOM)) != NULL) { 23 33 StopHost (host); 24 34 DownHost (host); … … 55 65 } 56 66 57 void DownHost (Host *host) { 58 CLOSE (host[0].stdin); 59 CLOSE (host[0].stdout); 60 CLOSE (host[0].stderr); 61 host[0].job = NULL; 62 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 63 } 64 65 void OffHost (Host *host) { 66 CLOSE (host[0].stdin); 67 CLOSE (host[0].stdout); 68 CLOSE (host[0].stderr); 69 host[0].job = NULL; 70 PutHost (host, PCONTROL_HOST_OFF, STACK_BOTTOM); 71 } 72 67 /* the host is thought to be down; check for child exit status */ 73 68 int HarvestHost (int pid) { 74 69 -
trunk/Ohana/src/opihi/pcontrol/check.c
r7917 r8296 1 1 # include "pcontrol.h" 2 2 3 char jobstate[ 6][32] = {"PENDING", "BUSY", "EXIT", "CRASH", "HUNG", "DONE"};4 char hoststate[5][32] = {"IDLE", "BUSY", "DOWN", "DONE", "OFF"};3 char jobstate[7][32] = {"PENDING", "BUSY", "HUNG", "DONE", "KILL", "EXIT", "CRASH"}; 4 char hoststate[5][32] = {"IDLE", "BUSY", "DOWN", "DONE", "OFF"}; 5 5 6 6 int check (int argc, char **argv) { … … 8 8 Job *job; 9 9 Host *host; 10 int JobID, HostID ;10 int JobID, HostID, StackID; 11 11 12 12 if (argc != 3) { … … 18 18 if (!strcasecmp (argv[1], "JOB")) { 19 19 JobID = atoi (argv[2]); 20 job = FindJobStack (JobID);20 job = PullJobByID (JobID, &StackID); 21 21 if (job == NULL) { 22 22 gprint (GP_LOG, "job not found\n"); 23 23 return (FALSE); 24 24 } 25 gprint (GP_LOG, "STATUS %s\n", jobstate[ job[0].stack]);25 gprint (GP_LOG, "STATUS %s\n", jobstate[StackID]); 26 26 gprint (GP_LOG, "EXITST %d\n", job[0].exit_status); 27 27 gprint (GP_LOG, "STDOUT %d\n", job[0].stdout_size); 28 28 gprint (GP_LOG, "STDERR %d\n", job[0].stderr_size); 29 PutJob (job, StackID, STACK_BOTTOM); 29 30 return (TRUE); 30 31 } … … 32 33 if (!strcasecmp (argv[1], "HOST")) { 33 34 HostID = atoi (argv[2]); 34 host = FindHostStack (HostID);35 host = PullHostByID (HostID, &StackID); 35 36 if (host == NULL) { 36 37 gprint (GP_LOG, "host not found\n"); 37 38 return (FALSE); 38 39 } 39 gprint (GP_LOG, "host %s\n", hoststate[host[0].stack]); 40 gprint (GP_LOG, "host %s\n", hoststate[StackID]); 41 PutHost (host, StackID, STACK_BOTTOM); 40 42 return (TRUE); 41 43 } … … 44 46 return (FALSE); 45 47 } 48 49 XXX how do I handle objects which are in flight?? -
trunk/Ohana/src/opihi/pcontrol/delete.c
r7917 r8296 13 13 /* use a string interp to convert JobIDs to ints ? */ 14 14 15 job = PullJob (JobID, PCONTROL_JOB_PENDING);15 job = PullJobFromStackByID (PCONTROL_JOB_PENDING, JobID); 16 16 if (job != NULL) goto found; 17 17 18 job = PullJob (JobID, PCONTROL_JOB_CRASH);18 job = PullJobFromStackByID (PCONTROL_JOB_CRASH, JobID); 19 19 if (job != NULL) goto found; 20 20 21 job = PullJob (JobID, PCONTROL_JOB_EXIT);21 job = PullJobFromStackByID (PCONTROL_JOB_EXIT, JobID); 22 22 if (job != NULL) goto found; 23 23 -
trunk/Ohana/src/opihi/pcontrol/host.c
r8181 r8296 4 4 5 5 int N, Ns; 6 int StackID; 6 7 IDtype HostID; 7 8 Host *host; … … 15 16 } 16 17 if (!strcasecmp (argv[1], "ON")) { 17 N = FindNamedHost (argv[2], PCONTROL_HOST_OFF);18 if ( N < 0) {18 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); 19 if (!host) { 19 20 gprint (GP_LOG, "host %s is not OFF\n", argv[2]); 20 21 return (FALSE); 21 22 } 22 host = GetHost (PCONTROL_HOST_OFF, N);23 23 DownHost (host); 24 24 return (TRUE); 25 25 } 26 26 if (!strcasecmp (argv[1], "RETRY")) { 27 N = FindNamedHost (argv[2], PCONTROL_HOST_DOWN);28 if ( N < 0) {27 host = PullHostFromStackByName (PCONTROL_HOST_DOWN, argv[2]); 28 if (!host) { 29 29 gprint (GP_LOG, "host %s is not DOWN\n", argv[2]); 30 30 return (FALSE); 31 31 } 32 host = GetHost (PCONTROL_HOST_DOWN, N);32 /* reset time, place back on DOWN stack */ 33 33 host[0].nexttry.tv_sec = 0; 34 34 host[0].nexttry.tv_usec = 0; 35 35 host[0].lasttry.tv_sec = 0; 36 36 host[0].lasttry.tv_usec = 0; 37 StartHost (host);37 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 38 38 return (TRUE); 39 39 } 40 40 if (!strcasecmp (argv[1], "CHECK")) { 41 Ns = FindNamedHostStack (argv[2]);42 switch ( Ns) {41 host = PullHostByName (argv[2], &StackID); 42 switch (StackID) { 43 43 case PCONTROL_HOST_IDLE: 44 gprint (GP_LOG, "host %s is IDLE\n", argv[2]); 44 45 case PCONTROL_HOST_BUSY: 46 gprint (GP_LOG, "host %s is BUSY\n", argv[2]); 45 47 case PCONTROL_HOST_DONE: 46 N = FindNamedHost (argv[2], Ns); 47 host = GetHost (Ns, N); 48 if (CheckHost (host)) { 49 if (VerboseMode()) gprint (GP_ERR, "host %s is on\n", host[0].hostname); 50 } 51 return (TRUE); 48 gprint (GP_LOG, "host %s is DONE\n", argv[2]); 52 49 case PCONTROL_HOST_DOWN: 53 50 gprint (GP_LOG, "host %s is DOWN\n", argv[2]); 54 return (TRUE);55 51 case PCONTROL_HOST_OFF: 56 52 gprint (GP_LOG, "host %s is OFF\n", argv[2]); 57 return (TRUE);58 53 default: 59 54 gprint (GP_LOG, "host %s not found\n", argv[2]); 60 55 return (FALSE); 61 56 } 57 PutHost (host, StackID, STACK_BOTTOM); 62 58 return (FALSE); 63 59 } 64 60 if (!strcasecmp (argv[1], "OFF")) { 65 N = FindNamedHost (argv[2], PCONTROL_HOST_IDLE); 66 if (N >= 0) { 67 host = GetHost (PCONTROL_HOST_IDLE, N); 61 host = PullHostFromStackByName (PCONTROL_HOST_IDLE, argv[2]); 62 if (host) { 68 63 StopHost (host); 69 64 OffHost (host); 70 65 return (TRUE); 71 66 } 72 N = FindNamedHost (argv[2], PCONTROL_HOST_DOWN); 73 if (N >= 0) { 74 host = GetHost (PCONTROL_HOST_DOWN, N); 67 host = PullHostFromStackByName (PCONTROL_HOST_DOWN, argv[2]); 68 if (host) { 75 69 OffHost (host); 76 70 return (TRUE); 77 71 } 78 N = FindNamedHost (argv[2], PCONTROL_HOST_BUSY);79 if (N >= 0) {80 host = GetHost (PCONTROL_HOST_BUSY, N);72 /* XXX the 'markoff' flag is not being used */ 73 host = PullHostFromStackByName (PCONTROL_HOST_BUSY, argv[2]); 74 if (host) { 81 75 host[0].markoff = TRUE; 82 76 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); … … 87 81 } 88 82 if (!strcasecmp (argv[1], "DELETE")) { 89 N = FindNamedHost (argv[2], PCONTROL_HOST_OFF);90 if ( N < 0) {83 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); 84 if (!host) { 91 85 gprint (GP_LOG, "host %s is not OFF\n", argv[2]); 92 86 return (FALSE); 93 87 } 94 host = GetHost (PCONTROL_HOST_OFF, N);95 88 DelHost (host); 96 89 return (TRUE); -
trunk/Ohana/src/opihi/pcontrol/init.c
r4767 r8296 4 4 int delete PROTO((int, char **)); 5 5 int host PROTO((int, char **)); 6 int hoststack PROTO((int, char **)); 6 7 int job PROTO((int, char **)); 7 8 int jobstack PROTO((int, char **)); … … 17 18 18 19 static Command cmds[] = { 19 {"check", check, "get job or host status"},20 {"delete", delete, "delete job"},21 20 {"host", host, "add / delete / modify host"}, 22 {"job", job, "add job"}, 23 {"jobstack", jobstack, "list jobs for a single stack"}, 24 {"kill", kill_pc, "kill job"}, 25 {"pulse", pulse, "set system pulse"}, 21 {"hoststack", hoststack, "list hosts for a single stack"}, 26 22 {"status", status, "get system status"}, 27 23 {"stop", stop, "stop controller processing"}, 28 24 {"run", run, "start controller processing"}, 25 {"verbose", verbose, "set the verbose mode for job"}, 26 {"version", version, "show version information"}, 27 {"pulse", pulse, "set system pulse"}, 28 {"job", job, "add job"}, 29 {"jobstack", jobstack, "list jobs for a single stack"}, 30 {"check", check, "get job or host status"}, 31 {"delete", delete, "delete job"}, 32 {"kill", kill_pc, "kill job"}, 29 33 {"stderr", stderr_pc, "get stderr buffer for job"}, 30 34 {"stdout", stdout_pc, "get stdout buffer for job"}, 31 {"verbose", verbose, "set the verbose mode for job"},32 {"version", version, "show version information"},33 35 }; 34 36 … … 41 43 } 42 44 43 /* temporary : put this elsewhere? */45 /* XXX temporary : put this elsewhere? */ 44 46 InitJobStacks (); 45 47 InitHostStacks (); 46 47 48 } -
trunk/Ohana/src/opihi/pcontrol/job.c
r7917 r8296 6 6 int i, N, Mode, targc, Timeout; 7 7 IDtype JobID; 8 9 if (get_argument (argc, argv, "-host") && get_argument (argc, argv, "+host")) { 10 gprint (GP_ERR, "ERROR: -host and +host are incompatible\n"); 11 return (FALSE); 12 } 8 13 9 14 Host = NULL; … … 16 21 } 17 22 if ((N = get_argument (argc, argv, "+host"))) { 18 if (Mode == PCONTROL_JOB_WANTHOST) {19 gprint (GP_ERR, "ERROR: -host and +host are incompatible\n");20 FREE (Host);21 return (FALSE);22 }23 23 remove_argument (N, &argc, argv); 24 24 Host = strcreate (argv[N]); -
trunk/Ohana/src/opihi/pcontrol/jobstack.c
r7917 r8296 21 21 22 22 /* print list */ 23 LockStack (stack); 23 24 gprint (GP_LOG, "Njobs: %d\n", stack[0].Nobject); 24 25 for (i = 0; i < stack[0].Nobject; i++) { … … 28 29 gprint (GP_LOG, "%s %s\n", job[0].argv[0], job[0].hostname); 29 30 } 31 UnlockStack (stack); 32 30 33 return (TRUE); 31 34 } 35 36 // Safe with PTHREAD_MUTEX_INITIALIZER lock -
trunk/Ohana/src/opihi/pcontrol/kill.c
r7917 r8296 13 13 14 14 /* XXX this function should only fail if a process is hung */ 15 job = PullJob (JobID, PCONTROL_JOB_BUSY);15 job = PullJobFromStackByID (PCONTROL_JOB_BUSY, JobID); 16 16 if (job == NULL) { 17 17 gprint (GP_ERR, "job %s not BUSY\n", argv[1]); … … 20 20 } 21 21 22 /* XXX - check on success / failure of kill */ 23 KillJob (job); 24 22 PutJob (job, PCONTROL_JOB_KILL, STACK_BOTTOM); 25 23 return (TRUE); 26 24 } -
trunk/Ohana/src/opihi/pcontrol/run.c
r7917 r8296 12 12 return (TRUE); 13 13 } 14 15 int run_threaded (int argc, char **argv) { 16 17 if (argc != 1) { 18 gprint (GP_ERR, "USAGE: run\n"); 19 return (FALSE); 20 } 21 22 // some action 23 24 return (TRUE); 25 } -
trunk/Ohana/src/opihi/pcontrol/status.c
r7917 r8296 1 1 # include "pcontrol.h" 2 2 3 char jobname[ 6][32] = {"PENDING", "BUSY", "EXIT", "CRASH", "HUNG", "DONE"};4 char hostname[5][32] = {"IDLE", "BUSY", "DOWN", "DONE", "OFF"};3 char jobname[7][32] = {"PENDING", "BUSY", "HUNG", "DONE", "KILL", "EXIT", "CRASH"}; 4 char hostname[5][32] = {"IDLE", "BUSY", "DOWN", "DONE", "OFF"}; 5 5 6 6 int status (int argc, char **argv) { … … 9 9 PrintJobStack (PCONTROL_JOB_BUSY); 10 10 PrintJobStack (PCONTROL_JOB_DONE); 11 PrintJobStack (PCONTROL_JOB_KILL); 11 12 PrintJobStack (PCONTROL_JOB_EXIT); 12 13 PrintJobStack (PCONTROL_JOB_CRASH); … … 27 28 28 29 stack = GetJobStack (Nstack); 30 31 LockStack (stack); 29 32 Nobject = stack[0].Nobject; 30 33 gprint (GP_LOG, "job stack %s: %d objects\n", jobname[Nstack], Nobject); … … 39 42 gprint (GP_LOG, "\n"); 40 43 } 44 UnlockStack (stack); 45 41 46 return (TRUE); 42 47 } … … 49 54 50 55 stack = GetHostStack (Nstack); 56 57 LockStack (stack); 51 58 Nobject = stack[0].Nobject; 52 59 gprint (GP_LOG, "host stack %s: %d objects\n", hostname[Nstack], Nobject); … … 58 65 gprint (GP_LOG, "\n"); 59 66 } 67 UnlockStack (stack); 68 60 69 return (TRUE); 61 70 } 62 71 72 // Safe with PTHREAD_MUTEX_INITIALIZER lock -
trunk/Ohana/src/opihi/pcontrol/stdout.c
r7917 r8296 3 3 int stdout_pc (int argc, char **argv) { 4 4 5 int JobID ;5 int JobID, StackID; 6 6 Job *job; 7 7 IOBuffer *buffer; … … 15 15 /* find Job of interest (must be EXIT or CRASH) */ 16 16 JobID = atoi (argv[1]); 17 job = FindJobPtr (JobID, PCONTROL_JOB_EXIT);18 if (job == NULL) {19 job = FindJobPtr (JobID, PCONTROL_JOB_CRASH);20 if (job == NULL) goto missing_stdout;21 }22 17 18 StackID = PCONTROL_JOB_EXIT; 19 job = PullJobFromStackByID (StackID, JobID); 20 if (job != NULL) goto found_stdout; 21 22 StackID = PCONTROL_JOB_CRASH; 23 job = PullJobFromStackByID (StackID, JobID); 24 if (job != NULL) goto found_stdout; 25 26 gprint (GP_ERR, "job not found in EXIT or CRASH\n"); 27 gprint (GP_LOG, "STATUS %d\n", -2); 28 return (FALSE); 29 30 found_stdout: 23 31 buffer = &job[0].stdout; 24 32 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 25 33 gprint (GP_LOG, "STATUS %d\n", 0); 34 PutJob (job, StackID, STACK_BOTTOM); 26 35 return (TRUE); 27 28 missing_stdout:29 gprint (GP_ERR, "job not found in EXIT or CRASH\n");30 gprint (GP_LOG, "STATUS %d\n", -2);31 return (FALSE);32 36 } 33 37 34 38 int stderr_pc (int argc, char **argv) { 35 39 36 int JobID ;40 int JobID, StackID; 37 41 Job *job; 38 42 IOBuffer *buffer; … … 46 50 /* find Job of interest (must be EXIT or CRASH) */ 47 51 JobID = atoi (argv[1]); 48 job = FindJobPtr (JobID, PCONTROL_JOB_EXIT);49 if (job == NULL) {50 job = FindJobPtr (JobID, PCONTROL_JOB_CRASH);51 if (job == NULL) goto missing_stderr;52 }53 52 53 StackID = PCONTROL_JOB_EXIT; 54 job = PullJobFromStackByID (StackID, JobID); 55 if (job != NULL) goto found_stderr; 56 57 StackID = PCONTROL_JOB_CRASH; 58 job = PullJobFromStackByID (StackID, JobID); 59 if (job != NULL) goto found_stderr; 60 61 gprint (GP_ERR, "job not found in EXIT or CRASH\n"); 62 gprint (GP_LOG, "STATUS %d\n", -2); 63 return (FALSE); 64 65 found_stderr: 54 66 buffer = &job[0].stderr; 55 67 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 56 68 gprint (GP_LOG, "STATUS %d\n", 0); 69 PutJob (job, StackID, STACK_BOTTOM); 57 70 return (TRUE); 58 59 missing_stderr:60 gprint (GP_ERR, "job not found in EXIT or CRASH\n");61 gprint (GP_LOG, "STATUS %d\n", -2);62 return (FALSE);63 71 }
Note:
See TracChangeset
for help on using the changeset viewer.
