author | viric <viriketo@gmail.com> |
Wed, 19 Oct 2016 22:09:43 +0200 | |
changeset 353 | cee48819d7e4 |
parent 346 | 90545736507e |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
335 | 3 |
Copyright (C) 2007-2013 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; |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
289
diff
changeset
|
329 |
p->num_slots = m->u.newjob.num_slots; |
27
886bdb2f4632
Fixed the Output File information in the list.
viric@llimona
parents:
26
diff
changeset
|
330 |
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
|
331 |
p->should_keep_finished = m->u.newjob.should_keep_finished; |
259 | 332 |
p->notify_errorlevel_to = 0; |
333 |
p->notify_errorlevel_to_size = 0; |
|
334 |
p->do_depend = m->u.newjob.do_depend; |
|
335 |
p->depend_on = -1; /* By default. May be overriden in the next conditions */ |
|
336 |
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
|
337 |
{ |
259 | 338 |
/* Depend on the last queued job. */ |
339 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
340 |
/* 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
|
341 |
* neglect it during the find_last_jobid_in_queue() */ |
259 | 342 |
if (m->u.newjob.depend_on == -1) |
343 |
{ |
|
344 |
p->depend_on = find_last_jobid_in_queue(p->jobid); |
|
345 |
||
346 |
/* We don't trust the last jobid in the queue (running or queued) |
|
347 |
* if it's not the last added job. In that case, let |
|
348 |
* the next control flow handle it as if it could not |
|
349 |
* do_depend on any still queued job. */ |
|
350 |
if (last_finished_jobid > p->depend_on) |
|
351 |
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
|
352 |
|
259 | 353 |
/* If it's queued still without result, let it know |
354 |
* its result to p when it finishes. */ |
|
355 |
if (p->depend_on != -1) |
|
356 |
{ |
|
357 |
struct Job *depended_job; |
|
358 |
depended_job = findjob(p->depend_on); |
|
359 |
if (depended_job != 0) |
|
360 |
add_notify_errorlevel_to(depended_job, p->jobid); |
|
361 |
else |
|
362 |
warning("The jobid %i is queued to do_depend on the jobid %i" |
|
346 | 363 |
" suddenly non existent in the queue", p->jobid, |
259 | 364 |
p->depend_on); |
365 |
} |
|
366 |
else /* Otherwise take the finished job, or the last_errorlevel */ |
|
367 |
{ |
|
368 |
if (m->u.newjob.depend_on == -1) |
|
369 |
{ |
|
370 |
int ljobid = find_last_stored_jobid_finished(); |
|
317
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
371 |
p->depend_on = ljobid; |
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
372 |
|
259 | 373 |
/* If we have a newer result stored, use it */ |
317
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
374 |
/* NOTE: |
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
375 |
* Reading this now, I don't know how ljobid can be |
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
376 |
* greater than last_finished_jobid */ |
259 | 377 |
if (last_finished_jobid < ljobid) |
378 |
{ |
|
379 |
struct Job *parent; |
|
380 |
parent = find_finished_job(ljobid); |
|
381 |
if (!parent) |
|
382 |
error("jobid %i suddenly disappeared from the finished list", |
|
383 |
ljobid); |
|
384 |
p->dependency_errorlevel = parent->result.errorlevel; |
|
385 |
} |
|
386 |
else |
|
387 |
p->dependency_errorlevel = last_errorlevel; |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
else |
|
392 |
{ |
|
393 |
/* The user decided what's the job this new job depends on */ |
|
394 |
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
|
395 |
|
259 | 396 |
p->depend_on = m->u.newjob.depend_on; |
397 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
398 |
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
|
399 |
if (depended_job != 0) |
259 | 400 |
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
|
401 |
else |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
402 |
{ |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
403 |
struct Job *parent; |
259 | 404 |
parent = find_finished_job(p->depend_on); |
405 |
if (parent) |
|
406 |
{ |
|
407 |
p->dependency_errorlevel = parent->result.errorlevel; |
|
408 |
} |
|
409 |
else |
|
410 |
{ |
|
411 |
/* We consider as if the job not found |
|
412 |
didn't finish well */ |
|
413 |
p->dependency_errorlevel = -1; |
|
414 |
} |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
415 |
} |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
416 |
} |
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
417 |
} |
218 | 418 |
|
18 | 419 |
|
147 | 420 |
pinfo_init(&p->info); |
146 | 421 |
pinfo_set_enqueue_time(&p->info); |
422 |
||
18 | 423 |
/* load the command */ |
424 |
p->command = malloc(m->u.newjob.command_size); |
|
147 | 425 |
if (p->command == 0) |
426 |
error("Cannot allocate memory in s_newjob command_size (%i)", |
|
427 |
m->u.newjob.command_size); |
|
18 | 428 |
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
|
429 |
if (res == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
430 |
error("wrong bytes received"); |
3 | 431 |
|
150 | 432 |
/* load the label */ |
433 |
p->label = 0; |
|
434 |
if (m->u.newjob.label_size > 0) |
|
435 |
{ |
|
436 |
char *ptr; |
|
437 |
ptr = (char *) malloc(m->u.newjob.label_size); |
|
438 |
if (ptr == 0) |
|
439 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
440 |
m->u.newjob.env_size); |
|
441 |
res = recv_bytes(s, ptr, m->u.newjob.label_size); |
|
442 |
if (res == -1) |
|
443 |
error("wrong bytes received"); |
|
444 |
p->label = ptr; |
|
445 |
} |
|
446 |
||
147 | 447 |
/* load the info */ |
448 |
if (m->u.newjob.env_size > 0) |
|
449 |
{ |
|
450 |
char *ptr; |
|
451 |
ptr = (char *) malloc(m->u.newjob.env_size); |
|
452 |
if (ptr == 0) |
|
453 |
error("Cannot allocate memory in s_newjob env_size(%i)", |
|
454 |
m->u.newjob.env_size); |
|
455 |
res = recv_bytes(s, ptr, m->u.newjob.env_size); |
|
456 |
if (res == -1) |
|
457 |
error("wrong bytes received"); |
|
458 |
pinfo_addinfo(&p->info, m->u.newjob.env_size+100, |
|
459 |
"Environment:\n%s", ptr); |
|
460 |
free(ptr); |
|
461 |
} |
|
462 |
||
3 | 463 |
return p->jobid; |
464 |
} |
|
465 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
466 |
/* This assumes the jobid exists */ |
3 | 467 |
void s_removejob(int jobid) |
468 |
{ |
|
469 |
struct Job *p; |
|
470 |
struct Job *newnext; |
|
471 |
||
472 |
if (firstjob->jobid == jobid) |
|
473 |
{ |
|
474 |
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
|
475 |
|
3 | 476 |
/* First job is to be removed */ |
477 |
newfirst = firstjob->next; |
|
18 | 478 |
free(firstjob->command); |
64 | 479 |
free(firstjob->output_filename); |
148 | 480 |
pinfo_free(&firstjob->info); |
150 | 481 |
free(firstjob->label); |
3 | 482 |
free(firstjob); |
483 |
firstjob = newfirst; |
|
484 |
return; |
|
485 |
} |
|
486 |
||
487 |
p = firstjob; |
|
488 |
/* Not first job */ |
|
489 |
while (p->next != 0) |
|
490 |
{ |
|
491 |
if (p->next->jobid == jobid) |
|
492 |
break; |
|
493 |
p = p->next; |
|
494 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
495 |
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
|
496 |
error("Job to be removed not found. jobid=%i", jobid); |
3 | 497 |
|
498 |
newnext = p->next->next; |
|
499 |
||
18 | 500 |
free(p->next->command); |
3 | 501 |
free(p->next); |
502 |
p->next = newnext; |
|
503 |
} |
|
8 | 504 |
|
505 |
/* -1 if no one should be run. */ |
|
506 |
int next_run_job() |
|
507 |
{ |
|
218 | 508 |
struct Job *p; |
509 |
||
316
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
510 |
const int free_slots = max_slots - busy_slots; |
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
511 |
|
219 | 512 |
/* busy_slots may be bigger than the maximum slots, |
513 |
* if the user was running many jobs, and suddenly |
|
514 |
* trimmed the maximum slots down. */ |
|
316
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
515 |
if (free_slots <= 0) |
218 | 516 |
return -1; |
517 |
||
518 |
/* If there are no jobs to run... */ |
|
519 |
if (firstjob == 0) |
|
8 | 520 |
return -1; |
521 |
||
218 | 522 |
/* Look for a runnable task */ |
523 |
p = firstjob; |
|
524 |
while(p != 0) |
|
9 | 525 |
{ |
218 | 526 |
if (p->state == QUEUED) |
527 |
{ |
|
528 |
if (p->depend_on >= 0) |
|
529 |
{ |
|
259 | 530 |
struct Job *do_depend_job = get_job(p->depend_on); |
531 |
/* We won't try to run any job do_depending on an unfinished |
|
218 | 532 |
* job */ |
259 | 533 |
if (do_depend_job != NULL && |
534 |
(do_depend_job->state == QUEUED || do_depend_job->state == RUNNING)) |
|
218 | 535 |
{ |
536 |
/* Next try */ |
|
537 |
p = p->next; |
|
538 |
continue; |
|
539 |
} |
|
540 |
} |
|
541 |
||
316
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
542 |
if (free_slots >= p->num_slots) |
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
543 |
{ |
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
544 |
busy_slots = busy_slots + p->num_slots; |
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
545 |
return p->jobid; |
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
546 |
} |
218 | 547 |
} |
548 |
p = p->next; |
|
9 | 549 |
} |
8 | 550 |
|
551 |
return -1; |
|
552 |
} |
|
553 |
||
64 | 554 |
/* Returns 1000 if no limit, The limit otherwise. */ |
555 |
static int get_max_finished_jobs() |
|
556 |
{ |
|
557 |
char *limit; |
|
558 |
||
559 |
limit = getenv("TS_MAXFINISHED"); |
|
560 |
if (limit == NULL) |
|
561 |
return 1000; |
|
562 |
return abs(atoi(limit)); |
|
563 |
} |
|
564 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
565 |
/* Add the job to the finished queue. */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
566 |
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
|
567 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
568 |
struct Job *p; |
64 | 569 |
int count, max; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
570 |
|
64 | 571 |
max = get_max_finished_jobs(); |
572 |
count = 0; |
|
573 |
||
574 |
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
|
575 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
576 |
first_finished_job = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
577 |
first_finished_job->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
578 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
579 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
580 |
|
64 | 581 |
++count; |
582 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
583 |
p = first_finished_job; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
584 |
while(p->next != 0) |
64 | 585 |
{ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
586 |
p = p->next; |
64 | 587 |
++count; |
588 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
589 |
|
64 | 590 |
/* If too many jobs, wipe out the first */ |
591 |
if (count >= max) |
|
592 |
{ |
|
593 |
struct Job *tmp; |
|
594 |
tmp = first_finished_job; |
|
595 |
first_finished_job = first_finished_job->next; |
|
596 |
free(tmp->command); |
|
597 |
free(tmp->output_filename); |
|
148 | 598 |
pinfo_free(&tmp->info); |
150 | 599 |
free(tmp->label); |
64 | 600 |
free(tmp); |
601 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
602 |
p->next = j; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
603 |
p->next->next = 0; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
604 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
605 |
return; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
606 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
607 |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
608 |
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
|
609 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
610 |
struct Job *p; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
611 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
612 |
p = findjob(jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
613 |
if (p == 0) |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
614 |
return 0; |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
615 |
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
|
616 |
return 1; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
617 |
return 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
618 |
} |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
246
diff
changeset
|
619 |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
620 |
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
|
621 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
622 |
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
|
623 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
624 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
625 |
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
|
626 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
627 |
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
|
628 |
} |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
629 |
|
333
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
630 |
static int in_notify_list(int jobid) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
631 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
632 |
struct Notify *n, *tmp; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
633 |
|
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
634 |
n = first_notify; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
635 |
while (n != 0) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
636 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
637 |
tmp = n; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
638 |
n = n->next; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
639 |
if (tmp->jobid == jobid) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
640 |
return 1; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
641 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
642 |
return 0; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
643 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
644 |
|
218 | 645 |
void job_finished(const struct Result *result, int jobid) |
8 | 646 |
{ |
218 | 647 |
struct Job *p; |
648 |
||
649 |
if (busy_slots <= 0) |
|
650 |
error("Wrong state in the server. busy_slots = %i instead of greater than 0", busy_slots); |
|
8 | 651 |
|
218 | 652 |
p = findjob(jobid); |
653 |
if (p == 0) |
|
654 |
error("on jobid %i finished, it doesn't exist", jobid); |
|
8 | 655 |
|
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
|
656 |
/* 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
|
657 |
* 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
|
658 |
* 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
|
659 |
if (p->state == RUNNING) |
316
7ce3aeaf73b5
Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
660 |
busy_slots = busy_slots - p->num_slots; |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
661 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
662 |
/* Mark state */ |
156 | 663 |
if (result->skipped) |
218 | 664 |
p->state = SKIPPED; |
156 | 665 |
else |
218 | 666 |
p->state = FINISHED; |
667 |
p->result = *result; |
|
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
668 |
last_finished_jobid = p->jobid; |
218 | 669 |
notify_errorlevel(p); |
670 |
pinfo_set_end_time(&p->info); |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
671 |
|
246
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
672 |
if (p->result.died_by_signal) |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
673 |
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
|
674 |
else |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
675 |
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
|
676 |
|
218 | 677 |
/* Find the pointing node, to |
678 |
* update it removing the finished job. */ |
|
679 |
{ |
|
680 |
struct Job **jpointer = 0; |
|
681 |
struct Job *newfirst = p->next; |
|
682 |
if (firstjob == p) |
|
683 |
jpointer = &firstjob; |
|
684 |
else |
|
685 |
{ |
|
686 |
struct Job *p2; |
|
687 |
p2 = firstjob; |
|
688 |
while(p2 != 0) |
|
689 |
{ |
|
690 |
if (p2->next == p) |
|
691 |
{ |
|
692 |
jpointer = &(p2->next); |
|
693 |
break; |
|
694 |
} |
|
695 |
p2 = p2->next; |
|
696 |
} |
|
697 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
698 |
|
333
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
699 |
/* Add it to the finished queue (maybe temporarily) */ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
700 |
if (p->should_keep_finished || in_notify_list(p->jobid)) |
218 | 701 |
new_finished_job(p); |
8 | 702 |
|
218 | 703 |
/* Remove it from the run queue */ |
704 |
if (jpointer == 0) |
|
705 |
error("Cannot remove a finished job from the " |
|
706 |
"queue list (jobid=%i)", p->jobid); |
|
707 |
||
708 |
*jpointer = newfirst; |
|
709 |
} |
|
8 | 710 |
} |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
711 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
712 |
void s_clear_finished() |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
713 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
714 |
struct Job *p; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
715 |
|
22 | 716 |
if (first_finished_job == 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
717 |
return; |
22 | 718 |
|
719 |
p = first_finished_job; |
|
720 |
first_finished_job = 0; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
721 |
|
64 | 722 |
while (p != 0) |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
723 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
724 |
struct Job *tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
725 |
tmp = p->next; |
22 | 726 |
free(p->command); |
727 |
free(p->output_filename); |
|
148 | 728 |
pinfo_free(&p->info); |
150 | 729 |
free(p->label); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
730 |
free(p); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
731 |
p = tmp; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
732 |
} |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
733 |
} |
22 | 734 |
|
35 | 735 |
void s_process_runjob_ok(int jobid, char *oname, int pid) |
22 | 736 |
{ |
737 |
struct Job *p; |
|
738 |
p = findjob(jobid); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
739 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
740 |
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
|
741 |
if (p->state != RUNNING) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
742 |
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
|
743 |
p->state); |
22 | 744 |
|
35 | 745 |
p->pid = pid; |
22 | 746 |
p->output_filename = oname; |
146 | 747 |
pinfo_set_start_time(&p->info); |
748 |
} |
|
749 |
||
218 | 750 |
void s_send_runjob(int s, int jobid) |
751 |
{ |
|
752 |
struct msg m; |
|
753 |
struct Job *p; |
|
754 |
||
755 |
p = findjob(jobid); |
|
756 |
if (p == 0) |
|
757 |
error("Job %i was expected to run", jobid); |
|
758 |
||
759 |
||
760 |
m.type = RUNJOB; |
|
761 |
||
762 |
/* TODO |
|
259 | 763 |
* We should make the dependencies update the jobids they're do_depending on. |
218 | 764 |
* Then, on finish, these could set the errorlevel to send to its dependency childs. |
765 |
* We cannot consider that the jobs will leave traces in the finished job list (-nf?) . */ |
|
766 |
||
767 |
m.u.last_errorlevel = p->dependency_errorlevel; |
|
768 |
||
769 |
send_msg(s, &m); |
|
770 |
} |
|
771 |
||
146 | 772 |
void s_job_info(int s, int jobid) |
773 |
{ |
|
774 |
struct Job *p = 0; |
|
775 |
struct msg m; |
|
776 |
||
777 |
if (jobid == -1) |
|
778 |
{ |
|
779 |
/* This means that we want the job info of the running task, or that |
|
780 |
* of the last job run */ |
|
218 | 781 |
if (busy_slots > 0) |
146 | 782 |
{ |
783 |
p = firstjob; |
|
784 |
if (p == 0) |
|
785 |
error("Internal state WAITING, but job not run." |
|
786 |
"firstjob = %x", firstjob); |
|
787 |
} |
|
788 |
else |
|
789 |
{ |
|
790 |
p = first_finished_job; |
|
791 |
if (p == 0) |
|
792 |
{ |
|
793 |
send_list_line(s, "No jobs.\n"); |
|
794 |
return; |
|
795 |
} |
|
796 |
while(p->next != 0) |
|
797 |
p = p->next; |
|
798 |
} |
|
799 |
} else |
|
800 |
{ |
|
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
|
801 |
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
|
802 |
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
|
803 |
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
|
804 |
|
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
805 |
/* 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
|
806 |
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
|
807 |
{ |
b1618fe033aa
Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents:
153
diff
changeset
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
} |
146 | 812 |
} |
813 |
||
814 |
if (p == 0) |
|
815 |
{ |
|
816 |
char tmp[50]; |
|
817 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
|
818 |
send_list_line(s, tmp); |
|
819 |
return; |
|
820 |
} |
|
821 |
||
822 |
m.type = INFO_DATA; |
|
823 |
send_msg(s, &m); |
|
824 |
pinfo_dump(&p->info, s); |
|
317
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
825 |
fd_nprintf(s, 100, "Command: "); |
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
826 |
if (p->depend_on != -1) |
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
827 |
fd_nprintf(s, 100, "[%i]&& ", p->depend_on); |
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
|
828 |
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
|
829 |
fd_nprintf(s, 100, "\n"); |
317
290b5aa53061
Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents:
316
diff
changeset
|
830 |
fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots); |
146 | 831 |
fd_nprintf(s, 100, "Enqueue time: %s", |
832 |
ctime(&p->info.enqueue_time.tv_sec)); |
|
833 |
if (p->state == RUNNING) |
|
834 |
{ |
|
835 |
fd_nprintf(s, 100, "Start time: %s", |
|
836 |
ctime(&p->info.start_time.tv_sec)); |
|
837 |
fd_nprintf(s, 100, "Time running: %fs\n", |
|
838 |
pinfo_time_until_now(&p->info)); |
|
839 |
} else if (p->state == FINISHED) |
|
840 |
{ |
|
841 |
fd_nprintf(s, 100, "Start time: %s", |
|
842 |
ctime(&p->info.start_time.tv_sec)); |
|
843 |
fd_nprintf(s, 100, "End time: %s", |
|
844 |
ctime(&p->info.end_time.tv_sec)); |
|
845 |
fd_nprintf(s, 100, "Time run: %fs\n", |
|
846 |
pinfo_time_run(&p->info)); |
|
847 |
} |
|
22 | 848 |
} |
32 | 849 |
|
850 |
void s_send_output(int s, int jobid) |
|
851 |
{ |
|
852 |
struct Job *p = 0; |
|
853 |
struct msg m; |
|
854 |
||
855 |
if (jobid == -1) |
|
856 |
{ |
|
146 | 857 |
/* This means that we want the output info of the running task, or that |
32 | 858 |
* of the last job run */ |
218 | 859 |
if (busy_slots > 0) |
32 | 860 |
{ |
861 |
p = firstjob; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
862 |
if (p == 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
863 |
error("Internal state WAITING, but job not run." |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
864 |
"firstjob = %x", firstjob); |
32 | 865 |
} |
866 |
else |
|
867 |
{ |
|
868 |
p = first_finished_job; |
|
869 |
if (p == 0) |
|
870 |
{ |
|
871 |
send_list_line(s, "No jobs.\n"); |
|
872 |
return; |
|
873 |
} |
|
874 |
while(p->next != 0) |
|
875 |
p = p->next; |
|
876 |
} |
|
877 |
} else |
|
878 |
{ |
|
218 | 879 |
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
|
880 |
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
|
881 |
&& p->state != FINISHED |
6c2583ea71eb
Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents:
224
diff
changeset
|
882 |
&& p->state != SKIPPED) |
218 | 883 |
p = 0; |
32 | 884 |
} |
885 |
||
886 |
if (p == 0) |
|
887 |
{ |
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
892 |
sprintf(tmp, "Job %i not finished or not running.\n", jobid); |
32 | 893 |
send_list_line(s, tmp); |
894 |
return; |
|
895 |
} |
|
896 |
||
157 | 897 |
if (p->state == SKIPPED) |
156 | 898 |
{ |
899 |
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
|
900 |
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
|
901 |
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
|
902 |
|
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
903 |
else |
bca29e2a1a86
Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents:
190
diff
changeset
|
904 |
sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid); |
156 | 905 |
send_list_line(s, tmp); |
906 |
return; |
|
907 |
} |
|
908 |
||
32 | 909 |
m.type = ANSWER_OUTPUT; |
910 |
m.u.output.store_output = p->store_output; |
|
35 | 911 |
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
|
912 |
if (m.u.output.store_output && p->output_filename) |
153 | 913 |
m.u.output.ofilename_size = strlen(p->output_filename) + 1; |
914 |
else |
|
915 |
m.u.output.ofilename_size = 0; |
|
32 | 916 |
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
|
917 |
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
|
918 |
send_bytes(s, p->output_filename, m.u.output.ofilename_size); |
32 | 919 |
} |
41 | 920 |
|
218 | 921 |
void notify_errorlevel(struct Job *p) |
922 |
{ |
|
259 | 923 |
int i; |
924 |
||
221
fed80bc73128
Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents:
219
diff
changeset
|
925 |
last_errorlevel = p->result.errorlevel; |
259 | 926 |
|
927 |
for(i = 0; i < p->notify_errorlevel_to_size; ++i) |
|
218 | 928 |
{ |
929 |
struct Job *notified; |
|
259 | 930 |
notified = get_job(p->notify_errorlevel_to[i]); |
218 | 931 |
if (notified) |
932 |
{ |
|
933 |
notified->dependency_errorlevel = p->result.errorlevel; |
|
934 |
} |
|
935 |
} |
|
936 |
} |
|
937 |
||
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
938 |
/* jobid is input/output. If the input is -1, it's changed to the jobid |
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
939 |
* removed */ |
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
940 |
int s_remove_job(int s, int *jobid) |
41 | 941 |
{ |
942 |
struct Job *p = 0; |
|
943 |
struct msg m; |
|
944 |
struct Job *before_p = 0; |
|
945 |
||
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
946 |
if (*jobid == -1) |
41 | 947 |
{ |
948 |
/* Find the last job added */ |
|
949 |
p = firstjob; |
|
950 |
if (p != 0) |
|
951 |
{ |
|
952 |
while (p->next != 0) |
|
953 |
{ |
|
954 |
before_p = p; |
|
955 |
p = p->next; |
|
956 |
} |
|
180 | 957 |
} else |
958 |
{ |
|
959 |
/* last 'finished' */ |
|
960 |
p = first_finished_job; |
|
190 | 961 |
if (p) |
180 | 962 |
{ |
190 | 963 |
while (p->next != 0) |
964 |
{ |
|
965 |
before_p = p; |
|
966 |
p = p->next; |
|
967 |
} |
|
180 | 968 |
} |
41 | 969 |
} |
970 |
} |
|
971 |
else |
|
972 |
{ |
|
973 |
p = firstjob; |
|
974 |
if (p != 0) |
|
975 |
{ |
|
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
976 |
while (p->next != 0 && p->jobid != *jobid) |
41 | 977 |
{ |
978 |
before_p = p; |
|
979 |
p = p->next; |
|
980 |
} |
|
981 |
} |
|
180 | 982 |
|
983 |
/* If not found, look in the 'finished' list */ |
|
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
984 |
if (p == 0 || p->jobid != *jobid) |
180 | 985 |
{ |
986 |
p = first_finished_job; |
|
987 |
if (p != 0) |
|
988 |
{ |
|
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
989 |
while (p->next != 0 && p->jobid != *jobid) |
180 | 990 |
{ |
991 |
before_p = p; |
|
992 |
p = p->next; |
|
993 |
} |
|
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
994 |
if (p->jobid != *jobid) |
227
3570252beade
Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents:
226
diff
changeset
|
995 |
p = 0; |
180 | 996 |
} |
997 |
} |
|
41 | 998 |
} |
999 |
||
227
3570252beade
Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents:
226
diff
changeset
|
1000 |
if (p == 0 || p->state == RUNNING || p == firstjob) |
41 | 1001 |
{ |
1002 |
char tmp[50]; |
|
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
1003 |
if (*jobid == -1) |
44 | 1004 |
sprintf(tmp, "The last job cannot be removed.\n"); |
41 | 1005 |
else |
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
1006 |
sprintf(tmp, "The job %i cannot be removed.\n", *jobid); |
41 | 1007 |
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
|
1008 |
return 0; |
41 | 1009 |
} |
1010 |
||
334
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
1011 |
/* Return the jobid found */ |
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
1012 |
*jobid = p->jobid; |
e9e212846a89
Fixing a process left, when "-r" is used without jobid.
viric
parents:
333
diff
changeset
|
1013 |
|
178
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1014 |
/* Tricks for the check_notify_list */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1015 |
p->state = FINISHED; |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1016 |
p->result.errorlevel = -1; |
218 | 1017 |
notify_errorlevel(p); |
1018 |
||
178
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1019 |
/* Notify the clients in wait_job */ |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1020 |
check_notify_list(m.u.jobid); |
5b64d66a8d89
Fixed awaking the wait_job clients on job removal.
viric@llimona
parents:
176
diff
changeset
|
1021 |
|
180 | 1022 |
/* Update the list pointers */ |
1023 |
if (p == first_finished_job) |
|
1024 |
first_finished_job = p->next; |
|
1025 |
else |
|
1026 |
before_p->next = p->next; |
|
1027 |
||
259 | 1028 |
free(p->notify_errorlevel_to); |
64 | 1029 |
free(p->command); |
1030 |
free(p->output_filename); |
|
146 | 1031 |
pinfo_free(&p->info); |
150 | 1032 |
free(p->label); |
41 | 1033 |
free(p); |
180 | 1034 |
|
41 | 1035 |
m.type = REMOVEJOB_OK; |
1036 |
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
|
1037 |
return 1; |
41 | 1038 |
} |
42 | 1039 |
|
1040 |
static void add_to_notify_list(int s, int jobid) |
|
1041 |
{ |
|
1042 |
struct Notify *n; |
|
1043 |
struct Notify *new; |
|
1044 |
||
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1045 |
new = (struct Notify *) malloc(sizeof(*new)); |
42 | 1046 |
|
1047 |
new->socket = s; |
|
1048 |
new->jobid = jobid; |
|
1049 |
new->next = 0; |
|
1050 |
||
1051 |
n = first_notify; |
|
1052 |
if (n == 0) |
|
1053 |
{ |
|
1054 |
first_notify = new; |
|
1055 |
return; |
|
1056 |
} |
|
1057 |
||
1058 |
while(n->next != 0) |
|
1059 |
n = n->next; |
|
1060 |
||
1061 |
n->next = new; |
|
1062 |
} |
|
1063 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1064 |
static void send_waitjob_ok(int s, int errorlevel) |
42 | 1065 |
{ |
1066 |
struct msg m; |
|
1067 |
||
1068 |
m.type = WAITJOB_OK; |
|
112 | 1069 |
m.u.result.errorlevel = errorlevel; |
42 | 1070 |
send_msg(s, &m); |
1071 |
} |
|
1072 |
||
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1073 |
static struct Job * |
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1074 |
get_job(int jobid) |
42 | 1075 |
{ |
1076 |
struct Job *j; |
|
1077 |
||
1078 |
j = findjob(jobid); |
|
1079 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1080 |
return j; |
42 | 1081 |
|
1082 |
j = find_finished_job(jobid); |
|
1083 |
||
1084 |
if (j != NULL) |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1085 |
return j; |
42 | 1086 |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1087 |
return 0; |
42 | 1088 |
} |
1089 |
||
1090 |
/* Don't complain, if the socket doesn't exist */ |
|
1091 |
void s_remove_notification(int s) |
|
1092 |
{ |
|
1093 |
struct Notify *n; |
|
1094 |
struct Notify *previous; |
|
1095 |
n = first_notify; |
|
1096 |
while (n != 0 && n->socket != s) |
|
1097 |
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
|
1098 |
if (n == 0 || n->socket != s) |
42 | 1099 |
return; |
1100 |
||
1101 |
/* Remove the notification */ |
|
1102 |
previous = first_notify; |
|
1103 |
if (n == previous) |
|
1104 |
{ |
|
254
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1105 |
first_notify = n->next; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1106 |
free(n); |
42 | 1107 |
return; |
1108 |
} |
|
1109 |
||
1110 |
/* if not the first... */ |
|
1111 |
while(previous->next != n) |
|
1112 |
previous = previous->next; |
|
1113 |
||
1114 |
previous->next = n->next; |
|
1115 |
free(n); |
|
1116 |
} |
|
1117 |
||
333
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1118 |
static void destroy_finished_job(struct Job *j) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1119 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1120 |
if (j == first_finished_job) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1121 |
first_finished_job = j->next; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1122 |
else |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1123 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1124 |
struct Job *i; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1125 |
for(i = first_finished_job; i != 0; ++i) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1126 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1127 |
if (i->next == j) |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1128 |
{ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1129 |
i->next = j->next; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1130 |
break; |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1131 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1132 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1133 |
if (i == 0) { |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1134 |
error("Cannot destroy the expected job %i", j->jobid); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1135 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1136 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1137 |
|
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1138 |
free(j->notify_errorlevel_to); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1139 |
free(j->command); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1140 |
free(j->output_filename); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1141 |
pinfo_free(&j->info); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1142 |
free(j->label); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1143 |
free(j); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1144 |
} |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1145 |
|
42 | 1146 |
/* This is called when a job finishes */ |
1147 |
void check_notify_list(int jobid) |
|
1148 |
{ |
|
206
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1149 |
struct Notify *n, *tmp; |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
1150 |
struct Job *j; |
42 | 1151 |
|
1152 |
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
|
1153 |
while (n != 0) |
42 | 1154 |
{ |
206
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1155 |
tmp = n; |
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1156 |
n = n->next; |
7acb031b40b8
Better managing of notifications on job finish.
viric@llimona
parents:
198
diff
changeset
|
1157 |
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
|
1158 |
{ |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1159 |
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
|
1160 |
/* 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
|
1161 |
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
|
1162 |
{ |
209
507bd37ab1d3
Bug resolving a pointer when notifying job_ends.
lbatlle@npdl268.bpo.hp.com
parents:
206
diff
changeset
|
1163 |
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
|
1164 |
/* 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
|
1165 |
* 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
|
1166 |
* 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
|
1167 |
* 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
|
1168 |
s_remove_notification(tmp->socket); |
333
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1169 |
|
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1170 |
/* Remove the jobs that were temporarily in the finished list, |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1171 |
* just for their notifiers. */ |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1172 |
if (!in_notify_list(jobid) && !j->should_keep_finished) { |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1173 |
destroy_finished_job(j); |
4a2f6bdca101
Trying to fix the segfault reported by Alexander Inyukhin in the mailing list:
viric <viriketo@gmail.com>
parents:
317
diff
changeset
|
1174 |
} |
195
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1175 |
} |
cbe64953fa1f
Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents:
190
diff
changeset
|
1176 |
} |
42 | 1177 |
} |
1178 |
} |
|
1179 |
||
1180 |
void s_wait_job(int s, int jobid) |
|
1181 |
{ |
|
1182 |
struct Job *p = 0; |
|
1183 |
||
1184 |
if (jobid == -1) |
|
1185 |
{ |
|
1186 |
/* Find the last job added */ |
|
1187 |
p = firstjob; |
|
1188 |
||
1189 |
if (p != 0) |
|
1190 |
while (p->next != 0) |
|
1191 |
p = p->next; |
|
1192 |
||
1193 |
/* Look in finished jobs if needed */ |
|
1194 |
if (p == 0) |
|
1195 |
{ |
|
1196 |
p = first_finished_job; |
|
1197 |
if (p != 0) |
|
1198 |
while (p->next != 0) |
|
1199 |
p = p->next; |
|
1200 |
} |
|
1201 |
} |
|
1202 |
else |
|
1203 |
{ |
|
1204 |
p = firstjob; |
|
1205 |
while (p != 0 && p->jobid != jobid) |
|
1206 |
p = p->next; |
|
1207 |
||
1208 |
/* Look in finished jobs if needed */ |
|
1209 |
if (p == 0) |
|
1210 |
{ |
|
1211 |
p = first_finished_job; |
|
1212 |
while (p != 0 && p->jobid != jobid) |
|
1213 |
p = p->next; |
|
1214 |
} |
|
1215 |
} |
|
1216 |
||
1217 |
if (p == 0) |
|
1218 |
{ |
|
1219 |
char tmp[50]; |
|
1220 |
if (jobid == -1) |
|
44 | 1221 |
sprintf(tmp, "The last job cannot be waited.\n"); |
42 | 1222 |
else |
1223 |
sprintf(tmp, "The job %i cannot be waited.\n", jobid); |
|
1224 |
send_list_line(s, tmp); |
|
1225 |
return; |
|
1226 |
} |
|
1227 |
||
166
8c19a66b5407
Fixing a bug on wait_job on skipped jobs. Moving vnumber to 0.5
viric@vicerveza
parents:
157
diff
changeset
|
1228 |
if (p->state == FINISHED || p->state == SKIPPED) |
42 | 1229 |
{ |
112 | 1230 |
send_waitjob_ok(s, p->result.errorlevel); |
42 | 1231 |
} |
1232 |
else |
|
1233 |
add_to_notify_list(s, p->jobid); |
|
1234 |
} |
|
53 | 1235 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1236 |
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
|
1237 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1238 |
struct Job *p = 0; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1239 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1240 |
/* 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
|
1241 |
* 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
|
1242 |
if (jobid == -1) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1243 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1244 |
/* 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
|
1245 |
* of the last job run */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1246 |
if (busy_slots > 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1247 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1248 |
p = firstjob; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1249 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1250 |
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
|
1251 |
"firstjob = %x", firstjob); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1252 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1253 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1254 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1255 |
p = first_finished_job; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1256 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1257 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1258 |
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
|
1259 |
return; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1260 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1261 |
while(p->next != 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1262 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1263 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1264 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1265 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1266 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1267 |
p = firstjob; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1268 |
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
|
1269 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1270 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1271 |
/* 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
|
1272 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1273 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1274 |
p = first_finished_job; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1275 |
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
|
1276 |
p = p->next; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1277 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1278 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1279 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1280 |
if (p == 0) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1281 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1282 |
char tmp[50]; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1283 |
if (jobid == -1) |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1284 |
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
|
1285 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1286 |
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
|
1287 |
send_list_line(s, tmp); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1288 |
return; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1289 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1290 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1291 |
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
|
1292 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1293 |
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
|
1294 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1295 |
else |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1296 |
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
|
1297 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
225
diff
changeset
|
1298 |
|
219 | 1299 |
void s_set_max_slots(int new_max_slots) |
1300 |
{ |
|
1301 |
if (new_max_slots > 0) |
|
1302 |
max_slots = new_max_slots; |
|
1303 |
else |
|
1304 |
warning("Received new_max_slots=%i", new_max_slots); |
|
1305 |
} |
|
1306 |
||
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1307 |
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
|
1308 |
{ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1309 |
struct msg m; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1310 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1311 |
/* Message */ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1312 |
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
|
1313 |
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
|
1314 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1315 |
send_msg(s, &m); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1316 |
} |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
1317 |
|
53 | 1318 |
void s_move_urgent(int s, int jobid) |
1319 |
{ |
|
1320 |
struct Job *p = 0; |
|
1321 |
struct Job *tmp1; |
|
1322 |
||
1323 |
if (jobid == -1) |
|
1324 |
{ |
|
1325 |
/* Find the last job added */ |
|
1326 |
p = firstjob; |
|
1327 |
||
1328 |
if (p != 0) |
|
1329 |
while (p->next != 0) |
|
1330 |
p = p->next; |
|
1331 |
} |
|
1332 |
else |
|
1333 |
{ |
|
1334 |
p = firstjob; |
|
1335 |
while (p != 0 && p->jobid != jobid) |
|
1336 |
p = p->next; |
|
1337 |
} |
|
1338 |
||
1339 |
if (p == 0 || firstjob->next == 0) |
|
1340 |
{ |
|
1341 |
char tmp[50]; |
|
1342 |
if (jobid == -1) |
|
1343 |
sprintf(tmp, "The last job cannot be urged.\n"); |
|
1344 |
else |
|
1345 |
sprintf(tmp, "The job %i cannot be urged.\n", jobid); |
|
1346 |
send_list_line(s, tmp); |
|
1347 |
return; |
|
1348 |
} |
|
1349 |
||
1350 |
/* Interchange the pointers */ |
|
1351 |
tmp1 = find_previous_job(p); |
|
1352 |
tmp1->next = p->next; |
|
1353 |
p->next = firstjob->next; |
|
1354 |
firstjob->next = p; |
|
1355 |
||
1356 |
||
1357 |
send_urgent_ok(s); |
|
1358 |
} |
|
63 | 1359 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1360 |
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
|
1361 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1362 |
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
|
1363 |
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
|
1364 |
struct Job *tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1365 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1366 |
p1 = findjob(jobid1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1367 |
p2 = findjob(jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1368 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1369 |
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
|
1370 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1371 |
char prev[60]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1372 |
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
|
1373 |
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
|
1374 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1375 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1376 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1377 |
/* Interchange the pointers */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1378 |
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
|
1379 |
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
|
1380 |
prev1->next = p2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1381 |
prev2->next = p1; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1382 |
tmp = p1->next; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1383 |
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
|
1384 |
p2->next = tmp; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1385 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1386 |
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
|
1387 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
64
diff
changeset
|
1388 |
|
63 | 1389 |
static void send_state(int s, enum Jobstate state) |
1390 |
{ |
|
1391 |
struct msg m; |
|
1392 |
||
1393 |
m.type = ANSWER_STATE; |
|
1394 |
m.u.state = state; |
|
1395 |
||
1396 |
send_msg(s, &m); |
|
1397 |
} |
|
1398 |
||
1399 |
void s_send_state(int s, int jobid) |
|
1400 |
{ |
|
1401 |
struct Job *p = 0; |
|
1402 |
||
1403 |
if (jobid == -1) |
|
1404 |
{ |
|
1405 |
/* Find the last job added */ |
|
1406 |
p = firstjob; |
|
1407 |
||
1408 |
if (p != 0) |
|
1409 |
while (p->next != 0) |
|
1410 |
p = p->next; |
|
1411 |
||
1412 |
/* Look in finished jobs if needed */ |
|
1413 |
if (p == 0) |
|
1414 |
{ |
|
1415 |
p = first_finished_job; |
|
1416 |
if (p != 0) |
|
1417 |
while (p->next != 0) |
|
1418 |
p = p->next; |
|
1419 |
} |
|
1420 |
||
1421 |
} |
|
1422 |
else |
|
1423 |
{ |
|
1424 |
p = get_job(jobid); |
|
1425 |
} |
|
1426 |
||
1427 |
if (p == 0) |
|
1428 |
{ |
|
1429 |
char tmp[50]; |
|
1430 |
if (jobid == -1) |
|
1431 |
sprintf(tmp, "The last job cannot be stated.\n"); |
|
1432 |
else |
|
1433 |
sprintf(tmp, "The job %i cannot be stated.\n", jobid); |
|
1434 |
send_list_line(s, tmp); |
|
1435 |
return; |
|
1436 |
} |
|
1437 |
||
1438 |
/* Interchange the pointers */ |
|
1439 |
send_state(s, p->state); |
|
1440 |
} |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1441 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1442 |
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
|
1443 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1444 |
fprintf(out, " new_job\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1445 |
fprintf(out, " jobid %i\n", p->jobid); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1446 |
fprintf(out, " command \"%s\"\n", p->command); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1447 |
fprintf(out, " state %s\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1448 |
jstate2string(p->state)); |
112 | 1449 |
fprintf(out, " result.errorlevel %i\n", p->result.errorlevel); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1450 |
fprintf(out, " output_filename \"%s\"\n", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1451 |
p->output_filename ? p->output_filename : "NULL"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1452 |
fprintf(out, " store_output %i\n", p->store_output); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1453 |
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
|
1454 |
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
|
1455 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1456 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1457 |
void dump_jobs_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1458 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1459 |
const struct Job *p; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1460 |
|
104 | 1461 |
fprintf(out, "New_jobs\n"); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1462 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1463 |
p = firstjob; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1464 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1465 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1466 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1467 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1468 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1469 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1470 |
p = first_finished_job; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1471 |
while (p != 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1472 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1473 |
dump_job_struct(out, p); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1474 |
p = p->next; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1475 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
1476 |
} |
120 | 1477 |
|
254
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1478 |
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
|
1479 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1480 |
fprintf(out, " notify\n"); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1481 |
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
|
1482 |
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
|
1483 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1484 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1485 |
void dump_notifies_struct(FILE *out) |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1486 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1487 |
const struct Notify *n; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1488 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1489 |
fprintf(out, "New_notifies\n"); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1490 |
|
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1491 |
n = first_notify; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1492 |
while (n != 0) |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1493 |
{ |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1494 |
dump_notify_struct(out, n); |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1495 |
n = n->next; |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1496 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1497 |
} |
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
1498 |
|
120 | 1499 |
void joblist_dump(int fd) |
1500 |
{ |
|
1501 |
struct Job *p; |
|
1502 |
char *buffer; |
|
1503 |
||
1504 |
buffer = joblistdump_headers(); |
|
1505 |
write(fd,buffer, strlen(buffer)); |
|
1506 |
free(buffer); |
|
1507 |
||
1508 |
/* We reuse the headers from the list */ |
|
1509 |
buffer = joblist_headers(); |
|
1510 |
write(fd, "# ", 2); |
|
1511 |
write(fd, buffer, strlen(buffer)); |
|
1512 |
||
1513 |
/* Show Finished jobs */ |
|
1514 |
p = first_finished_job; |
|
1515 |
while(p != 0) |
|
1516 |
{ |
|
1517 |
buffer = joblist_line(p); |
|
1518 |
write(fd, "# ", 2); |
|
1519 |
write(fd,buffer, strlen(buffer)); |
|
1520 |
free(buffer); |
|
1521 |
p = p->next; |
|
1522 |
} |
|
1523 |
||
1524 |
write(fd, "\n", 1); |
|
1525 |
||
1526 |
/* Show Queued or Running jobs */ |
|
1527 |
p = firstjob; |
|
1528 |
while(p != 0) |
|
1529 |
{ |
|
1530 |
buffer = joblistdump_torun(p); |
|
1531 |
write(fd,buffer,strlen(buffer)); |
|
1532 |
free(buffer); |
|
1533 |
p = p->next; |
|
1534 |
} |
|
1535 |
} |