author | viric@llimona |
Sat, 09 Feb 2008 11:56:03 +0100 | |
changeset 196 | bca29e2a1a86 |
parent 190 | a1d9f881740e |
child 198 | 729eebc5c293 |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
|
4 |
||
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
8 | 7 |
#include <stdlib.h> |
44 | 8 |
#include <unistd.h> |
8 | 9 |
#include <stdio.h> |
44 | 10 |
#include <string.h> |
146 | 11 |
#include <sys/time.h> |
12 |
#include <time.h> |
|
32 | 13 |
#include "main.h" |
3 | 14 |
|
8 | 15 |
static enum |
16 |
{ |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
17 |
FREE, /* No task is running */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
18 |
WAITING /* A task is running, and the server is waiting */ |
8 | 19 |
} state = FREE; |
20 |
||
42 | 21 |
struct Notify |
22 |
{ |
|
23 |
int socket; |
|
24 |
int jobid; |
|
25 |
struct Notify *next; |
|
26 |
}; |
|
27 |
||
3 | 28 |
/* Globals */ |
29 |
static struct Job *firstjob = 0; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
30 |
static struct Job *first_finished_job = 0; |
44 | 31 |
static int jobids = 0; |
3 | 32 |
|
42 | 33 |
static struct Notify *first_notify = 0; |
34 |
||
5 | 35 |
static void send_list_line(int s, const char * str) |
36 |
{ |
|
37 |
struct msg m; |
|
38 |
||
21 | 39 |
/* Message */ |
5 | 40 |
m.type = LIST_LINE; |
146 | 41 |
m.u.size = strlen(str) + 1; |
5 | 42 |
|
21 | 43 |
send_msg(s, &m); |
44 |
||
45 |
/* Send the line */ |
|
146 | 46 |
send_bytes(s, str, m.u.size); |
5 | 47 |
} |
48 |
||
53 | 49 |
static void send_urgent_ok(int s) |
50 |
{ |
|
51 |
struct msg m; |
|
52 |
||
53 |
/* Message */ |
|
54 |
m.type = URGENT_OK; |
|
55 |
||
56 |
send_msg(s, &m); |
|
57 |
} |
|
58 |
||
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
59 |
static void send_swap_jobs_ok(int s) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
60 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
61 |
struct msg m; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
62 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
63 |
/* Message */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
64 |
m.type = SWAP_JOBS_OK; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
65 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
66 |
send_msg(s, &m); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
67 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
68 |
|
120 | 69 |
static struct Job * find_previous_job(const struct Job *final) |
53 | 70 |
{ |
71 |
struct Job *p; |
|
72 |
||
73 |
/* Show Queued or Running jobs */ |
|
74 |
p = firstjob; |
|
75 |
while(p != 0) |
|
76 |
{ |
|
77 |
if (p->next == final) |
|
78 |
return p; |
|
79 |
p = p->next; |
|
80 |
} |
|
81 |
||
82 |
return 0; |
|
83 |
} |
|
84 |
||
22 | 85 |
static struct Job * findjob(int jobid) |
86 |
{ |
|
87 |
struct Job *p; |
|
88 |
||
89 |
/* Show Queued or Running jobs */ |
|
90 |
p = firstjob; |
|
91 |
while(p != 0) |
|
92 |
{ |
|
93 |
if (p->jobid == jobid) |
|
94 |
return p; |
|
95 |
p = p->next; |
|
96 |
} |
|
97 |
||
98 |
return 0; |
|
99 |
} |
|
100 |
||
32 | 101 |
static struct Job * find_finished_job(int jobid) |
102 |
{ |
|
103 |
struct Job *p; |
|
104 |
||
105 |
/* Show Queued or Running jobs */ |
|
106 |
p = first_finished_job; |
|
107 |
while(p != 0) |
|
108 |
{ |
|
109 |
if (p->jobid == jobid) |
|
110 |
return p; |
|
111 |
p = p->next; |
|
112 |
} |
|
113 |
||
114 |
return 0; |
|
115 |
} |
|
116 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
117 |
void s_mark_job_running() |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
118 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
119 |
firstjob->state = RUNNING; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
120 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
121 |
|
63 | 122 |
const char * jstate2string(enum Jobstate s) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
123 |
{ |
120 | 124 |
const char * jobstate; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
125 |
switch(s) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
126 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
127 |
case QUEUED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
128 |
jobstate = "queued"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
129 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
130 |
case RUNNING: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
131 |
jobstate = "running"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
132 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
133 |
case FINISHED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
134 |
jobstate = "finished"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
135 |
break; |
156 | 136 |
case SKIPPED: |
137 |
jobstate = "skipped"; |
|
138 |
break; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
139 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
140 |
return jobstate; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
141 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
142 |
|
3 | 143 |
void s_list(int s) |
144 |
{ |
|
145 |
struct Job *p; |
|
117 | 146 |
char *buffer; |
3 | 147 |
|
114 | 148 |
/* Times: 0.00/0.00/0.00 - 4+4+4+2 = 14*/ |
117 | 149 |
buffer = joblist_headers(); |
5 | 150 |
send_list_line(s,buffer); |
117 | 151 |
free(buffer); |
3 | 152 |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
153 |
/* Show Queued or Running jobs */ |
3 | 154 |
p = firstjob; |
155 |
while(p != 0) |
|
156 |
{ |
|
117 | 157 |
buffer = joblist_line(p); |
5 | 158 |
send_list_line(s,buffer); |
117 | 159 |
free(buffer); |
3 | 160 |
p = p->next; |
161 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
162 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
163 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
164 |
|
120 | 165 |
/* Show Finished jobs */ |
166 |
while(p != 0) |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
167 |
{ |
120 | 168 |
buffer = joblist_line(p); |
169 |
send_list_line(s,buffer); |
|
170 |
free(buffer); |
|
171 |
p = p->next; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
172 |
} |
3 | 173 |
} |
174 |
||
175 |
static struct Job * newjobptr() |
|
176 |
{ |
|
177 |
struct Job *p; |
|
178 |
||
179 |
if (firstjob == 0) |
|
180 |
{ |
|
181 |
firstjob = (struct Job *) malloc(sizeof(*firstjob)); |
|
182 |
firstjob->next = 0; |
|
64 | 183 |
firstjob->output_filename = 0; |
184 |
firstjob->command = 0; |
|
3 | 185 |
return firstjob; |
186 |
} |
|
187 |
||
188 |
p = firstjob; |
|
189 |
while(p->next != 0) |
|
190 |
p = p->next; |
|
191 |
||
192 |
p->next = (struct Job *) malloc(sizeof(*p)); |
|
193 |
p->next->next = 0; |
|
64 | 194 |
p->next->output_filename = 0; |
195 |
p->next->command = 0; |
|
3 | 196 |
|
197 |
return p->next; |
|
198 |
} |
|
199 |
||
200 |
/* Returns job id */ |
|
18 | 201 |
int s_newjob(int s, struct msg *m) |
3 | 202 |
{ |
203 |
struct Job *p; |
|
18 | 204 |
int res; |
3 | 205 |
|
206 |
p = newjobptr(); |
|
207 |
||
208 |
p->jobid = jobids++; |
|
209 |
p->state = QUEUED; |
|
27
886bdb2f4632
Fixed the Output File information in the list.
viric@llimona
parents:
26
diff
changeset
|
210 |
p->store_output = m->u.newjob.store_output; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
54
diff
changeset
|
211 |
p->should_keep_finished = m->u.newjob.should_keep_finished; |
155 | 212 |
p->depend = m->u.newjob.depend; |
18 | 213 |
|
147 | 214 |
pinfo_init(&p->info); |
146 | 215 |
pinfo_set_enqueue_time(&p->info); |
216 |
||
18 | 217 |
/* load the command */ |
218 |
p->command = malloc(m->u.newjob.command_size); |
|
147 | 219 |
if (p->command == 0) |
220 |
error("Cannot allocate memory in s_newjob command_size (%i)", |
|
221 |
m->u.newjob.command_size); |
|
18 | 222 |
res = recv_bytes(s, p->command, m->u.newjob.command_size); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
223 |
if (res == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
224 |
error("wrong bytes received"); |
3 | 225 |
|
150 | 226 |
/* load the label */ |
227 |
p->label = 0; |
|
228 |
if (m->u.newjob.label_size > 0) |
|
229 |
{ |
|
230 |
char *ptr; |
|
231 |
ptr = (char *) malloc(m->u.newjob.label_size); |
|
232 |
if (ptr == 0) |
|
233 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
234 |
m->u.newjob.env_size); |
|
235 |
res = recv_bytes(s, ptr, m->u.newjob.label_size); |
|
236 |
if (res == -1) |
|
237 |
error("wrong bytes received"); |
|
238 |
p->label = ptr; |
|
239 |
} |
|
240 |
||
147 | 241 |
/* load the info */ |
242 |
if (m->u.newjob.env_size > 0) |
|
243 |
{ |
|
244 |
char *ptr; |
|
245 |
ptr = (char *) malloc(m->u.newjob.env_size); |
|
246 |
if (ptr == 0) |
|
247 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
248 |
m->u.newjob.env_size); |
|
249 |
res = recv_bytes(s, ptr, m->u.newjob.env_size); |
|
250 |
if (res == -1) |
|
251 |
error("wrong bytes received"); |
|
252 |
pinfo_addinfo(&p->info, m->u.newjob.env_size+100, |
|
253 |
"Environment:\n%s", ptr); |
|
254 |
free(ptr); |
|
255 |
} |
|
256 |
||
3 | 257 |
return p->jobid; |
258 |
} |
|
259 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
260 |
/* This assumes the jobid exists */ |
3 | 261 |
void s_removejob(int jobid) |
262 |
{ |
|
263 |
struct Job *p; |
|
264 |
struct Job *newnext; |
|
265 |
||
266 |
if (firstjob->jobid == jobid) |
|
267 |
{ |
|
268 |
struct Job *newfirst; |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
269 |
|
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
270 |
if (state == WAITING) |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
271 |
state = FREE; |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
272 |
|
3 | 273 |
/* First job is to be removed */ |
274 |
newfirst = firstjob->next; |
|
18 | 275 |
free(firstjob->command); |
64 | 276 |
free(firstjob->output_filename); |
148 | 277 |
pinfo_free(&firstjob->info); |
150 | 278 |
free(firstjob->label); |
3 | 279 |
free(firstjob); |
280 |
firstjob = newfirst; |
|
281 |
return; |
|
282 |
} |
|
283 |
||
284 |
p = firstjob; |
|
285 |
/* Not first job */ |
|
286 |
while (p->next != 0) |
|
287 |
{ |
|
288 |
if (p->next->jobid == jobid) |
|
289 |
break; |
|
290 |
p = p->next; |
|
291 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
292 |
if (p->next == 0) |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
293 |
error("Job to be removed not found. jobid=%i", jobid); |
3 | 294 |
|
295 |
newnext = p->next->next; |
|
296 |
||
18 | 297 |
free(p->next->command); |
3 | 298 |
free(p->next); |
299 |
p->next = newnext; |
|
300 |
} |
|
8 | 301 |
|
302 |
/* -1 if no one should be run. */ |
|
303 |
int next_run_job() |
|
304 |
{ |
|
305 |
if (state == WAITING) |
|
306 |
return -1; |
|
307 |
||
308 |
if (firstjob != 0) |
|
9 | 309 |
{ |
310 |
state = WAITING; |
|
8 | 311 |
return firstjob->jobid; |
9 | 312 |
} |
8 | 313 |
|
314 |
return -1; |
|
315 |
} |
|
316 |
||
64 | 317 |
/* Returns 1000 if no limit, The limit otherwise. */ |
318 |
static int get_max_finished_jobs() |
|
319 |
{ |
|
320 |
char *limit; |
|
321 |
||
322 |
limit = getenv("TS_MAXFINISHED"); |
|
323 |
if (limit == NULL) |
|
324 |
return 1000; |
|
325 |
return abs(atoi(limit)); |
|
326 |
} |
|
327 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
328 |
/* Add the job to the finished queue. */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
329 |
static void new_finished_job(struct Job *j) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
330 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
331 |
struct Job *p; |
64 | 332 |
int count, max; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
333 |
|
64 | 334 |
max = get_max_finished_jobs(); |
335 |
count = 0; |
|
336 |
||
337 |
if (first_finished_job == 0 && count < max) |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
338 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
339 |
first_finished_job = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
340 |
first_finished_job->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
341 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
342 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
343 |
|
64 | 344 |
++count; |
345 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
346 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
347 |
while(p->next != 0) |
64 | 348 |
{ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
349 |
p = p->next; |
64 | 350 |
++count; |
351 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
352 |
|
64 | 353 |
/* If too many jobs, wipe out the first */ |
354 |
if (count >= max) |
|
355 |
{ |
|
356 |
struct Job *tmp; |
|
357 |
tmp = first_finished_job; |
|
358 |
first_finished_job = first_finished_job->next; |
|
359 |
free(tmp->command); |
|
360 |
free(tmp->output_filename); |
|
148 | 361 |
pinfo_free(&tmp->info); |
150 | 362 |
free(tmp->label); |
64 | 363 |
free(tmp); |
364 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
365 |
p->next = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
366 |
p->next->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
367 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
368 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
369 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
370 |
|
114 | 371 |
void job_finished(const struct Result *result) |
8 | 372 |
{ |
373 |
struct Job *newfirst; |
|
374 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
375 |
if (state != WAITING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
376 |
error("Wrong state in the server. Not WAITING, but %i", state); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
377 |
if (firstjob == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
378 |
error("on job finished, firstjob values %x", firstjob); |
8 | 379 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
380 |
if (firstjob->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
381 |
error("on job finished, the firstjob is not running but %i", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
382 |
firstjob->state); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
383 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
384 |
/* Mark state */ |
156 | 385 |
if (result->skipped) |
386 |
firstjob->state = SKIPPED; |
|
387 |
else |
|
388 |
firstjob->state = FINISHED; |
|
114 | 389 |
firstjob->result = *result; |
146 | 390 |
pinfo_set_end_time(&firstjob->info); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
391 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
392 |
/* Add it to the finished queue */ |
26 | 393 |
newfirst = firstjob->next; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
54
diff
changeset
|
394 |
if (firstjob->should_keep_finished) |
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
54
diff
changeset
|
395 |
new_finished_job(firstjob); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
396 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
397 |
/* Remove it from the run queue */ |
26 | 398 |
firstjob = newfirst; |
8 | 399 |
|
400 |
state = FREE; |
|
401 |
} |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
402 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
403 |
void s_clear_finished() |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
404 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
405 |
struct Job *p; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
406 |
|
22 | 407 |
if (first_finished_job == 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
408 |
return; |
22 | 409 |
|
410 |
p = first_finished_job; |
|
411 |
first_finished_job = 0; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
412 |
|
64 | 413 |
while (p != 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
414 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
415 |
struct Job *tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
416 |
tmp = p->next; |
22 | 417 |
free(p->command); |
418 |
free(p->output_filename); |
|
148 | 419 |
pinfo_free(&p->info); |
150 | 420 |
free(p->label); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
421 |
free(p); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
422 |
p = tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
423 |
} |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
424 |
} |
22 | 425 |
|
35 | 426 |
void s_process_runjob_ok(int jobid, char *oname, int pid) |
22 | 427 |
{ |
428 |
struct Job *p; |
|
429 |
p = findjob(jobid); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
430 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
431 |
error("Job %i already run not found on runjob_ok", jobid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
432 |
if (p->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
433 |
error("Job %i not running, but %i on runjob_ok", jobid, |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
434 |
p->state); |
22 | 435 |
|
35 | 436 |
p->pid = pid; |
22 | 437 |
p->output_filename = oname; |
146 | 438 |
pinfo_set_start_time(&p->info); |
439 |
} |
|
440 |
||
441 |
void s_job_info(int s, int jobid) |
|
442 |
{ |
|
443 |
struct Job *p = 0; |
|
444 |
struct msg m; |
|
445 |
||
446 |
if (jobid == -1) |
|
447 |
{ |
|
448 |
/* This means that we want the job info of the running task, or that |
|
449 |
* of the last job run */ |
|
450 |
if (state == WAITING) |
|
451 |
{ |
|
452 |
p = firstjob; |
|
453 |
if (p == 0) |
|
454 |
error("Internal state WAITING, but job not run." |
|
455 |
"firstjob = %x", firstjob); |
|
456 |
} |
|
457 |
else |
|
458 |
{ |
|
459 |
p = first_finished_job; |
|
460 |
if (p == 0) |
|
461 |
{ |
|
462 |
send_list_line(s, "No jobs.\n"); |
|
463 |
return; |
|
464 |
} |
|
465 |
while(p->next != 0) |
|
466 |
p = p->next; |
|
467 |
} |
|
468 |
} else |
|
469 |
{ |
|
154
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
470 |
p = firstjob; |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
471 |
while (p != 0 && p->jobid != jobid) |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
472 |
p = p->next; |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
473 |
|
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
474 |
/* Look in finished jobs if needed */ |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
475 |
if (p == 0) |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
476 |
{ |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
477 |
p = first_finished_job; |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
478 |
while (p != 0 && p->jobid != jobid) |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
479 |
p = p->next; |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
480 |
} |
146 | 481 |
} |
482 |
||
483 |
if (p == 0) |
|
484 |
{ |
|
485 |
char tmp[50]; |
|
486 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
|
487 |
send_list_line(s, tmp); |
|
488 |
return; |
|
489 |
} |
|
490 |
||
491 |
m.type = INFO_DATA; |
|
492 |
send_msg(s, &m); |
|
493 |
pinfo_dump(&p->info, s); |
|
156 | 494 |
fd_nprintf(s, 100, "Command: %s", p->depend?"&& ":""); |
154
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
495 |
write(s, p->command, strlen(p->command)); |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
496 |
fd_nprintf(s, 100, "\n"); |
146 | 497 |
fd_nprintf(s, 100, "Enqueue time: %s", |
498 |
ctime(&p->info.enqueue_time.tv_sec)); |
|
499 |
if (p->state == RUNNING) |
|
500 |
{ |
|
501 |
fd_nprintf(s, 100, "Start time: %s", |
|
502 |
ctime(&p->info.start_time.tv_sec)); |
|
503 |
fd_nprintf(s, 100, "Time running: %fs\n", |
|
504 |
pinfo_time_until_now(&p->info)); |
|
505 |
} else if (p->state == FINISHED) |
|
506 |
{ |
|
507 |
fd_nprintf(s, 100, "Start time: %s", |
|
508 |
ctime(&p->info.start_time.tv_sec)); |
|
509 |
fd_nprintf(s, 100, "End time: %s", |
|
510 |
ctime(&p->info.end_time.tv_sec)); |
|
511 |
fd_nprintf(s, 100, "Time run: %fs\n", |
|
512 |
pinfo_time_run(&p->info)); |
|
513 |
} |
|
22 | 514 |
} |
32 | 515 |
|
516 |
void s_send_output(int s, int jobid) |
|
517 |
{ |
|
518 |
struct Job *p = 0; |
|
519 |
struct msg m; |
|
520 |
||
521 |
if (jobid == -1) |
|
522 |
{ |
|
146 | 523 |
/* This means that we want the output info of the running task, or that |
32 | 524 |
* of the last job run */ |
525 |
if (state == WAITING) |
|
526 |
{ |
|
527 |
p = firstjob; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
528 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
529 |
error("Internal state WAITING, but job not run." |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
530 |
"firstjob = %x", firstjob); |
32 | 531 |
} |
532 |
else |
|
533 |
{ |
|
534 |
p = first_finished_job; |
|
535 |
if (p == 0) |
|
536 |
{ |
|
537 |
send_list_line(s, "No jobs.\n"); |
|
538 |
return; |
|
539 |
} |
|
540 |
while(p->next != 0) |
|
541 |
p = p->next; |
|
542 |
} |
|
543 |
} else |
|
544 |
{ |
|
545 |
if (state == WAITING && firstjob->jobid == jobid) |
|
546 |
p = firstjob; |
|
547 |
else |
|
548 |
p = find_finished_job(jobid); |
|
549 |
} |
|
550 |
||
551 |
if (p == 0) |
|
552 |
{ |
|
553 |
char tmp[50]; |
|
196
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
554 |
if (jobid == -1) |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
555 |
sprintf(tmp, "The last job has not finished or is not running.\n"); |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
556 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
557 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
32 | 558 |
send_list_line(s, tmp); |
559 |
return; |
|
560 |
} |
|
561 |
||
157 | 562 |
if (p->state == SKIPPED) |
156 | 563 |
{ |
564 |
char tmp[50]; |
|
196
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
565 |
if (jobid == -1) |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
566 |
sprintf(tmp, "The last job was skipped due to a dependency.\n"); |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
567 |
|
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
568 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
569 |
sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid); |
156 | 570 |
send_list_line(s, tmp); |
571 |
return; |
|
572 |
} |
|
573 |
||
32 | 574 |
m.type = ANSWER_OUTPUT; |
575 |
m.u.output.store_output = p->store_output; |
|
35 | 576 |
m.u.output.pid = p->pid; |
153 | 577 |
if (m.u.output.store_output) |
578 |
m.u.output.ofilename_size = strlen(p->output_filename) + 1; |
|
579 |
else |
|
580 |
m.u.output.ofilename_size = 0; |
|
32 | 581 |
send_msg(s, &m); |
582 |
send_bytes(s, p->output_filename, m.u.output.ofilename_size); |
|
583 |
} |
|
41 | 584 |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
585 |
int s_remove_job(int s, int jobid) |
41 | 586 |
{ |
587 |
struct Job *p = 0; |
|
588 |
struct msg m; |
|
589 |
struct Job *before_p = 0; |
|
590 |
||
591 |
if (jobid == -1) |
|
592 |
{ |
|
593 |
/* Find the last job added */ |
|
594 |
p = firstjob; |
|
595 |
if (p != 0) |
|
596 |
{ |
|
190 | 597 |
jobid = p->jobid; |
41 | 598 |
while (p->next != 0) |
599 |
{ |
|
600 |
before_p = p; |
|
601 |
p = p->next; |
|
190 | 602 |
jobid = p->jobid; |
41 | 603 |
} |
180 | 604 |
} else |
605 |
{ |
|
606 |
/* last 'finished' */ |
|
607 |
p = first_finished_job; |
|
190 | 608 |
if (p) |
180 | 609 |
{ |
190 | 610 |
jobid = p->jobid; |
611 |
while (p->next != 0) |
|
612 |
{ |
|
613 |
before_p = p; |
|
614 |
jobid = p->jobid; |
|
615 |
p = p->next; |
|
616 |
} |
|
180 | 617 |
} |
41 | 618 |
} |
619 |
} |
|
620 |
else |
|
621 |
{ |
|
622 |
p = firstjob; |
|
623 |
if (p != 0) |
|
624 |
{ |
|
625 |
while (p->next != 0 && p->jobid != jobid) |
|
626 |
{ |
|
627 |
before_p = p; |
|
628 |
p = p->next; |
|
629 |
} |
|
630 |
} |
|
180 | 631 |
|
632 |
/* If not found, look in the 'finished' list */ |
|
633 |
if (p == 0 || p->jobid != jobid) |
|
634 |
{ |
|
635 |
p = first_finished_job; |
|
636 |
if (p != 0) |
|
637 |
{ |
|
638 |
while (p->next != 0 && p->jobid != jobid) |
|
639 |
{ |
|
640 |
before_p = p; |
|
641 |
p = p->next; |
|
642 |
} |
|
643 |
} |
|
644 |
} |
|
41 | 645 |
} |
646 |
||
182
e4c03200b149
Fixed a problem in -r, when the jobid wasn't found.
viric@llimona
parents:
180
diff
changeset
|
647 |
if (p == 0 || p->state == RUNNING || p == firstjob || p->jobid != jobid) |
41 | 648 |
{ |
649 |
char tmp[50]; |
|
650 |
if (jobid == -1) |
|
44 | 651 |
sprintf(tmp, "The last job cannot be removed.\n"); |
41 | 652 |
else |
653 |
sprintf(tmp, "The job %i cannot be removed.\n", jobid); |
|
654 |
send_list_line(s, tmp); |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
655 |
return 0; |
41 | 656 |
} |
657 |
||
178
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
658 |
/* Tricks for the check_notify_list */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
659 |
p->state = FINISHED; |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
660 |
p->result.errorlevel = -1; |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
661 |
/* Notify the clients in wait_job */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
662 |
check_notify_list(m.u.jobid); |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
663 |
|
180 | 664 |
/* Update the list pointers */ |
665 |
if (p == first_finished_job) |
|
666 |
first_finished_job = p->next; |
|
667 |
else |
|
668 |
before_p->next = p->next; |
|
669 |
||
64 | 670 |
free(p->command); |
671 |
free(p->output_filename); |
|
146 | 672 |
pinfo_free(&p->info); |
150 | 673 |
free(p->label); |
41 | 674 |
free(p); |
180 | 675 |
|
41 | 676 |
m.type = REMOVEJOB_OK; |
677 |
send_msg(s, &m); |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
678 |
return 1; |
41 | 679 |
} |
42 | 680 |
|
681 |
static void add_to_notify_list(int s, int jobid) |
|
682 |
{ |
|
683 |
struct Notify *n; |
|
684 |
struct Notify *new; |
|
685 |
||
686 |
new = (struct Notify *) malloc(sizeof(*n)); |
|
687 |
||
688 |
new->socket = s; |
|
689 |
new->jobid = jobid; |
|
690 |
new->next = 0; |
|
691 |
||
692 |
n = first_notify; |
|
693 |
if (n == 0) |
|
694 |
{ |
|
695 |
first_notify = new; |
|
696 |
return; |
|
697 |
} |
|
698 |
||
699 |
while(n->next != 0) |
|
700 |
n = n->next; |
|
701 |
||
702 |
n->next = new; |
|
703 |
} |
|
704 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
705 |
static void send_waitjob_ok(int s, int errorlevel) |
42 | 706 |
{ |
707 |
struct msg m; |
|
708 |
||
709 |
m.type = WAITJOB_OK; |
|
112 | 710 |
m.u.result.errorlevel = errorlevel; |
42 | 711 |
send_msg(s, &m); |
712 |
} |
|
713 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
714 |
static struct Job * |
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
715 |
get_job(int jobid) |
42 | 716 |
{ |
717 |
struct Job *j; |
|
718 |
||
719 |
j = findjob(jobid); |
|
720 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
721 |
return j; |
42 | 722 |
|
723 |
j = find_finished_job(jobid); |
|
724 |
||
725 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
726 |
return j; |
42 | 727 |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
728 |
return 0; |
42 | 729 |
} |
730 |
||
731 |
/* Don't complain, if the socket doesn't exist */ |
|
732 |
void s_remove_notification(int s) |
|
733 |
{ |
|
734 |
struct Notify *n; |
|
735 |
struct Notify *previous; |
|
736 |
n = first_notify; |
|
737 |
while (n != 0 && n->socket != s) |
|
738 |
n = n->next; |
|
176
306890eeeffa
Fixing a bug on s_remove_job, related to -w and dying with signals
viric@llimona
parents:
166
diff
changeset
|
739 |
if (n == 0 || n->socket != s) |
42 | 740 |
return; |
741 |
||
742 |
/* Remove the notification */ |
|
743 |
previous = first_notify; |
|
744 |
if (n == previous) |
|
745 |
{ |
|
746 |
free(first_notify); |
|
747 |
first_notify = 0; |
|
748 |
return; |
|
749 |
} |
|
750 |
||
751 |
/* if not the first... */ |
|
752 |
while(previous->next != n) |
|
753 |
previous = previous->next; |
|
754 |
||
755 |
previous->next = n->next; |
|
756 |
free(n); |
|
757 |
} |
|
758 |
||
759 |
/* This is called when a job finishes */ |
|
760 |
void check_notify_list(int jobid) |
|
761 |
{ |
|
762 |
struct Notify *n; |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
763 |
struct Job *j; |
42 | 764 |
|
765 |
n = first_notify; |
|
766 |
while (n != 0 && n->jobid != jobid) |
|
767 |
{ |
|
768 |
n = n->next; |
|
769 |
} |
|
770 |
||
771 |
if (n == 0) |
|
772 |
{ |
|
773 |
return; |
|
774 |
} |
|
775 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
776 |
j = get_job(jobid); |
42 | 777 |
/* If the job finishes, notify the waiter */ |
166
8c19a66b5407
Fixing a bug on wait_job on skipped jobs. Moving vnumber to 0.5
viric@vicerveza
parents:
157
diff
changeset
|
778 |
if (j->state == FINISHED || j->state == SKIPPED) |
42 | 779 |
{ |
112 | 780 |
send_waitjob_ok(n->socket, j->result.errorlevel); |
42 | 781 |
s_remove_notification(n->socket); |
782 |
} |
|
783 |
} |
|
784 |
||
785 |
void s_wait_job(int s, int jobid) |
|
786 |
{ |
|
787 |
struct Job *p = 0; |
|
788 |
||
789 |
if (jobid == -1) |
|
790 |
{ |
|
791 |
/* Find the last job added */ |
|
792 |
p = firstjob; |
|
793 |
||
794 |
if (p != 0) |
|
795 |
while (p->next != 0) |
|
796 |
p = p->next; |
|
797 |
||
798 |
/* Look in finished jobs if needed */ |
|
799 |
if (p == 0) |
|
800 |
{ |
|
801 |
p = first_finished_job; |
|
802 |
if (p != 0) |
|
803 |
while (p->next != 0) |
|
804 |
p = p->next; |
|
805 |
} |
|
806 |
} |
|
807 |
else |
|
808 |
{ |
|
809 |
p = firstjob; |
|
810 |
while (p != 0 && p->jobid != jobid) |
|
811 |
p = p->next; |
|
812 |
||
813 |
/* Look in finished jobs if needed */ |
|
814 |
if (p == 0) |
|
815 |
{ |
|
816 |
p = first_finished_job; |
|
817 |
while (p != 0 && p->jobid != jobid) |
|
818 |
p = p->next; |
|
819 |
} |
|
820 |
} |
|
821 |
||
822 |
if (p == 0) |
|
823 |
{ |
|
824 |
char tmp[50]; |
|
825 |
if (jobid == -1) |
|
44 | 826 |
sprintf(tmp, "The last job cannot be waited.\n"); |
42 | 827 |
else |
828 |
sprintf(tmp, "The job %i cannot be waited.\n", jobid); |
|
829 |
send_list_line(s, tmp); |
|
830 |
return; |
|
831 |
} |
|
832 |
||
166
8c19a66b5407
Fixing a bug on wait_job on skipped jobs. Moving vnumber to 0.5
viric@vicerveza
parents:
157
diff
changeset
|
833 |
if (p->state == FINISHED || p->state == SKIPPED) |
42 | 834 |
{ |
112 | 835 |
send_waitjob_ok(s, p->result.errorlevel); |
42 | 836 |
} |
837 |
else |
|
838 |
add_to_notify_list(s, p->jobid); |
|
839 |
} |
|
53 | 840 |
|
841 |
void s_move_urgent(int s, int jobid) |
|
842 |
{ |
|
843 |
struct Job *p = 0; |
|
844 |
struct Job *tmp1; |
|
845 |
||
846 |
if (jobid == -1) |
|
847 |
{ |
|
848 |
/* Find the last job added */ |
|
849 |
p = firstjob; |
|
850 |
||
851 |
if (p != 0) |
|
852 |
while (p->next != 0) |
|
853 |
p = p->next; |
|
854 |
} |
|
855 |
else |
|
856 |
{ |
|
857 |
p = firstjob; |
|
858 |
while (p != 0 && p->jobid != jobid) |
|
859 |
p = p->next; |
|
860 |
} |
|
861 |
||
862 |
if (p == 0 || firstjob->next == 0) |
|
863 |
{ |
|
864 |
char tmp[50]; |
|
865 |
if (jobid == -1) |
|
866 |
sprintf(tmp, "The last job cannot be urged.\n"); |
|
867 |
else |
|
868 |
sprintf(tmp, "The job %i cannot be urged.\n", jobid); |
|
869 |
send_list_line(s, tmp); |
|
870 |
return; |
|
871 |
} |
|
872 |
||
873 |
/* Interchange the pointers */ |
|
874 |
tmp1 = find_previous_job(p); |
|
875 |
tmp1->next = p->next; |
|
876 |
p->next = firstjob->next; |
|
877 |
firstjob->next = p; |
|
878 |
||
879 |
||
880 |
send_urgent_ok(s); |
|
881 |
} |
|
63 | 882 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
883 |
void s_swap_jobs(int s, int jobid1, int jobid2) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
884 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
885 |
struct Job *p1, *p2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
886 |
struct Job *prev1, *prev2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
887 |
struct Job *tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
888 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
889 |
p1 = findjob(jobid1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
890 |
p2 = findjob(jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
891 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
892 |
if (p1 == 0 || p2 == 0 || p1 == firstjob || p2 == firstjob) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
893 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
894 |
char prev[60]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
895 |
sprintf(prev, "The jobs %i and %i cannot be swapped.\n", jobid1, jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
896 |
send_list_line(s, prev); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
897 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
898 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
899 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
900 |
/* Interchange the pointers */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
901 |
prev1 = find_previous_job(p1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
902 |
prev2 = find_previous_job(p2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
903 |
prev1->next = p2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
904 |
prev2->next = p1; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
905 |
tmp = p1->next; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
906 |
p1->next = p2->next; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
907 |
p2->next = tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
908 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
909 |
send_swap_jobs_ok(s); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
910 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
911 |
|
63 | 912 |
static void send_state(int s, enum Jobstate state) |
913 |
{ |
|
914 |
struct msg m; |
|
915 |
||
916 |
m.type = ANSWER_STATE; |
|
917 |
m.u.state = state; |
|
918 |
||
919 |
send_msg(s, &m); |
|
920 |
} |
|
921 |
||
922 |
void s_send_state(int s, int jobid) |
|
923 |
{ |
|
924 |
struct Job *p = 0; |
|
925 |
||
926 |
if (jobid == -1) |
|
927 |
{ |
|
928 |
/* Find the last job added */ |
|
929 |
p = firstjob; |
|
930 |
||
931 |
if (p != 0) |
|
932 |
while (p->next != 0) |
|
933 |
p = p->next; |
|
934 |
||
935 |
/* Look in finished jobs if needed */ |
|
936 |
if (p == 0) |
|
937 |
{ |
|
938 |
p = first_finished_job; |
|
939 |
if (p != 0) |
|
940 |
while (p->next != 0) |
|
941 |
p = p->next; |
|
942 |
} |
|
943 |
||
944 |
} |
|
945 |
else |
|
946 |
{ |
|
947 |
p = get_job(jobid); |
|
948 |
} |
|
949 |
||
950 |
if (p == 0) |
|
951 |
{ |
|
952 |
char tmp[50]; |
|
953 |
if (jobid == -1) |
|
954 |
sprintf(tmp, "The last job cannot be stated.\n"); |
|
955 |
else |
|
956 |
sprintf(tmp, "The job %i cannot be stated.\n", jobid); |
|
957 |
send_list_line(s, tmp); |
|
958 |
return; |
|
959 |
} |
|
960 |
||
961 |
/* Interchange the pointers */ |
|
962 |
send_state(s, p->state); |
|
963 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
964 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
965 |
static void dump_job_struct(FILE *out, const struct Job *p) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
966 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
967 |
fprintf(out, " new_job\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
968 |
fprintf(out, " jobid %i\n", p->jobid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
969 |
fprintf(out, " command \"%s\"\n", p->command); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
970 |
fprintf(out, " state %s\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
971 |
jstate2string(p->state)); |
112 | 972 |
fprintf(out, " result.errorlevel %i\n", p->result.errorlevel); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
973 |
fprintf(out, " output_filename \"%s\"\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
974 |
p->output_filename ? p->output_filename : "NULL"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
975 |
fprintf(out, " store_output %i\n", p->store_output); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
976 |
fprintf(out, " pid %i\n", p->pid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
977 |
fprintf(out, " should_keep_finished %i\n", p->pid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
978 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
979 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
980 |
void dump_jobs_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
981 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
982 |
const struct Job *p; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
983 |
|
104 | 984 |
fprintf(out, "New_jobs\n"); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
985 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
986 |
p = firstjob; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
987 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
988 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
989 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
990 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
991 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
992 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
993 |
p = first_finished_job; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
994 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
995 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
996 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
997 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
998 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
999 |
} |
120 | 1000 |
|
1001 |
void joblist_dump(int fd) |
|
1002 |
{ |
|
1003 |
struct Job *p; |
|
1004 |
char *buffer; |
|
1005 |
||
1006 |
buffer = joblistdump_headers(); |
|
1007 |
write(fd,buffer, strlen(buffer)); |
|
1008 |
free(buffer); |
|
1009 |
||
1010 |
/* We reuse the headers from the list */ |
|
1011 |
buffer = joblist_headers(); |
|
1012 |
write(fd, "# ", 2); |
|
1013 |
write(fd, buffer, strlen(buffer)); |
|
1014 |
||
1015 |
/* Show Finished jobs */ |
|
1016 |
p = first_finished_job; |
|
1017 |
while(p != 0) |
|
1018 |
{ |
|
1019 |
buffer = joblist_line(p); |
|
1020 |
write(fd, "# ", 2); |
|
1021 |
write(fd,buffer, strlen(buffer)); |
|
1022 |
free(buffer); |
|
1023 |
p = p->next; |
|
1024 |
} |
|
1025 |
||
1026 |
write(fd, "\n", 1); |
|
1027 |
||
1028 |
/* Show Queued or Running jobs */ |
|
1029 |
p = firstjob; |
|
1030 |
while(p != 0) |
|
1031 |
{ |
|
1032 |
buffer = joblistdump_torun(p); |
|
1033 |
write(fd,buffer,strlen(buffer)); |
|
1034 |
free(buffer); |
|
1035 |
p = p->next; |
|
1036 |
} |
|
1037 |
} |