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