author | viric@llimona |
Fri, 13 Apr 2007 20:52:28 +0200 | |
changeset 127 | c620eacd7630 |
parent 120 | 790bc4cecd3b |
child 134 | 5a6b8bb1f7a8 |
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> |
32 | 11 |
#include "main.h" |
3 | 12 |
|
8 | 13 |
static enum |
14 |
{ |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
15 |
FREE, /* No task is running */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
16 |
WAITING /* A task is running, and the server is waiting */ |
8 | 17 |
} state = FREE; |
18 |
||
42 | 19 |
struct Notify |
20 |
{ |
|
21 |
int socket; |
|
22 |
int jobid; |
|
23 |
struct Notify *next; |
|
24 |
}; |
|
25 |
||
3 | 26 |
/* Globals */ |
27 |
static struct Job *firstjob = 0; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
28 |
static struct Job *first_finished_job = 0; |
44 | 29 |
static int jobids = 0; |
3 | 30 |
|
42 | 31 |
static struct Notify *first_notify = 0; |
32 |
||
5 | 33 |
static void send_list_line(int s, const char * str) |
34 |
{ |
|
35 |
struct msg m; |
|
36 |
||
21 | 37 |
/* Message */ |
5 | 38 |
m.type = LIST_LINE; |
21 | 39 |
m.u.line_size = strlen(str) + 1; |
5 | 40 |
|
21 | 41 |
send_msg(s, &m); |
42 |
||
43 |
/* Send the line */ |
|
44 |
send_bytes(s, str, m.u.line_size); |
|
5 | 45 |
} |
46 |
||
53 | 47 |
static void send_urgent_ok(int s) |
48 |
{ |
|
49 |
struct msg m; |
|
50 |
||
51 |
/* Message */ |
|
52 |
m.type = URGENT_OK; |
|
53 |
||
54 |
send_msg(s, &m); |
|
55 |
} |
|
56 |
||
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
57 |
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
|
58 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
59 |
struct msg m; |
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 |
/* Message */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
62 |
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
|
63 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
64 |
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
|
65 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
66 |
|
120 | 67 |
static struct Job * find_previous_job(const struct Job *final) |
53 | 68 |
{ |
69 |
struct Job *p; |
|
70 |
||
71 |
/* Show Queued or Running jobs */ |
|
72 |
p = firstjob; |
|
73 |
while(p != 0) |
|
74 |
{ |
|
75 |
if (p->next == final) |
|
76 |
return p; |
|
77 |
p = p->next; |
|
78 |
} |
|
79 |
||
80 |
return 0; |
|
81 |
} |
|
82 |
||
22 | 83 |
static struct Job * findjob(int jobid) |
84 |
{ |
|
85 |
struct Job *p; |
|
86 |
||
87 |
/* Show Queued or Running jobs */ |
|
88 |
p = firstjob; |
|
89 |
while(p != 0) |
|
90 |
{ |
|
91 |
if (p->jobid == jobid) |
|
92 |
return p; |
|
93 |
p = p->next; |
|
94 |
} |
|
95 |
||
96 |
return 0; |
|
97 |
} |
|
98 |
||
32 | 99 |
static struct Job * find_finished_job(int jobid) |
100 |
{ |
|
101 |
struct Job *p; |
|
102 |
||
103 |
/* Show Queued or Running jobs */ |
|
104 |
p = first_finished_job; |
|
105 |
while(p != 0) |
|
106 |
{ |
|
107 |
if (p->jobid == jobid) |
|
108 |
return p; |
|
109 |
p = p->next; |
|
110 |
} |
|
111 |
||
112 |
return 0; |
|
113 |
} |
|
114 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
115 |
void s_mark_job_running() |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
116 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
117 |
firstjob->state = 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 |
|
63 | 120 |
const char * jstate2string(enum Jobstate s) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
121 |
{ |
120 | 122 |
const char * jobstate; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
123 |
switch(s) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
124 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
125 |
case QUEUED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
126 |
jobstate = "queued"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
127 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
128 |
case RUNNING: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
129 |
jobstate = "running"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
130 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
131 |
case FINISHED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
132 |
jobstate = "finished"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
133 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
134 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
135 |
return jobstate; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
136 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
137 |
|
3 | 138 |
void s_list(int s) |
139 |
{ |
|
140 |
struct Job *p; |
|
117 | 141 |
char *buffer; |
3 | 142 |
|
114 | 143 |
/* Times: 0.00/0.00/0.00 - 4+4+4+2 = 14*/ |
117 | 144 |
buffer = joblist_headers(); |
5 | 145 |
send_list_line(s,buffer); |
117 | 146 |
free(buffer); |
3 | 147 |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
148 |
/* Show Queued or Running jobs */ |
3 | 149 |
p = firstjob; |
150 |
while(p != 0) |
|
151 |
{ |
|
117 | 152 |
buffer = joblist_line(p); |
5 | 153 |
send_list_line(s,buffer); |
117 | 154 |
free(buffer); |
3 | 155 |
p = p->next; |
156 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
157 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
158 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
159 |
|
120 | 160 |
/* Show Finished jobs */ |
161 |
while(p != 0) |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
162 |
{ |
120 | 163 |
buffer = joblist_line(p); |
164 |
send_list_line(s,buffer); |
|
165 |
free(buffer); |
|
166 |
p = p->next; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
167 |
} |
3 | 168 |
} |
169 |
||
170 |
static struct Job * newjobptr() |
|
171 |
{ |
|
172 |
struct Job *p; |
|
173 |
||
174 |
if (firstjob == 0) |
|
175 |
{ |
|
176 |
firstjob = (struct Job *) malloc(sizeof(*firstjob)); |
|
177 |
firstjob->next = 0; |
|
64 | 178 |
firstjob->output_filename = 0; |
179 |
firstjob->command = 0; |
|
3 | 180 |
return firstjob; |
181 |
} |
|
182 |
||
183 |
p = firstjob; |
|
184 |
while(p->next != 0) |
|
185 |
p = p->next; |
|
186 |
||
187 |
p->next = (struct Job *) malloc(sizeof(*p)); |
|
188 |
p->next->next = 0; |
|
64 | 189 |
p->next->output_filename = 0; |
190 |
p->next->command = 0; |
|
3 | 191 |
|
192 |
return p->next; |
|
193 |
} |
|
194 |
||
195 |
/* Returns job id */ |
|
18 | 196 |
int s_newjob(int s, struct msg *m) |
3 | 197 |
{ |
198 |
struct Job *p; |
|
18 | 199 |
int res; |
3 | 200 |
|
201 |
p = newjobptr(); |
|
202 |
||
203 |
p->jobid = jobids++; |
|
204 |
p->state = QUEUED; |
|
27
886bdb2f4632
Fixed the Output File information in the list.
viric@llimona
parents:
26
diff
changeset
|
205 |
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
|
206 |
p->should_keep_finished = m->u.newjob.should_keep_finished; |
18 | 207 |
|
208 |
/* load the command */ |
|
209 |
p->command = malloc(m->u.newjob.command_size); |
|
210 |
/* !!! Check retval */ |
|
211 |
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
|
212 |
if (res == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
213 |
error("wrong bytes received"); |
3 | 214 |
|
215 |
return p->jobid; |
|
216 |
} |
|
217 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
218 |
/* This assumes the jobid exists */ |
3 | 219 |
void s_removejob(int jobid) |
220 |
{ |
|
221 |
struct Job *p; |
|
222 |
struct Job *newnext; |
|
223 |
||
224 |
if (firstjob->jobid == jobid) |
|
225 |
{ |
|
226 |
struct Job *newfirst; |
|
227 |
/* First job is to be removed */ |
|
228 |
newfirst = firstjob->next; |
|
18 | 229 |
free(firstjob->command); |
64 | 230 |
free(firstjob->output_filename); |
3 | 231 |
free(firstjob); |
232 |
firstjob = newfirst; |
|
233 |
return; |
|
234 |
} |
|
235 |
||
236 |
p = firstjob; |
|
237 |
/* Not first job */ |
|
238 |
while (p->next != 0) |
|
239 |
{ |
|
240 |
if (p->next->jobid == jobid) |
|
241 |
break; |
|
242 |
p = p->next; |
|
243 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
244 |
if (p->next == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
245 |
error("Job to be removed not found"); |
3 | 246 |
|
247 |
newnext = p->next->next; |
|
248 |
||
18 | 249 |
free(p->next->command); |
3 | 250 |
free(p->next); |
251 |
p->next = newnext; |
|
252 |
} |
|
8 | 253 |
|
254 |
/* -1 if no one should be run. */ |
|
255 |
int next_run_job() |
|
256 |
{ |
|
257 |
if (state == WAITING) |
|
258 |
return -1; |
|
259 |
||
260 |
if (firstjob != 0) |
|
9 | 261 |
{ |
262 |
state = WAITING; |
|
8 | 263 |
return firstjob->jobid; |
9 | 264 |
} |
8 | 265 |
|
266 |
return -1; |
|
267 |
} |
|
268 |
||
64 | 269 |
/* Returns 1000 if no limit, The limit otherwise. */ |
270 |
static int get_max_finished_jobs() |
|
271 |
{ |
|
272 |
char *limit; |
|
273 |
||
274 |
limit = getenv("TS_MAXFINISHED"); |
|
275 |
if (limit == NULL) |
|
276 |
return 1000; |
|
277 |
return abs(atoi(limit)); |
|
278 |
} |
|
279 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
280 |
/* Add the job to the finished queue. */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
281 |
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
|
282 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
283 |
struct Job *p; |
64 | 284 |
int count, max; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
285 |
|
64 | 286 |
max = get_max_finished_jobs(); |
287 |
count = 0; |
|
288 |
||
289 |
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
|
290 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
291 |
first_finished_job = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
292 |
first_finished_job->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
293 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
294 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
295 |
|
64 | 296 |
++count; |
297 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
298 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
299 |
while(p->next != 0) |
64 | 300 |
{ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
301 |
p = p->next; |
64 | 302 |
++count; |
303 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
304 |
|
64 | 305 |
/* If too many jobs, wipe out the first */ |
306 |
if (count >= max) |
|
307 |
{ |
|
308 |
struct Job *tmp; |
|
309 |
tmp = first_finished_job; |
|
310 |
first_finished_job = first_finished_job->next; |
|
311 |
free(tmp->command); |
|
312 |
free(tmp->output_filename); |
|
313 |
free(tmp); |
|
314 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
315 |
p->next = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
316 |
p->next->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
317 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
318 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
319 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
320 |
|
114 | 321 |
void job_finished(const struct Result *result) |
8 | 322 |
{ |
323 |
struct Job *newfirst; |
|
324 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
325 |
if (state != WAITING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
326 |
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
|
327 |
if (firstjob == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
328 |
error("on job finished, firstjob values %x", firstjob); |
8 | 329 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
330 |
if (firstjob->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
331 |
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
|
332 |
firstjob->state); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
333 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
334 |
/* Mark state */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
335 |
firstjob->state = FINISHED; |
114 | 336 |
firstjob->result = *result; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
337 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
338 |
/* Add it to the finished queue */ |
26 | 339 |
newfirst = firstjob->next; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
54
diff
changeset
|
340 |
if (firstjob->should_keep_finished) |
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
54
diff
changeset
|
341 |
new_finished_job(firstjob); |
19
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 |
/* Remove it from the run queue */ |
26 | 344 |
firstjob = newfirst; |
8 | 345 |
|
346 |
state = FREE; |
|
347 |
} |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
348 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
349 |
void s_clear_finished() |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
350 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
351 |
struct Job *p; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
352 |
|
22 | 353 |
if (first_finished_job == 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
354 |
return; |
22 | 355 |
|
356 |
p = first_finished_job; |
|
357 |
first_finished_job = 0; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
358 |
|
64 | 359 |
while (p != 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
360 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
361 |
struct Job *tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
362 |
tmp = p->next; |
22 | 363 |
free(p->command); |
364 |
free(p->output_filename); |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
365 |
free(p); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
366 |
p = tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
367 |
} |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
368 |
} |
22 | 369 |
|
35 | 370 |
void s_process_runjob_ok(int jobid, char *oname, int pid) |
22 | 371 |
{ |
372 |
struct Job *p; |
|
373 |
p = findjob(jobid); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
374 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
375 |
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
|
376 |
if (p->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
377 |
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
|
378 |
p->state); |
22 | 379 |
|
35 | 380 |
p->pid = pid; |
22 | 381 |
p->output_filename = oname; |
382 |
} |
|
32 | 383 |
|
384 |
void s_send_output(int s, int jobid) |
|
385 |
{ |
|
386 |
struct Job *p = 0; |
|
387 |
struct msg m; |
|
388 |
||
389 |
if (jobid == -1) |
|
390 |
{ |
|
391 |
/* This means that we want the tail of the running task, or that |
|
392 |
* of the last job run */ |
|
393 |
if (state == WAITING) |
|
394 |
{ |
|
395 |
p = firstjob; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
396 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
397 |
error("Internal state WAITING, but job not run." |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
398 |
"firstjob = %x", firstjob); |
32 | 399 |
} |
400 |
else |
|
401 |
{ |
|
402 |
p = first_finished_job; |
|
403 |
if (p == 0) |
|
404 |
{ |
|
405 |
send_list_line(s, "No jobs.\n"); |
|
406 |
return; |
|
407 |
} |
|
408 |
while(p->next != 0) |
|
409 |
p = p->next; |
|
410 |
} |
|
411 |
} else |
|
412 |
{ |
|
413 |
if (state == WAITING && firstjob->jobid == jobid) |
|
414 |
p = firstjob; |
|
415 |
else |
|
416 |
p = find_finished_job(jobid); |
|
417 |
} |
|
418 |
||
419 |
if (p == 0) |
|
420 |
{ |
|
421 |
char tmp[50]; |
|
422 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
|
423 |
send_list_line(s, tmp); |
|
424 |
return; |
|
425 |
} |
|
426 |
||
427 |
m.type = ANSWER_OUTPUT; |
|
428 |
if (!p->store_output) |
|
429 |
{ |
|
430 |
send_list_line(s, "The job hasn't output stored.\n"); |
|
431 |
return; |
|
432 |
} |
|
433 |
m.u.output.store_output = p->store_output; |
|
35 | 434 |
m.u.output.pid = p->pid; |
32 | 435 |
m.u.output.ofilename_size = strlen(p->output_filename) + 1; |
436 |
send_msg(s, &m); |
|
437 |
send_bytes(s, p->output_filename, m.u.output.ofilename_size); |
|
438 |
} |
|
41 | 439 |
|
440 |
void s_remove_job(int s, int jobid) |
|
441 |
{ |
|
442 |
struct Job *p = 0; |
|
443 |
struct msg m; |
|
444 |
struct Job *before_p = 0; |
|
445 |
||
446 |
if (jobid == -1) |
|
447 |
{ |
|
448 |
/* Find the last job added */ |
|
449 |
p = firstjob; |
|
450 |
if (p != 0) |
|
451 |
{ |
|
452 |
while (p->next != 0) |
|
453 |
{ |
|
454 |
before_p = p; |
|
455 |
p = p->next; |
|
456 |
} |
|
457 |
} |
|
458 |
} |
|
459 |
else |
|
460 |
{ |
|
461 |
p = firstjob; |
|
462 |
if (p != 0) |
|
463 |
{ |
|
464 |
while (p->next != 0 && p->jobid != jobid) |
|
465 |
{ |
|
466 |
before_p = p; |
|
467 |
p = p->next; |
|
468 |
} |
|
469 |
} |
|
470 |
} |
|
471 |
||
472 |
if (p == 0 || p->state != QUEUED || before_p == 0) |
|
473 |
{ |
|
474 |
char tmp[50]; |
|
475 |
if (jobid == -1) |
|
44 | 476 |
sprintf(tmp, "The last job cannot be removed.\n"); |
41 | 477 |
else |
478 |
sprintf(tmp, "The job %i cannot be removed.\n", jobid); |
|
479 |
send_list_line(s, tmp); |
|
480 |
return; |
|
481 |
} |
|
482 |
||
483 |
before_p->next = p->next; |
|
64 | 484 |
free(p->command); |
485 |
free(p->output_filename); |
|
41 | 486 |
free(p); |
487 |
m.type = REMOVEJOB_OK; |
|
488 |
send_msg(s, &m); |
|
489 |
} |
|
42 | 490 |
|
491 |
static void add_to_notify_list(int s, int jobid) |
|
492 |
{ |
|
493 |
struct Notify *n; |
|
494 |
struct Notify *new; |
|
495 |
||
496 |
new = (struct Notify *) malloc(sizeof(*n)); |
|
497 |
||
498 |
new->socket = s; |
|
499 |
new->jobid = jobid; |
|
500 |
new->next = 0; |
|
501 |
||
502 |
n = first_notify; |
|
503 |
if (n == 0) |
|
504 |
{ |
|
505 |
first_notify = new; |
|
506 |
return; |
|
507 |
} |
|
508 |
||
509 |
while(n->next != 0) |
|
510 |
n = n->next; |
|
511 |
||
512 |
n->next = new; |
|
513 |
} |
|
514 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
515 |
static void send_waitjob_ok(int s, int errorlevel) |
42 | 516 |
{ |
517 |
struct msg m; |
|
518 |
||
519 |
m.type = WAITJOB_OK; |
|
112 | 520 |
m.u.result.errorlevel = errorlevel; |
42 | 521 |
send_msg(s, &m); |
522 |
} |
|
523 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
524 |
static struct Job * |
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
525 |
get_job(int jobid) |
42 | 526 |
{ |
527 |
struct Job *j; |
|
528 |
||
529 |
j = findjob(jobid); |
|
530 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
531 |
return j; |
42 | 532 |
|
533 |
j = find_finished_job(jobid); |
|
534 |
||
535 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
536 |
return j; |
42 | 537 |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
538 |
return 0; |
42 | 539 |
} |
540 |
||
541 |
/* Don't complain, if the socket doesn't exist */ |
|
542 |
void s_remove_notification(int s) |
|
543 |
{ |
|
544 |
struct Notify *n; |
|
545 |
struct Notify *previous; |
|
546 |
n = first_notify; |
|
547 |
while (n != 0 && n->socket != s) |
|
548 |
n = n->next; |
|
549 |
if (n == 0) |
|
550 |
return; |
|
551 |
||
552 |
/* Remove the notification */ |
|
553 |
previous = first_notify; |
|
554 |
if (n == previous) |
|
555 |
{ |
|
556 |
free(first_notify); |
|
557 |
first_notify = 0; |
|
558 |
return; |
|
559 |
} |
|
560 |
||
561 |
/* if not the first... */ |
|
562 |
while(previous->next != n) |
|
563 |
previous = previous->next; |
|
564 |
||
565 |
previous->next = n->next; |
|
566 |
free(n); |
|
567 |
} |
|
568 |
||
569 |
/* This is called when a job finishes */ |
|
570 |
void check_notify_list(int jobid) |
|
571 |
{ |
|
572 |
struct Notify *n; |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
573 |
struct Job *j; |
42 | 574 |
|
575 |
n = first_notify; |
|
576 |
while (n != 0 && n->jobid != jobid) |
|
577 |
{ |
|
578 |
n = n->next; |
|
579 |
} |
|
580 |
||
581 |
if (n == 0) |
|
582 |
{ |
|
583 |
return; |
|
584 |
} |
|
585 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
586 |
j = get_job(jobid); |
42 | 587 |
/* If the job finishes, notify the waiter */ |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
588 |
if (j->state == FINISHED) |
42 | 589 |
{ |
112 | 590 |
send_waitjob_ok(n->socket, j->result.errorlevel); |
42 | 591 |
s_remove_notification(n->socket); |
592 |
} |
|
593 |
} |
|
594 |
||
595 |
void s_wait_job(int s, int jobid) |
|
596 |
{ |
|
597 |
struct Job *p = 0; |
|
598 |
||
599 |
if (jobid == -1) |
|
600 |
{ |
|
601 |
/* Find the last job added */ |
|
602 |
p = firstjob; |
|
603 |
||
604 |
if (p != 0) |
|
605 |
while (p->next != 0) |
|
606 |
p = p->next; |
|
607 |
||
608 |
/* Look in finished jobs if needed */ |
|
609 |
if (p == 0) |
|
610 |
{ |
|
611 |
p = first_finished_job; |
|
612 |
if (p != 0) |
|
613 |
while (p->next != 0) |
|
614 |
p = p->next; |
|
615 |
} |
|
616 |
} |
|
617 |
else |
|
618 |
{ |
|
619 |
p = firstjob; |
|
620 |
while (p != 0 && p->jobid != jobid) |
|
621 |
p = p->next; |
|
622 |
||
623 |
/* Look in finished jobs if needed */ |
|
624 |
if (p == 0) |
|
625 |
{ |
|
626 |
p = first_finished_job; |
|
627 |
while (p != 0 && p->jobid != jobid) |
|
628 |
p = p->next; |
|
629 |
} |
|
630 |
} |
|
631 |
||
632 |
if (p == 0) |
|
633 |
{ |
|
634 |
char tmp[50]; |
|
635 |
if (jobid == -1) |
|
44 | 636 |
sprintf(tmp, "The last job cannot be waited.\n"); |
42 | 637 |
else |
638 |
sprintf(tmp, "The job %i cannot be waited.\n", jobid); |
|
639 |
send_list_line(s, tmp); |
|
640 |
return; |
|
641 |
} |
|
642 |
||
643 |
if (p->state == FINISHED) |
|
644 |
{ |
|
112 | 645 |
send_waitjob_ok(s, p->result.errorlevel); |
42 | 646 |
} |
647 |
else |
|
648 |
add_to_notify_list(s, p->jobid); |
|
649 |
} |
|
53 | 650 |
|
651 |
void s_move_urgent(int s, int jobid) |
|
652 |
{ |
|
653 |
struct Job *p = 0; |
|
654 |
struct Job *tmp1; |
|
655 |
||
656 |
if (jobid == -1) |
|
657 |
{ |
|
658 |
/* Find the last job added */ |
|
659 |
p = firstjob; |
|
660 |
||
661 |
if (p != 0) |
|
662 |
while (p->next != 0) |
|
663 |
p = p->next; |
|
664 |
} |
|
665 |
else |
|
666 |
{ |
|
667 |
p = firstjob; |
|
668 |
while (p != 0 && p->jobid != jobid) |
|
669 |
p = p->next; |
|
670 |
} |
|
671 |
||
672 |
if (p == 0 || firstjob->next == 0) |
|
673 |
{ |
|
674 |
char tmp[50]; |
|
675 |
if (jobid == -1) |
|
676 |
sprintf(tmp, "The last job cannot be urged.\n"); |
|
677 |
else |
|
678 |
sprintf(tmp, "The job %i cannot be urged.\n", jobid); |
|
679 |
send_list_line(s, tmp); |
|
680 |
return; |
|
681 |
} |
|
682 |
||
683 |
/* Interchange the pointers */ |
|
684 |
tmp1 = find_previous_job(p); |
|
685 |
tmp1->next = p->next; |
|
686 |
p->next = firstjob->next; |
|
687 |
firstjob->next = p; |
|
688 |
||
689 |
||
690 |
send_urgent_ok(s); |
|
691 |
} |
|
63 | 692 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
693 |
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
|
694 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
695 |
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
|
696 |
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
|
697 |
struct Job *tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
698 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
699 |
p1 = findjob(jobid1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
700 |
p2 = findjob(jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
701 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
702 |
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
|
703 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
704 |
char prev[60]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
705 |
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
|
706 |
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
|
707 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
708 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
709 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
710 |
/* Interchange the pointers */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
711 |
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
|
712 |
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
|
713 |
prev1->next = p2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
714 |
prev2->next = p1; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
715 |
tmp = p1->next; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
716 |
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
|
717 |
p2->next = tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
718 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
719 |
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
|
720 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
721 |
|
63 | 722 |
static void send_state(int s, enum Jobstate state) |
723 |
{ |
|
724 |
struct msg m; |
|
725 |
||
726 |
m.type = ANSWER_STATE; |
|
727 |
m.u.state = state; |
|
728 |
||
729 |
send_msg(s, &m); |
|
730 |
} |
|
731 |
||
732 |
void s_send_state(int s, int jobid) |
|
733 |
{ |
|
734 |
struct Job *p = 0; |
|
735 |
||
736 |
if (jobid == -1) |
|
737 |
{ |
|
738 |
/* Find the last job added */ |
|
739 |
p = firstjob; |
|
740 |
||
741 |
if (p != 0) |
|
742 |
while (p->next != 0) |
|
743 |
p = p->next; |
|
744 |
||
745 |
/* Look in finished jobs if needed */ |
|
746 |
if (p == 0) |
|
747 |
{ |
|
748 |
p = first_finished_job; |
|
749 |
if (p != 0) |
|
750 |
while (p->next != 0) |
|
751 |
p = p->next; |
|
752 |
} |
|
753 |
||
754 |
} |
|
755 |
else |
|
756 |
{ |
|
757 |
p = get_job(jobid); |
|
758 |
} |
|
759 |
||
760 |
if (p == 0) |
|
761 |
{ |
|
762 |
char tmp[50]; |
|
763 |
if (jobid == -1) |
|
764 |
sprintf(tmp, "The last job cannot be stated.\n"); |
|
765 |
else |
|
766 |
sprintf(tmp, "The job %i cannot be stated.\n", jobid); |
|
767 |
send_list_line(s, tmp); |
|
768 |
return; |
|
769 |
} |
|
770 |
||
771 |
/* Interchange the pointers */ |
|
772 |
send_state(s, p->state); |
|
773 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
774 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
775 |
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
|
776 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
777 |
fprintf(out, " new_job\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
778 |
fprintf(out, " jobid %i\n", p->jobid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
779 |
fprintf(out, " command \"%s\"\n", p->command); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
780 |
fprintf(out, " state %s\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
781 |
jstate2string(p->state)); |
112 | 782 |
fprintf(out, " result.errorlevel %i\n", p->result.errorlevel); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
783 |
fprintf(out, " output_filename \"%s\"\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
784 |
p->output_filename ? p->output_filename : "NULL"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
785 |
fprintf(out, " store_output %i\n", p->store_output); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
786 |
fprintf(out, " pid %i\n", p->pid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
787 |
fprintf(out, " should_keep_finished %i\n", p->pid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
788 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
789 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
790 |
void dump_jobs_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
791 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
792 |
const struct Job *p; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
793 |
|
104 | 794 |
fprintf(out, "New_jobs\n"); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
795 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
796 |
p = firstjob; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
797 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
798 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
799 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
800 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
801 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
802 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
803 |
p = first_finished_job; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
804 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
805 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
806 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
807 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
808 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
809 |
} |
120 | 810 |
|
811 |
void joblist_dump(int fd) |
|
812 |
{ |
|
813 |
struct Job *p; |
|
814 |
char *buffer; |
|
815 |
||
816 |
buffer = joblistdump_headers(); |
|
817 |
write(fd,buffer, strlen(buffer)); |
|
818 |
free(buffer); |
|
819 |
||
820 |
/* We reuse the headers from the list */ |
|
821 |
buffer = joblist_headers(); |
|
822 |
write(fd, "# ", 2); |
|
823 |
write(fd, buffer, strlen(buffer)); |
|
824 |
||
825 |
/* Show Finished jobs */ |
|
826 |
p = first_finished_job; |
|
827 |
while(p != 0) |
|
828 |
{ |
|
829 |
buffer = joblist_line(p); |
|
830 |
write(fd, "# ", 2); |
|
831 |
write(fd,buffer, strlen(buffer)); |
|
832 |
free(buffer); |
|
833 |
p = p->next; |
|
834 |
} |
|
835 |
||
836 |
write(fd, "\n", 1); |
|
837 |
||
838 |
/* Show Queued or Running jobs */ |
|
839 |
p = firstjob; |
|
840 |
while(p != 0) |
|
841 |
{ |
|
842 |
buffer = joblistdump_torun(p); |
|
843 |
write(fd,buffer,strlen(buffer)); |
|
844 |
free(buffer); |
|
845 |
p = p->next; |
|
846 |
} |
|
847 |
} |