Changeset 4450 for trunk/Ohana/src/opihi/pcontrol/JobOps.c
- Timestamp:
- Jul 4, 2005, 5:35:47 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/JobOps.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/JobOps.c
r3212 r4450 35 35 } 36 36 37 Job *FindJobStack (IDtype JobID) { 38 39 Job *job; 40 41 job = FindJobPtr (JobID, PCONTROL_JOB_PENDING); 42 if (job != NULL) return (job); 43 44 job = FindJobPtr (JobID, PCONTROL_JOB_BUSY); 45 if (job != NULL) return (job); 46 47 job = FindJobPtr (JobID, PCONTROL_JOB_EXIT); 48 if (job != NULL) return (job); 49 50 job = FindJobPtr (JobID, PCONTROL_JOB_CRASH); 51 if (job != NULL) return (job); 52 53 job = FindJobPtr (JobID, PCONTROL_JOB_DONE); 54 if (job != NULL) return (job); 55 56 return (NULL); 57 } 58 59 /* add job to position in stack */ 37 60 int PutJob (Job *job, int StackID, int where) { 38 61 … … 51 74 } 52 75 76 /* remove job from position in stack */ 53 77 Job *GetJob (int StackID, int where) { 54 78 … … 63 87 } 64 88 89 /* return stack position of job */ 65 90 int FindJob (IDtype JobID, int StackID) { 66 91 … … 81 106 } 82 107 108 /* return pointer to job */ 109 Job *FindJobPtr (IDtype JobID, int StackID) { 110 111 int i; 112 Job *job; 113 Stack *stack; 114 115 stack = GetJobStack (StackID); 116 if (stack == NULL) return (NULL); 117 118 for (i = 0; i < stack[0].Nobject; i++) { 119 job = (Job *) stack[0].object[i]; 120 if (job[0].JobID == JobID) { 121 return (job); 122 } 123 } 124 return (NULL); 125 } 126 127 /* remove job from stack, return pointer */ 128 Job *PullJob (IDtype JobID, int StackID) { 129 130 int N; 131 Job *job; 132 133 N = FindJob (JobID, StackID); 134 if (N < 0) return (NULL); 135 136 job = GetJob (StackID, N); 137 if (job == NULL) { 138 fprintf (stderr, "programming error! job missing from stack\n"); 139 exit (1); 140 } 141 return (job); 142 } 143 83 144 IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) { 84 145 … … 89 150 job[0].argc = argc; 90 151 job[0].argv = argv; 91 job[0].hostname = strcreate (hostname);152 job[0].hostname = hostname; 92 153 job[0].mode = mode; 93 154 job[0].host = NULL; … … 119 180 } 120 181 121 # if (0) 122 void KillJob (Job *job) { 123 124 int status; 125 char line[64]; 126 Host *host; 127 128 sprintf (line, "reset\n"); 129 130 /* send command to client */ 131 status = write (host[0].stdin, line, strlen(line)); 132 if ((status == -1) && (errno == EPIPE)) { 133 fprintf (stderr, "host %s is down\n", host[0].hostname); 134 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 135 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 136 return (FALSE); 137 } 138 /* check for a response */ 139 140 /** this needs to be cleaned up to handle the slow response case **/ 141 } 142 # endif 143 182 /* unlink job and host, pull host from its stack */ 144 183 Host *UnlinkJobAndHost (Job *job) { 145 184 … … 147 186 Host *host; 148 187 149 host = job[0].host; 188 host = (Host *) job[0].host; 189 if (host == NULL) { 190 fprintf (stderr, "programming error: job has no host\n"); 191 exit (2); 192 } 150 193 151 194 /* unlink host & job */ … … 153 196 host[0].job = NULL; 154 197 155 /*** need to pop host off of correct stack XXX ***/ 156 N = FindHost (host[0].HostID, host[0].stack); 157 if (N < 0) { 198 /* remove host from correct stack */ 199 if (PullHost (host[0].HostID, host[0].stack) == NULL) { 158 200 fprintf (stderr, "programming error: host is not found in current stack\n"); 159 201 exit (2); 160 202 } 161 host = GetHost (host[0].stack, N);162 203 return (host); 163 204 } … … 166 207 int N; 167 208 168 job[0].host = host; 169 host[0].job = job; 170 171 # if (0) 172 /*** need to pop host off of correct stack XXX ***/ 173 N = FindHost (host[0].HostID, host[0].stack); 174 if (N < 0) { 175 fprintf (stderr, "programming error: host is not found in current stack\n"); 176 exit (2); 177 } 178 host = GetHost (host[0].stack, N); 179 # endif 180 181 /*** need to pop job off of correct stack XXX ***/ 182 N = FindJob (job[0].JobID, job[0].stack); 183 if (N < 0) { 209 job[0].host = (struct Host *) host; 210 host[0].job = (struct Job *) job; 211 212 /* remove job from correct stack */ 213 if (PullJob (job[0].JobID, job[0].stack) == NULL) { 184 214 fprintf (stderr, "programming error: job is not found in current stack\n"); 185 215 exit (2); 186 216 } 187 job = GetJob (job[0].stack, N); 188 189 /*** this is fairly crazy : the only reason this works is cause I 190 get the same host ptr here and in CheckIdleHost 191 ***/ 192 } 217 }
Note:
See TracChangeset
for help on using the changeset viewer.
