author | viric <viriketo@gmail.com> |
Mon, 18 Jul 2011 22:45:13 +0200 | |
branch | queuelimit2 |
changeset 292 | 72419de39d72 |
parent 289 | f331d05328b3 |
child 315 | 2b3ed8fdfb12 |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
267 | 3 |
Copyright (C) 2007-2009 LluĂs Batlle i Rossell |
49 | 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 |
|
219 | 15 |
/* The list will access them */ |
16 |
int busy_slots = 0; |
|
17 |
int max_slots = 1; |
|
8 | 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; |
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
30 |
/* This is used for dependencies from jobs |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
31 |
* already out of the queue */ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
32 |
static int last_errorlevel = 0; /* Before the first job, let's consider |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
33 |
a good previous result */ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
34 |
/* We need this to handle well "-d" after a "-nf" run */ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
35 |
static int last_finished_jobid; |
3 | 36 |
|
42 | 37 |
static struct Notify *first_notify = 0; |
38 |
||
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
39 |
int max_jobs; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
40 |
|
218 | 41 |
static struct Job * get_job(int jobid); |
42 |
void notify_errorlevel(struct Job *p); |
|
43 |
||
5 | 44 |
static void send_list_line(int s, const char * str) |
45 |
{ |
|
46 |
struct msg m; |
|
47 |
||
21 | 48 |
/* Message */ |
5 | 49 |
m.type = LIST_LINE; |
146 | 50 |
m.u.size = strlen(str) + 1; |
5 | 51 |
|
21 | 52 |
send_msg(s, &m); |
53 |
||
54 |
/* Send the line */ |
|
146 | 55 |
send_bytes(s, str, m.u.size); |
5 | 56 |
} |
57 |
||
53 | 58 |
static void send_urgent_ok(int s) |
59 |
{ |
|
60 |
struct msg m; |
|
61 |
||
62 |
/* Message */ |
|
63 |
m.type = URGENT_OK; |
|
64 |
||
65 |
send_msg(s, &m); |
|
66 |
} |
|
67 |
||
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
68 |
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
|
69 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
70 |
struct msg m; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
71 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
72 |
/* Message */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
73 |
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
|
74 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
75 |
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
|
76 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
77 |
|
120 | 78 |
static struct Job * find_previous_job(const struct Job *final) |
53 | 79 |
{ |
80 |
struct Job *p; |
|
81 |
||
82 |
/* Show Queued or Running jobs */ |
|
83 |
p = firstjob; |
|
84 |
while(p != 0) |
|
85 |
{ |
|
86 |
if (p->next == final) |
|
87 |
return p; |
|
88 |
p = p->next; |
|
89 |
} |
|
90 |
||
91 |
return 0; |
|
92 |
} |
|
93 |
||
22 | 94 |
static struct Job * findjob(int jobid) |
95 |
{ |
|
96 |
struct Job *p; |
|
97 |
||
98 |
/* Show Queued or Running jobs */ |
|
99 |
p = firstjob; |
|
100 |
while(p != 0) |
|
101 |
{ |
|
102 |
if (p->jobid == jobid) |
|
103 |
return p; |
|
104 |
p = p->next; |
|
105 |
} |
|
106 |
||
107 |
return 0; |
|
108 |
} |
|
109 |
||
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
110 |
static struct Job * findjob_holding_client() |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
111 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
112 |
struct Job *p; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
113 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
114 |
/* Show Queued or Running jobs */ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
115 |
p = firstjob; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
116 |
while(p != 0) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
117 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
118 |
if (p->state == HOLDING_CLIENT) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
119 |
return p; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
120 |
p = p->next; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
121 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
122 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
123 |
return 0; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
124 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
125 |
|
32 | 126 |
static struct Job * find_finished_job(int jobid) |
127 |
{ |
|
128 |
struct Job *p; |
|
129 |
||
130 |
/* Show Queued or Running jobs */ |
|
131 |
p = first_finished_job; |
|
132 |
while(p != 0) |
|
133 |
{ |
|
134 |
if (p->jobid == jobid) |
|
135 |
return p; |
|
136 |
p = p->next; |
|
137 |
} |
|
138 |
||
139 |
return 0; |
|
140 |
} |
|
141 |
||
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
142 |
static int count_not_finished_jobs() |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
143 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
144 |
int count=0; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
145 |
struct Job *p; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
146 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
147 |
/* Show Queued or Running jobs */ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
148 |
p = firstjob; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
149 |
while(p != 0) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
150 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
151 |
++count; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
152 |
p = p->next; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
153 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
154 |
return count; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
155 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
156 |
|
259 | 157 |
static void add_notify_errorlevel_to(struct Job *job, int jobid) |
158 |
{ |
|
159 |
int *p; |
|
160 |
int newsize = (job->notify_errorlevel_to_size + 1) |
|
161 |
* sizeof(int); |
|
162 |
p = (int *) realloc(job->notify_errorlevel_to, |
|
163 |
newsize); |
|
164 |
||
165 |
if (p == 0) |
|
166 |
error("Cannot allocate more memory for notify_errorlist_to for jobid %i," |
|
167 |
" having already %i elements", |
|
168 |
job->jobid, job->notify_errorlevel_to_size); |
|
169 |
||
170 |
job->notify_errorlevel_to = p; |
|
171 |
job->notify_errorlevel_to_size += 1; |
|
172 |
job->notify_errorlevel_to[job->notify_errorlevel_to_size - 1] = jobid; |
|
173 |
} |
|
174 |
||
218 | 175 |
void s_mark_job_running(int jobid) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
176 |
{ |
218 | 177 |
struct Job *p; |
178 |
p = findjob(jobid); |
|
179 |
if (!p) |
|
180 |
error("Cannot mark the jobid %i RUNNING.", jobid); |
|
181 |
p->state = RUNNING; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
182 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
183 |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
184 |
/* -1 means nothing awaken, otherwise returns the jobid awaken */ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
185 |
int wake_hold_client() |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
186 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
187 |
struct Job *p; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
188 |
p = findjob_holding_client(); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
189 |
if (p) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
190 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
191 |
p->state = QUEUED; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
192 |
return p->jobid; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
193 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
194 |
return -1; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
195 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
196 |
|
63 | 197 |
const char * jstate2string(enum Jobstate s) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
198 |
{ |
120 | 199 |
const char * jobstate; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
200 |
switch(s) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
201 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
202 |
case QUEUED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
203 |
jobstate = "queued"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
204 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
205 |
case RUNNING: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
206 |
jobstate = "running"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
207 |
break; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
208 |
case FINISHED: |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
209 |
jobstate = "finished"; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
210 |
break; |
156 | 211 |
case SKIPPED: |
212 |
jobstate = "skipped"; |
|
213 |
break; |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
214 |
case HOLDING_CLIENT: |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
215 |
jobstate = "skipped"; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
216 |
break; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
217 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
218 |
return jobstate; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
219 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
220 |
|
3 | 221 |
void s_list(int s) |
222 |
{ |
|
223 |
struct Job *p; |
|
117 | 224 |
char *buffer; |
3 | 225 |
|
114 | 226 |
/* Times: 0.00/0.00/0.00 - 4+4+4+2 = 14*/ |
117 | 227 |
buffer = joblist_headers(); |
5 | 228 |
send_list_line(s,buffer); |
117 | 229 |
free(buffer); |
3 | 230 |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
231 |
/* Show Queued or Running jobs */ |
3 | 232 |
p = firstjob; |
233 |
while(p != 0) |
|
234 |
{ |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
235 |
if (p->state != HOLDING_CLIENT) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
236 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
237 |
buffer = joblist_line(p); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
238 |
send_list_line(s,buffer); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
239 |
free(buffer); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
240 |
} |
3 | 241 |
p = p->next; |
242 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
243 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
244 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
245 |
|
120 | 246 |
/* Show Finished jobs */ |
247 |
while(p != 0) |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
248 |
{ |
120 | 249 |
buffer = joblist_line(p); |
250 |
send_list_line(s,buffer); |
|
251 |
free(buffer); |
|
252 |
p = p->next; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
253 |
} |
3 | 254 |
} |
255 |
||
256 |
static struct Job * newjobptr() |
|
257 |
{ |
|
258 |
struct Job *p; |
|
259 |
||
260 |
if (firstjob == 0) |
|
261 |
{ |
|
262 |
firstjob = (struct Job *) malloc(sizeof(*firstjob)); |
|
263 |
firstjob->next = 0; |
|
64 | 264 |
firstjob->output_filename = 0; |
265 |
firstjob->command = 0; |
|
3 | 266 |
return firstjob; |
267 |
} |
|
268 |
||
269 |
p = firstjob; |
|
270 |
while(p->next != 0) |
|
271 |
p = p->next; |
|
272 |
||
273 |
p->next = (struct Job *) malloc(sizeof(*p)); |
|
274 |
p->next->next = 0; |
|
64 | 275 |
p->next->output_filename = 0; |
276 |
p->next->command = 0; |
|
3 | 277 |
|
278 |
return p->next; |
|
279 |
} |
|
280 |
||
218 | 281 |
/* Returns -1 if no last job id found */ |
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
282 |
static int find_last_jobid_in_queue(int neglect_jobid) |
218 | 283 |
{ |
284 |
struct Job *p; |
|
285 |
int last_jobid = -1; |
|
286 |
||
287 |
p = firstjob; |
|
288 |
while(p != 0) |
|
289 |
{ |
|
290 |
if (p->jobid != neglect_jobid && |
|
291 |
p->jobid > last_jobid) |
|
292 |
last_jobid = p->jobid; |
|
293 |
p = p->next; |
|
294 |
} |
|
295 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
296 |
return last_jobid; |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
297 |
} |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
298 |
|
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
299 |
/* Returns -1 if no last job id found */ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
300 |
static int find_last_stored_jobid_finished() |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
301 |
{ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
302 |
struct Job *p; |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
303 |
int last_jobid = -1; |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
304 |
|
218 | 305 |
p = first_finished_job; |
306 |
while(p != 0) |
|
307 |
{ |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
308 |
if (p->jobid > last_jobid) |
218 | 309 |
last_jobid = p->jobid; |
310 |
p = p->next; |
|
311 |
} |
|
312 |
||
313 |
return last_jobid; |
|
314 |
} |
|
315 |
||
259 | 316 |
/* Returns job id or -1 on error */ |
18 | 317 |
int s_newjob(int s, struct msg *m) |
3 | 318 |
{ |
319 |
struct Job *p; |
|
18 | 320 |
int res; |
3 | 321 |
|
322 |
p = newjobptr(); |
|
323 |
||
324 |
p->jobid = jobids++; |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
325 |
if (count_not_finished_jobs() < max_jobs) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
326 |
p->state = QUEUED; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
327 |
else |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
328 |
p->state = HOLDING_CLIENT; |
27
886bdb2f4632
Fixed the Output File information in the list.
viric@llimona
parents:
26
diff
changeset
|
329 |
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
|
330 |
p->should_keep_finished = m->u.newjob.should_keep_finished; |
259 | 331 |
p->notify_errorlevel_to = 0; |
332 |
p->notify_errorlevel_to_size = 0; |
|
333 |
p->do_depend = m->u.newjob.do_depend; |
|
334 |
p->depend_on = -1; /* By default. May be overriden in the next conditions */ |
|
335 |
if (m->u.newjob.do_depend == 1) |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
336 |
{ |
259 | 337 |
/* Depend on the last queued job. */ |
338 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
339 |
/* As we already have 'p' in the queue, |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
340 |
* neglect it during the find_last_jobid_in_queue() */ |
259 | 341 |
if (m->u.newjob.depend_on == -1) |
342 |
{ |
|
343 |
p->depend_on = find_last_jobid_in_queue(p->jobid); |
|
344 |
||
345 |
/* We don't trust the last jobid in the queue (running or queued) |
|
346 |
* if it's not the last added job. In that case, let |
|
347 |
* the next control flow handle it as if it could not |
|
348 |
* do_depend on any still queued job. */ |
|
349 |
if (last_finished_jobid > p->depend_on) |
|
350 |
p->depend_on = -1; |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
351 |
|
259 | 352 |
/* If it's queued still without result, let it know |
353 |
* its result to p when it finishes. */ |
|
354 |
if (p->depend_on != -1) |
|
355 |
{ |
|
356 |
struct Job *depended_job; |
|
357 |
depended_job = findjob(p->depend_on); |
|
358 |
if (depended_job != 0) |
|
359 |
add_notify_errorlevel_to(depended_job, p->jobid); |
|
360 |
else |
|
361 |
warning("The jobid %i is queued to do_depend on the jobid %i" |
|
362 |
" suddenly non existant in the queue", p->jobid, |
|
363 |
p->depend_on); |
|
364 |
} |
|
365 |
else /* Otherwise take the finished job, or the last_errorlevel */ |
|
366 |
{ |
|
367 |
if (m->u.newjob.depend_on == -1) |
|
368 |
{ |
|
369 |
int ljobid = find_last_stored_jobid_finished(); |
|
370 |
/* If we have a newer result stored, use it */ |
|
371 |
if (last_finished_jobid < ljobid) |
|
372 |
{ |
|
373 |
struct Job *parent; |
|
374 |
parent = find_finished_job(ljobid); |
|
375 |
if (!parent) |
|
376 |
error("jobid %i suddenly disappeared from the finished list", |
|
377 |
ljobid); |
|
378 |
p->dependency_errorlevel = parent->result.errorlevel; |
|
379 |
} |
|
380 |
else |
|
381 |
p->dependency_errorlevel = last_errorlevel; |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
else |
|
386 |
{ |
|
387 |
/* The user decided what's the job this new job depends on */ |
|
388 |
struct Job *depended_job; |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
389 |
|
259 | 390 |
p->depend_on = m->u.newjob.depend_on; |
391 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
392 |
depended_job = findjob(p->depend_on); |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
393 |
if (depended_job != 0) |
259 | 394 |
add_notify_errorlevel_to(depended_job, p->jobid); |
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
395 |
else |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
396 |
{ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
397 |
struct Job *parent; |
259 | 398 |
parent = find_finished_job(p->depend_on); |
399 |
if (parent) |
|
400 |
{ |
|
401 |
p->dependency_errorlevel = parent->result.errorlevel; |
|
402 |
} |
|
403 |
else |
|
404 |
{ |
|
405 |
/* We consider as if the job not found |
|
406 |
didn't finish well */ |
|
407 |
p->dependency_errorlevel = -1; |
|
408 |
} |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
409 |
} |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
410 |
} |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
411 |
} |
218 | 412 |
|
18 | 413 |
|
147 | 414 |
pinfo_init(&p->info); |
146 | 415 |
pinfo_set_enqueue_time(&p->info); |
416 |
||
18 | 417 |
/* load the command */ |
418 |
p->command = malloc(m->u.newjob.command_size); |
|
147 | 419 |
if (p->command == 0) |
420 |
error("Cannot allocate memory in s_newjob command_size (%i)", |
|
421 |
m->u.newjob.command_size); |
|
18 | 422 |
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
|
423 |
if (res == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
424 |
error("wrong bytes received"); |
3 | 425 |
|
150 | 426 |
/* load the label */ |
427 |
p->label = 0; |
|
428 |
if (m->u.newjob.label_size > 0) |
|
429 |
{ |
|
430 |
char *ptr; |
|
431 |
ptr = (char *) malloc(m->u.newjob.label_size); |
|
432 |
if (ptr == 0) |
|
433 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
434 |
m->u.newjob.env_size); |
|
435 |
res = recv_bytes(s, ptr, m->u.newjob.label_size); |
|
436 |
if (res == -1) |
|
437 |
error("wrong bytes received"); |
|
438 |
p->label = ptr; |
|
439 |
} |
|
440 |
||
147 | 441 |
/* load the info */ |
442 |
if (m->u.newjob.env_size > 0) |
|
443 |
{ |
|
444 |
char *ptr; |
|
445 |
ptr = (char *) malloc(m->u.newjob.env_size); |
|
446 |
if (ptr == 0) |
|
447 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
448 |
m->u.newjob.env_size); |
|
449 |
res = recv_bytes(s, ptr, m->u.newjob.env_size); |
|
450 |
if (res == -1) |
|
451 |
error("wrong bytes received"); |
|
452 |
pinfo_addinfo(&p->info, m->u.newjob.env_size+100, |
|
453 |
"Environment:\n%s", ptr); |
|
454 |
free(ptr); |
|
455 |
} |
|
456 |
||
3 | 457 |
return p->jobid; |
458 |
} |
|
459 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
460 |
/* This assumes the jobid exists */ |
3 | 461 |
void s_removejob(int jobid) |
462 |
{ |
|
463 |
struct Job *p; |
|
464 |
struct Job *newnext; |
|
465 |
||
466 |
if (firstjob->jobid == jobid) |
|
467 |
{ |
|
468 |
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
|
469 |
|
3 | 470 |
/* First job is to be removed */ |
471 |
newfirst = firstjob->next; |
|
18 | 472 |
free(firstjob->command); |
64 | 473 |
free(firstjob->output_filename); |
148 | 474 |
pinfo_free(&firstjob->info); |
150 | 475 |
free(firstjob->label); |
3 | 476 |
free(firstjob); |
477 |
firstjob = newfirst; |
|
478 |
return; |
|
479 |
} |
|
480 |
||
481 |
p = firstjob; |
|
482 |
/* Not first job */ |
|
483 |
while (p->next != 0) |
|
484 |
{ |
|
485 |
if (p->next->jobid == jobid) |
|
486 |
break; |
|
487 |
p = p->next; |
|
488 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
489 |
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
|
490 |
error("Job to be removed not found. jobid=%i", jobid); |
3 | 491 |
|
492 |
newnext = p->next->next; |
|
493 |
||
18 | 494 |
free(p->next->command); |
3 | 495 |
free(p->next); |
496 |
p->next = newnext; |
|
497 |
} |
|
8 | 498 |
|
499 |
/* -1 if no one should be run. */ |
|
500 |
int next_run_job() |
|
501 |
{ |
|
218 | 502 |
struct Job *p; |
503 |
||
219 | 504 |
/* busy_slots may be bigger than the maximum slots, |
505 |
* if the user was running many jobs, and suddenly |
|
506 |
* trimmed the maximum slots down. */ |
|
507 |
if (busy_slots >= max_slots) |
|
218 | 508 |
return -1; |
509 |
||
510 |
/* If there are no jobs to run... */ |
|
511 |
if (firstjob == 0) |
|
8 | 512 |
return -1; |
513 |
||
218 | 514 |
/* Look for a runnable task */ |
515 |
p = firstjob; |
|
516 |
while(p != 0) |
|
9 | 517 |
{ |
218 | 518 |
if (p->state == QUEUED) |
519 |
{ |
|
520 |
if (p->depend_on >= 0) |
|
521 |
{ |
|
259 | 522 |
struct Job *do_depend_job = get_job(p->depend_on); |
523 |
/* We won't try to run any job do_depending on an unfinished |
|
218 | 524 |
* job */ |
259 | 525 |
if (do_depend_job != NULL && |
526 |
(do_depend_job->state == QUEUED || do_depend_job->state == RUNNING)) |
|
218 | 527 |
{ |
528 |
/* Next try */ |
|
529 |
p = p->next; |
|
530 |
continue; |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
++busy_slots; |
|
535 |
return p->jobid; |
|
536 |
} |
|
537 |
p = p->next; |
|
9 | 538 |
} |
8 | 539 |
|
540 |
return -1; |
|
541 |
} |
|
542 |
||
64 | 543 |
/* Returns 1000 if no limit, The limit otherwise. */ |
544 |
static int get_max_finished_jobs() |
|
545 |
{ |
|
546 |
char *limit; |
|
547 |
||
548 |
limit = getenv("TS_MAXFINISHED"); |
|
549 |
if (limit == NULL) |
|
550 |
return 1000; |
|
551 |
return abs(atoi(limit)); |
|
552 |
} |
|
553 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
554 |
/* Add the job to the finished queue. */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
555 |
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
|
556 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
557 |
struct Job *p; |
64 | 558 |
int count, max; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
559 |
|
64 | 560 |
max = get_max_finished_jobs(); |
561 |
count = 0; |
|
562 |
||
563 |
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
|
564 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
565 |
first_finished_job = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
566 |
first_finished_job->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
567 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
568 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
569 |
|
64 | 570 |
++count; |
571 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
572 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
573 |
while(p->next != 0) |
64 | 574 |
{ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
575 |
p = p->next; |
64 | 576 |
++count; |
577 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
578 |
|
64 | 579 |
/* If too many jobs, wipe out the first */ |
580 |
if (count >= max) |
|
581 |
{ |
|
582 |
struct Job *tmp; |
|
583 |
tmp = first_finished_job; |
|
584 |
first_finished_job = first_finished_job->next; |
|
585 |
free(tmp->command); |
|
586 |
free(tmp->output_filename); |
|
148 | 587 |
pinfo_free(&tmp->info); |
150 | 588 |
free(tmp->label); |
64 | 589 |
free(tmp); |
590 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
591 |
p->next = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
592 |
p->next->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
593 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
594 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
595 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
596 |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
597 |
static int job_is_in_state(int jobid, enum Jobstate state) |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
598 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
599 |
struct Job *p; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
600 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
601 |
p = findjob(jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
602 |
if (p == 0) |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
603 |
return 0; |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
604 |
if (p->state == state) |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
605 |
return 1; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
606 |
return 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
607 |
} |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
608 |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
609 |
int job_is_running(int jobid) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
610 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
611 |
return job_is_in_state(jobid, RUNNING); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
612 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
613 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
614 |
int job_is_holding_client(int jobid) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
615 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
616 |
return job_is_in_state(jobid, HOLDING_CLIENT); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
617 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
618 |
|
218 | 619 |
void job_finished(const struct Result *result, int jobid) |
8 | 620 |
{ |
218 | 621 |
struct Job *p; |
622 |
||
623 |
if (busy_slots <= 0) |
|
624 |
error("Wrong state in the server. busy_slots = %i instead of greater than 0", busy_slots); |
|
8 | 625 |
|
218 | 626 |
p = findjob(jobid); |
627 |
if (p == 0) |
|
628 |
error("on jobid %i finished, it doesn't exist", jobid); |
|
8 | 629 |
|
288
8459747e1a73
Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
630 |
/* The job may be not only in running state, but also in other states, as |
8459747e1a73
Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
631 |
* we call this to clean up the jobs list in case of the client closing the |
8459747e1a73
Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
632 |
* connection. */ |
8459747e1a73
Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
633 |
if (p->state == RUNNING) |
8459747e1a73
Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
634 |
--busy_slots; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
635 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
636 |
/* Mark state */ |
156 | 637 |
if (result->skipped) |
218 | 638 |
p->state = SKIPPED; |
156 | 639 |
else |
218 | 640 |
p->state = FINISHED; |
641 |
p->result = *result; |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
642 |
last_finished_jobid = p->jobid; |
218 | 643 |
notify_errorlevel(p); |
644 |
pinfo_set_end_time(&p->info); |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
645 |
|
246
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
646 |
if (p->result.died_by_signal) |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
647 |
pinfo_addinfo(&p->info, 100, "Exit status: killed by signal %i\n", p->result.signal); |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
648 |
else |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
649 |
pinfo_addinfo(&p->info, 100, "Exit status: died with exit code %i\n", p->result.errorlevel); |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
650 |
|
218 | 651 |
/* Find the pointing node, to |
652 |
* update it removing the finished job. */ |
|
653 |
{ |
|
654 |
struct Job **jpointer = 0; |
|
655 |
struct Job *newfirst = p->next; |
|
656 |
if (firstjob == p) |
|
657 |
jpointer = &firstjob; |
|
658 |
else |
|
659 |
{ |
|
660 |
struct Job *p2; |
|
661 |
p2 = firstjob; |
|
662 |
while(p2 != 0) |
|
663 |
{ |
|
664 |
if (p2->next == p) |
|
665 |
{ |
|
666 |
jpointer = &(p2->next); |
|
667 |
break; |
|
668 |
} |
|
669 |
p2 = p2->next; |
|
670 |
} |
|
671 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
672 |
|
218 | 673 |
/* Add it to the finished queue */ |
674 |
if (p->should_keep_finished) |
|
675 |
new_finished_job(p); |
|
8 | 676 |
|
218 | 677 |
/* Remove it from the run queue */ |
678 |
if (jpointer == 0) |
|
679 |
error("Cannot remove a finished job from the " |
|
680 |
"queue list (jobid=%i)", p->jobid); |
|
681 |
||
682 |
*jpointer = newfirst; |
|
683 |
} |
|
8 | 684 |
} |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
685 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
686 |
void s_clear_finished() |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
687 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
688 |
struct Job *p; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
689 |
|
22 | 690 |
if (first_finished_job == 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
691 |
return; |
22 | 692 |
|
693 |
p = first_finished_job; |
|
694 |
first_finished_job = 0; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
695 |
|
64 | 696 |
while (p != 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
697 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
698 |
struct Job *tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
699 |
tmp = p->next; |
22 | 700 |
free(p->command); |
701 |
free(p->output_filename); |
|
148 | 702 |
pinfo_free(&p->info); |
150 | 703 |
free(p->label); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
704 |
free(p); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
705 |
p = tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
706 |
} |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
707 |
} |
22 | 708 |
|
35 | 709 |
void s_process_runjob_ok(int jobid, char *oname, int pid) |
22 | 710 |
{ |
711 |
struct Job *p; |
|
712 |
p = findjob(jobid); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
713 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
714 |
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
|
715 |
if (p->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
716 |
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
|
717 |
p->state); |
22 | 718 |
|
35 | 719 |
p->pid = pid; |
22 | 720 |
p->output_filename = oname; |
146 | 721 |
pinfo_set_start_time(&p->info); |
722 |
} |
|
723 |
||
218 | 724 |
void s_send_runjob(int s, int jobid) |
725 |
{ |
|
726 |
struct msg m; |
|
727 |
struct Job *p; |
|
728 |
||
729 |
p = findjob(jobid); |
|
730 |
if (p == 0) |
|
731 |
error("Job %i was expected to run", jobid); |
|
732 |
||
733 |
||
734 |
m.type = RUNJOB; |
|
735 |
||
736 |
/* TODO |
|
259 | 737 |
* We should make the dependencies update the jobids they're do_depending on. |
218 | 738 |
* Then, on finish, these could set the errorlevel to send to its dependency childs. |
739 |
* We cannot consider that the jobs will leave traces in the finished job list (-nf?) . */ |
|
740 |
||
741 |
m.u.last_errorlevel = p->dependency_errorlevel; |
|
742 |
||
743 |
send_msg(s, &m); |
|
744 |
} |
|
745 |
||
146 | 746 |
void s_job_info(int s, int jobid) |
747 |
{ |
|
748 |
struct Job *p = 0; |
|
749 |
struct msg m; |
|
750 |
||
751 |
if (jobid == -1) |
|
752 |
{ |
|
753 |
/* This means that we want the job info of the running task, or that |
|
754 |
* of the last job run */ |
|
218 | 755 |
if (busy_slots > 0) |
146 | 756 |
{ |
757 |
p = firstjob; |
|
758 |
if (p == 0) |
|
759 |
error("Internal state WAITING, but job not run." |
|
760 |
"firstjob = %x", firstjob); |
|
761 |
} |
|
762 |
else |
|
763 |
{ |
|
764 |
p = first_finished_job; |
|
765 |
if (p == 0) |
|
766 |
{ |
|
767 |
send_list_line(s, "No jobs.\n"); |
|
768 |
return; |
|
769 |
} |
|
770 |
while(p->next != 0) |
|
771 |
p = p->next; |
|
772 |
} |
|
773 |
} else |
|
774 |
{ |
|
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
|
775 |
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
|
776 |
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
|
777 |
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
|
778 |
|
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
779 |
/* 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
|
780 |
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
|
781 |
{ |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
782 |
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
|
783 |
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
|
784 |
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
|
785 |
} |
146 | 786 |
} |
787 |
||
788 |
if (p == 0) |
|
789 |
{ |
|
790 |
char tmp[50]; |
|
791 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
|
792 |
send_list_line(s, tmp); |
|
793 |
return; |
|
794 |
} |
|
795 |
||
796 |
m.type = INFO_DATA; |
|
797 |
send_msg(s, &m); |
|
798 |
pinfo_dump(&p->info, s); |
|
218 | 799 |
fd_nprintf(s, 100, "Command: %s", (p->depend_on != -1)?"&& ":""); |
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
|
800 |
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
|
801 |
fd_nprintf(s, 100, "\n"); |
146 | 802 |
fd_nprintf(s, 100, "Enqueue time: %s", |
803 |
ctime(&p->info.enqueue_time.tv_sec)); |
|
804 |
if (p->state == RUNNING) |
|
805 |
{ |
|
806 |
fd_nprintf(s, 100, "Start time: %s", |
|
807 |
ctime(&p->info.start_time.tv_sec)); |
|
808 |
fd_nprintf(s, 100, "Time running: %fs\n", |
|
809 |
pinfo_time_until_now(&p->info)); |
|
810 |
} else if (p->state == FINISHED) |
|
811 |
{ |
|
812 |
fd_nprintf(s, 100, "Start time: %s", |
|
813 |
ctime(&p->info.start_time.tv_sec)); |
|
814 |
fd_nprintf(s, 100, "End time: %s", |
|
815 |
ctime(&p->info.end_time.tv_sec)); |
|
816 |
fd_nprintf(s, 100, "Time run: %fs\n", |
|
817 |
pinfo_time_run(&p->info)); |
|
818 |
} |
|
22 | 819 |
} |
32 | 820 |
|
821 |
void s_send_output(int s, int jobid) |
|
822 |
{ |
|
823 |
struct Job *p = 0; |
|
824 |
struct msg m; |
|
825 |
||
826 |
if (jobid == -1) |
|
827 |
{ |
|
146 | 828 |
/* This means that we want the output info of the running task, or that |
32 | 829 |
* of the last job run */ |
218 | 830 |
if (busy_slots > 0) |
32 | 831 |
{ |
832 |
p = firstjob; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
833 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
834 |
error("Internal state WAITING, but job not run." |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
835 |
"firstjob = %x", firstjob); |
32 | 836 |
} |
837 |
else |
|
838 |
{ |
|
839 |
p = first_finished_job; |
|
840 |
if (p == 0) |
|
841 |
{ |
|
842 |
send_list_line(s, "No jobs.\n"); |
|
843 |
return; |
|
844 |
} |
|
845 |
while(p->next != 0) |
|
846 |
p = p->next; |
|
847 |
} |
|
848 |
} else |
|
849 |
{ |
|
218 | 850 |
p = get_job(jobid); |
225
6c2583ea71eb
Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents:
224
diff
changeset
|
851 |
if (p != 0 && p->state != RUNNING |
6c2583ea71eb
Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents:
224
diff
changeset
|
852 |
&& p->state != FINISHED |
6c2583ea71eb
Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents:
224
diff
changeset
|
853 |
&& p->state != SKIPPED) |
218 | 854 |
p = 0; |
32 | 855 |
} |
856 |
||
857 |
if (p == 0) |
|
858 |
{ |
|
859 |
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
|
860 |
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
|
861 |
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
|
862 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
863 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
32 | 864 |
send_list_line(s, tmp); |
865 |
return; |
|
866 |
} |
|
867 |
||
157 | 868 |
if (p->state == SKIPPED) |
156 | 869 |
{ |
870 |
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
|
871 |
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
|
872 |
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
|
873 |
|
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
874 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
875 |
sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid); |
156 | 876 |
send_list_line(s, tmp); |
877 |
return; |
|
878 |
} |
|
879 |
||
32 | 880 |
m.type = ANSWER_OUTPUT; |
881 |
m.u.output.store_output = p->store_output; |
|
35 | 882 |
m.u.output.pid = p->pid; |
289
f331d05328b3
Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents:
288
diff
changeset
|
883 |
if (m.u.output.store_output && p->output_filename) |
153 | 884 |
m.u.output.ofilename_size = strlen(p->output_filename) + 1; |
885 |
else |
|
886 |
m.u.output.ofilename_size = 0; |
|
32 | 887 |
send_msg(s, &m); |
289
f331d05328b3
Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents:
288
diff
changeset
|
888 |
if (m.u.output.ofilename_size > 0) |
f331d05328b3
Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents:
288
diff
changeset
|
889 |
send_bytes(s, p->output_filename, m.u.output.ofilename_size); |
32 | 890 |
} |
41 | 891 |
|
218 | 892 |
void notify_errorlevel(struct Job *p) |
893 |
{ |
|
259 | 894 |
int i; |
895 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
896 |
last_errorlevel = p->result.errorlevel; |
259 | 897 |
|
898 |
for(i = 0; i < p->notify_errorlevel_to_size; ++i) |
|
218 | 899 |
{ |
900 |
struct Job *notified; |
|
259 | 901 |
notified = get_job(p->notify_errorlevel_to[i]); |
218 | 902 |
if (notified) |
903 |
{ |
|
904 |
notified->dependency_errorlevel = p->result.errorlevel; |
|
905 |
} |
|
906 |
} |
|
907 |
} |
|
908 |
||
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
909 |
int s_remove_job(int s, int jobid) |
41 | 910 |
{ |
911 |
struct Job *p = 0; |
|
912 |
struct msg m; |
|
913 |
struct Job *before_p = 0; |
|
914 |
||
915 |
if (jobid == -1) |
|
916 |
{ |
|
917 |
/* Find the last job added */ |
|
918 |
p = firstjob; |
|
919 |
if (p != 0) |
|
920 |
{ |
|
921 |
while (p->next != 0) |
|
922 |
{ |
|
923 |
before_p = p; |
|
924 |
p = p->next; |
|
925 |
} |
|
180 | 926 |
} else |
927 |
{ |
|
928 |
/* last 'finished' */ |
|
929 |
p = first_finished_job; |
|
190 | 930 |
if (p) |
180 | 931 |
{ |
190 | 932 |
while (p->next != 0) |
933 |
{ |
|
934 |
before_p = p; |
|
935 |
p = p->next; |
|
936 |
} |
|
180 | 937 |
} |
41 | 938 |
} |
939 |
} |
|
940 |
else |
|
941 |
{ |
|
942 |
p = firstjob; |
|
943 |
if (p != 0) |
|
944 |
{ |
|
945 |
while (p->next != 0 && p->jobid != jobid) |
|
946 |
{ |
|
947 |
before_p = p; |
|
948 |
p = p->next; |
|
949 |
} |
|
950 |
} |
|
180 | 951 |
|
952 |
/* If not found, look in the 'finished' list */ |
|
953 |
if (p == 0 || p->jobid != jobid) |
|
954 |
{ |
|
955 |
p = first_finished_job; |
|
956 |
if (p != 0) |
|
957 |
{ |
|
958 |
while (p->next != 0 && p->jobid != jobid) |
|
959 |
{ |
|
960 |
before_p = p; |
|
961 |
p = p->next; |
|
962 |
} |
|
227
3570252beade
Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents:
226
diff
changeset
|
963 |
if (p->jobid != jobid) |
3570252beade
Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents:
226
diff
changeset
|
964 |
p = 0; |
180 | 965 |
} |
966 |
} |
|
41 | 967 |
} |
968 |
||
227
3570252beade
Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents:
226
diff
changeset
|
969 |
if (p == 0 || p->state == RUNNING || p == firstjob) |
41 | 970 |
{ |
971 |
char tmp[50]; |
|
972 |
if (jobid == -1) |
|
44 | 973 |
sprintf(tmp, "The last job cannot be removed.\n"); |
41 | 974 |
else |
975 |
sprintf(tmp, "The job %i cannot be removed.\n", jobid); |
|
976 |
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
|
977 |
return 0; |
41 | 978 |
} |
979 |
||
178
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
980 |
/* Tricks for the check_notify_list */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
981 |
p->state = FINISHED; |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
982 |
p->result.errorlevel = -1; |
218 | 983 |
notify_errorlevel(p); |
984 |
||
178
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
985 |
/* Notify the clients in wait_job */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
986 |
check_notify_list(m.u.jobid); |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
987 |
|
180 | 988 |
/* Update the list pointers */ |
989 |
if (p == first_finished_job) |
|
990 |
first_finished_job = p->next; |
|
991 |
else |
|
992 |
before_p->next = p->next; |
|
993 |
||
259 | 994 |
free(p->notify_errorlevel_to); |
64 | 995 |
free(p->command); |
996 |
free(p->output_filename); |
|
146 | 997 |
pinfo_free(&p->info); |
150 | 998 |
free(p->label); |
41 | 999 |
free(p); |
180 | 1000 |
|
41 | 1001 |
m.type = REMOVEJOB_OK; |
1002 |
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
|
1003 |
return 1; |
41 | 1004 |
} |
42 | 1005 |
|
1006 |
static void add_to_notify_list(int s, int jobid) |
|
1007 |
{ |
|
1008 |
struct Notify *n; |
|
1009 |
struct Notify *new; |
|
1010 |
||
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1011 |
new = (struct Notify *) malloc(sizeof(*new)); |
42 | 1012 |
|
1013 |
new->socket = s; |
|
1014 |
new->jobid = jobid; |
|
1015 |
new->next = 0; |
|
1016 |
||
1017 |
n = first_notify; |
|
1018 |
if (n == 0) |
|
1019 |
{ |
|
1020 |
first_notify = new; |
|
1021 |
return; |
|
1022 |
} |
|
1023 |
||
1024 |
while(n->next != 0) |
|
1025 |
n = n->next; |
|
1026 |
||
1027 |
n->next = new; |
|
1028 |
} |
|
1029 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1030 |
static void send_waitjob_ok(int s, int errorlevel) |
42 | 1031 |
{ |
1032 |
struct msg m; |
|
1033 |
||
1034 |
m.type = WAITJOB_OK; |
|
112 | 1035 |
m.u.result.errorlevel = errorlevel; |
42 | 1036 |
send_msg(s, &m); |
1037 |
} |
|
1038 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1039 |
static struct Job * |
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1040 |
get_job(int jobid) |
42 | 1041 |
{ |
1042 |
struct Job *j; |
|
1043 |
||
1044 |
j = findjob(jobid); |
|
1045 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1046 |
return j; |
42 | 1047 |
|
1048 |
j = find_finished_job(jobid); |
|
1049 |
||
1050 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1051 |
return j; |
42 | 1052 |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1053 |
return 0; |
42 | 1054 |
} |
1055 |
||
1056 |
/* Don't complain, if the socket doesn't exist */ |
|
1057 |
void s_remove_notification(int s) |
|
1058 |
{ |
|
1059 |
struct Notify *n; |
|
1060 |
struct Notify *previous; |
|
1061 |
n = first_notify; |
|
1062 |
while (n != 0 && n->socket != s) |
|
1063 |
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
|
1064 |
if (n == 0 || n->socket != s) |
42 | 1065 |
return; |
1066 |
||
1067 |
/* Remove the notification */ |
|
1068 |
previous = first_notify; |
|
1069 |
if (n == previous) |
|
1070 |
{ |
|
254
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1071 |
first_notify = n->next; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1072 |
free(n); |
42 | 1073 |
return; |
1074 |
} |
|
1075 |
||
1076 |
/* if not the first... */ |
|
1077 |
while(previous->next != n) |
|
1078 |
previous = previous->next; |
|
1079 |
||
1080 |
previous->next = n->next; |
|
1081 |
free(n); |
|
1082 |
} |
|
1083 |
||
1084 |
/* This is called when a job finishes */ |
|
1085 |
void check_notify_list(int jobid) |
|
1086 |
{ |
|
206
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1087 |
struct Notify *n, *tmp; |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1088 |
struct Job *j; |
42 | 1089 |
|
1090 |
n = first_notify; |
|
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1091 |
while (n != 0) |
42 | 1092 |
{ |
206
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1093 |
tmp = n; |
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1094 |
n = n->next; |
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1095 |
if (tmp->jobid == jobid) |
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1096 |
{ |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1097 |
j = get_job(jobid); |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1098 |
/* If the job finishes, notify the waiter */ |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1099 |
if (j->state == FINISHED || j->state == SKIPPED) |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1100 |
{ |
209
507bd37ab1d3
Bug resolving a pointer when notifying job_ends.
lbatlle@npdl268.bpo.hp.com
parents:
206
diff
changeset
|
1101 |
send_waitjob_ok(tmp->socket, j->result.errorlevel); |
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1102 |
/* We want to get the next Nofity* before we remove |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1103 |
* the actual 'n'. As s_remove_notification() simply |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1104 |
* removes the element from the linked list, we can |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1105 |
* safely follow on the list from n->next. */ |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1106 |
s_remove_notification(tmp->socket); |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1107 |
} |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1108 |
} |
42 | 1109 |
} |
1110 |
} |
|
1111 |
||
1112 |
void s_wait_job(int s, int jobid) |
|
1113 |
{ |
|
1114 |
struct Job *p = 0; |
|
1115 |
||
1116 |
if (jobid == -1) |
|
1117 |
{ |
|
1118 |
/* Find the last job added */ |
|
1119 |
p = firstjob; |
|
1120 |
||
1121 |
if (p != 0) |
|
1122 |
while (p->next != 0) |
|
1123 |
p = p->next; |
|
1124 |
||
1125 |
/* Look in finished jobs if needed */ |
|
1126 |
if (p == 0) |
|
1127 |
{ |
|
1128 |
p = first_finished_job; |
|
1129 |
if (p != 0) |
|
1130 |
while (p->next != 0) |
|
1131 |
p = p->next; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
else |
|
1135 |
{ |
|
1136 |
p = firstjob; |
|
1137 |
while (p != 0 && p->jobid != jobid) |
|
1138 |
p = p->next; |
|
1139 |
||
1140 |
/* Look in finished jobs if needed */ |
|
1141 |
if (p == 0) |
|
1142 |
{ |
|
1143 |
p = first_finished_job; |
|
1144 |
while (p != 0 && p->jobid != jobid) |
|
1145 |
p = p->next; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
||
1149 |
if (p == 0) |
|
1150 |
{ |
|
1151 |
char tmp[50]; |
|
1152 |
if (jobid == -1) |
|
44 | 1153 |
sprintf(tmp, "The last job cannot be waited.\n"); |
42 | 1154 |
else |
1155 |
sprintf(tmp, "The job %i cannot be waited.\n", jobid); |
|
1156 |
send_list_line(s, tmp); |
|
1157 |
return; |
|
1158 |
} |
|
1159 |
||
166
8c19a66b5407
Fixing a bug on wait_job on skipped jobs. Moving vnumber to 0.5
viric@vicerveza
parents:
157
diff
changeset
|
1160 |
if (p->state == FINISHED || p->state == SKIPPED) |
42 | 1161 |
{ |
112 | 1162 |
send_waitjob_ok(s, p->result.errorlevel); |
42 | 1163 |
} |
1164 |
else |
|
1165 |
add_to_notify_list(s, p->jobid); |
|
1166 |
} |
|
53 | 1167 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1168 |
void s_wait_running_job(int s, int jobid) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1169 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1170 |
struct Job *p = 0; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1171 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1172 |
/* The job finding algorithm should be similar to that of |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1173 |
* s_send_output, because this will be used by "-t" and "-c" */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1174 |
if (jobid == -1) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1175 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1176 |
/* This means that we want the output info of the running task, or that |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1177 |
* of the last job run */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1178 |
if (busy_slots > 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1179 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1180 |
p = firstjob; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1181 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1182 |
error("Internal state WAITING, but job not run." |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1183 |
"firstjob = %x", firstjob); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1184 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1185 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1186 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1187 |
p = first_finished_job; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1188 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1189 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1190 |
send_list_line(s, "No jobs.\n"); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1191 |
return; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1192 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1193 |
while(p->next != 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1194 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1195 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1196 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1197 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1198 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1199 |
p = firstjob; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1200 |
while (p != 0 && p->jobid != jobid) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1201 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1202 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1203 |
/* Look in finished jobs if needed */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1204 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1205 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1206 |
p = first_finished_job; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1207 |
while (p != 0 && p->jobid != jobid) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1208 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1209 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1210 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1211 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1212 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1213 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1214 |
char tmp[50]; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1215 |
if (jobid == -1) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1216 |
sprintf(tmp, "The last job cannot be waited.\n"); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1217 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1218 |
sprintf(tmp, "The job %i cannot be waited.\n", jobid); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1219 |
send_list_line(s, tmp); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1220 |
return; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1221 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1222 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1223 |
if (p->state == FINISHED || p->state == SKIPPED) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1224 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1225 |
send_waitjob_ok(s, p->result.errorlevel); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1226 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1227 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1228 |
add_to_notify_list(s, p->jobid); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1229 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1230 |
|
219 | 1231 |
void s_set_max_slots(int new_max_slots) |
1232 |
{ |
|
1233 |
if (new_max_slots > 0) |
|
1234 |
max_slots = new_max_slots; |
|
1235 |
else |
|
1236 |
warning("Received new_max_slots=%i", new_max_slots); |
|
1237 |
} |
|
1238 |
||
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1239 |
void s_get_max_slots(int s) |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1240 |
{ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1241 |
struct msg m; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1242 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1243 |
/* Message */ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1244 |
m.type = GET_MAX_SLOTS_OK; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1245 |
m.u.max_slots = max_slots; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1246 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1247 |
send_msg(s, &m); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1248 |
} |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1249 |
|
53 | 1250 |
void s_move_urgent(int s, int jobid) |
1251 |
{ |
|
1252 |
struct Job *p = 0; |
|
1253 |
struct Job *tmp1; |
|
1254 |
||
1255 |
if (jobid == -1) |
|
1256 |
{ |
|
1257 |
/* Find the last job added */ |
|
1258 |
p = firstjob; |
|
1259 |
||
1260 |
if (p != 0) |
|
1261 |
while (p->next != 0) |
|
1262 |
p = p->next; |
|
1263 |
} |
|
1264 |
else |
|
1265 |
{ |
|
1266 |
p = firstjob; |
|
1267 |
while (p != 0 && p->jobid != jobid) |
|
1268 |
p = p->next; |
|
1269 |
} |
|
1270 |
||
1271 |
if (p == 0 || firstjob->next == 0) |
|
1272 |
{ |
|
1273 |
char tmp[50]; |
|
1274 |
if (jobid == -1) |
|
1275 |
sprintf(tmp, "The last job cannot be urged.\n"); |
|
1276 |
else |
|
1277 |
sprintf(tmp, "The job %i cannot be urged.\n", jobid); |
|
1278 |
send_list_line(s, tmp); |
|
1279 |
return; |
|
1280 |
} |
|
1281 |
||
1282 |
/* Interchange the pointers */ |
|
1283 |
tmp1 = find_previous_job(p); |
|
1284 |
tmp1->next = p->next; |
|
1285 |
p->next = firstjob->next; |
|
1286 |
firstjob->next = p; |
|
1287 |
||
1288 |
||
1289 |
send_urgent_ok(s); |
|
1290 |
} |
|
63 | 1291 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1292 |
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
|
1293 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1294 |
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
|
1295 |
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
|
1296 |
struct Job *tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1297 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1298 |
p1 = findjob(jobid1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1299 |
p2 = findjob(jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1300 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1301 |
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
|
1302 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1303 |
char prev[60]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1304 |
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
|
1305 |
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
|
1306 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1307 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1308 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1309 |
/* Interchange the pointers */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1310 |
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
|
1311 |
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
|
1312 |
prev1->next = p2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1313 |
prev2->next = p1; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1314 |
tmp = p1->next; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1315 |
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
|
1316 |
p2->next = tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1317 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1318 |
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
|
1319 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1320 |
|
63 | 1321 |
static void send_state(int s, enum Jobstate state) |
1322 |
{ |
|
1323 |
struct msg m; |
|
1324 |
||
1325 |
m.type = ANSWER_STATE; |
|
1326 |
m.u.state = state; |
|
1327 |
||
1328 |
send_msg(s, &m); |
|
1329 |
} |
|
1330 |
||
1331 |
void s_send_state(int s, int jobid) |
|
1332 |
{ |
|
1333 |
struct Job *p = 0; |
|
1334 |
||
1335 |
if (jobid == -1) |
|
1336 |
{ |
|
1337 |
/* Find the last job added */ |
|
1338 |
p = firstjob; |
|
1339 |
||
1340 |
if (p != 0) |
|
1341 |
while (p->next != 0) |
|
1342 |
p = p->next; |
|
1343 |
||
1344 |
/* Look in finished jobs if needed */ |
|
1345 |
if (p == 0) |
|
1346 |
{ |
|
1347 |
p = first_finished_job; |
|
1348 |
if (p != 0) |
|
1349 |
while (p->next != 0) |
|
1350 |
p = p->next; |
|
1351 |
} |
|
1352 |
||
1353 |
} |
|
1354 |
else |
|
1355 |
{ |
|
1356 |
p = get_job(jobid); |
|
1357 |
} |
|
1358 |
||
1359 |
if (p == 0) |
|
1360 |
{ |
|
1361 |
char tmp[50]; |
|
1362 |
if (jobid == -1) |
|
1363 |
sprintf(tmp, "The last job cannot be stated.\n"); |
|
1364 |
else |
|
1365 |
sprintf(tmp, "The job %i cannot be stated.\n", jobid); |
|
1366 |
send_list_line(s, tmp); |
|
1367 |
return; |
|
1368 |
} |
|
1369 |
||
1370 |
/* Interchange the pointers */ |
|
1371 |
send_state(s, p->state); |
|
1372 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1373 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1374 |
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
|
1375 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1376 |
fprintf(out, " new_job\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1377 |
fprintf(out, " jobid %i\n", p->jobid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1378 |
fprintf(out, " command \"%s\"\n", p->command); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1379 |
fprintf(out, " state %s\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1380 |
jstate2string(p->state)); |
112 | 1381 |
fprintf(out, " result.errorlevel %i\n", p->result.errorlevel); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1382 |
fprintf(out, " output_filename \"%s\"\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1383 |
p->output_filename ? p->output_filename : "NULL"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1384 |
fprintf(out, " store_output %i\n", p->store_output); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1385 |
fprintf(out, " pid %i\n", p->pid); |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
1386 |
fprintf(out, " should_keep_finished %i\n", p->should_keep_finished); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1387 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1388 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1389 |
void dump_jobs_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1390 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1391 |
const struct Job *p; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1392 |
|
104 | 1393 |
fprintf(out, "New_jobs\n"); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1394 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1395 |
p = firstjob; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1396 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1397 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1398 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1399 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1400 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1401 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1402 |
p = first_finished_job; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1403 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1404 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1405 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1406 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1407 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1408 |
} |
120 | 1409 |
|
254
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1410 |
static void dump_notify_struct(FILE *out, const struct Notify *n) |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1411 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1412 |
fprintf(out, " notify\n"); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1413 |
fprintf(out, " jobid %i\n", n->jobid); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1414 |
fprintf(out, " socket \"%i\"\n", n->socket); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1415 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1416 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1417 |
void dump_notifies_struct(FILE *out) |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1418 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1419 |
const struct Notify *n; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1420 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1421 |
fprintf(out, "New_notifies\n"); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1422 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1423 |
n = first_notify; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1424 |
while (n != 0) |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1425 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1426 |
dump_notify_struct(out, n); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1427 |
n = n->next; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1428 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1429 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1430 |
|
120 | 1431 |
void joblist_dump(int fd) |
1432 |
{ |
|
1433 |
struct Job *p; |
|
1434 |
char *buffer; |
|
1435 |
||
1436 |
buffer = joblistdump_headers(); |
|
1437 |
write(fd,buffer, strlen(buffer)); |
|
1438 |
free(buffer); |
|
1439 |
||
1440 |
/* We reuse the headers from the list */ |
|
1441 |
buffer = joblist_headers(); |
|
1442 |
write(fd, "# ", 2); |
|
1443 |
write(fd, buffer, strlen(buffer)); |
|
1444 |
||
1445 |
/* Show Finished jobs */ |
|
1446 |
p = first_finished_job; |
|
1447 |
while(p != 0) |
|
1448 |
{ |
|
1449 |
buffer = joblist_line(p); |
|
1450 |
write(fd, "# ", 2); |
|
1451 |
write(fd,buffer, strlen(buffer)); |
|
1452 |
free(buffer); |
|
1453 |
p = p->next; |
|
1454 |
} |
|
1455 |
||
1456 |
write(fd, "\n", 1); |
|
1457 |
||
1458 |
/* Show Queued or Running jobs */ |
|
1459 |
p = firstjob; |
|
1460 |
while(p != 0) |
|
1461 |
{ |
|
1462 |
buffer = joblistdump_torun(p); |
|
1463 |
write(fd,buffer,strlen(buffer)); |
|
1464 |
free(buffer); |
|
1465 |
p = p->next; |
|
1466 |
} |
|
1467 |
} |