author | viric <viriketo@gmail.com> |
Mon, 18 Jul 2011 22:48:54 +0200 | |
branch | queuelimit |
changeset 293 | bb87d5e7c466 |
parent 286 | f648473fd056 |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
267 | 3 |
Copyright (C) 2007-2009 LluĂs Batlle i Rossell |
49 | 4 |
|
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
1 | 7 |
#include <sys/types.h> |
8 |
#include <sys/socket.h> |
|
44 | 9 |
#include <sys/select.h> |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
10 |
#ifdef linux |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
11 |
#include <sys/time.h> |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
12 |
#endif |
94 | 13 |
#include <sys/resource.h> |
1 | 14 |
#include <sys/un.h> |
15 |
#include <errno.h> |
|
3 | 16 |
#include <string.h> |
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
17 |
#include <stdlib.h> |
44 | 18 |
#include <unistd.h> |
94 | 19 |
#include <limits.h> |
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
20 |
#include <signal.h> |
120 | 21 |
#include <fcntl.h> |
263 | 22 |
#include <libgen.h> |
1 | 23 |
|
24 |
#include <stdio.h> |
|
25 |
||
3 | 26 |
#include "main.h" |
1 | 27 |
|
28 |
enum |
|
29 |
{ |
|
64 | 30 |
MAXCONN=1000 |
1 | 31 |
}; |
32 |
||
33 |
enum Break |
|
34 |
{ |
|
2 | 35 |
BREAK, |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
36 |
NOBREAK, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
37 |
CLOSE |
1 | 38 |
}; |
39 |
||
3 | 40 |
/* Prototypes */ |
41 |
static void server_loop(int ls); |
|
42 |
static enum Break |
|
43 |
client_read(int index); |
|
44 |
static void end_server(int ls); |
|
8 | 45 |
static void s_newjob_ok(int index); |
218 | 46 |
static void s_runjob(int jobid, int index); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
47 |
static void clean_after_client_disappeared(int socket, int index); |
3 | 48 |
|
49 |
struct Client_conn |
|
50 |
{ |
|
51 |
int socket; |
|
52 |
int hasjob; |
|
53 |
int jobid; |
|
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
54 |
int waits_enqueuing; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
55 |
struct msg enqueue_msg; |
3 | 56 |
}; |
57 |
||
58 |
/* Globals */ |
|
59 |
static struct Client_conn client_cs[MAXCONN]; |
|
60 |
static int nconnections; |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
61 |
static char *path; |
94 | 62 |
static int max_descriptors; |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
63 |
static int max_queued; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
64 |
static int nqueued; |
94 | 65 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
66 |
static void s_send_version(int s) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
67 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
68 |
struct msg m; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
69 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
70 |
m.type = VERSION; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
71 |
m.u.version = PROTOCOL_VERSION; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
72 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
73 |
send_msg(s, &m); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
74 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
75 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
76 |
static void sigterm_handler(int n) |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
77 |
{ |
120 | 78 |
const char *dumpfilename; |
79 |
int fd; |
|
80 |
||
81 |
/* Dump the job list if we should to */ |
|
82 |
dumpfilename = getenv("TS_SAVELIST"); |
|
83 |
if (dumpfilename != NULL) |
|
84 |
{ |
|
85 |
fd = open(dumpfilename, O_WRONLY | O_APPEND | O_CREAT, 0600); |
|
86 |
if (fd != -1) |
|
87 |
{ |
|
88 |
joblist_dump(fd); |
|
89 |
close(fd); |
|
90 |
} else |
|
91 |
warning("The TS_SAVELIST file \"%s\" cannot be opened", |
|
92 |
dumpfilename); |
|
93 |
} |
|
94 |
||
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
95 |
/* path will be initialized for sure, before installing the handler */ |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
96 |
unlink(path); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
97 |
exit(1); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
98 |
} |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
99 |
|
239
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
100 |
static void set_default_maxslots() |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
101 |
{ |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
102 |
char *str; |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
103 |
|
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
104 |
str = getenv("TS_SLOTS"); |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
105 |
if (str != NULL) |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
106 |
{ |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
107 |
int slots; |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
108 |
slots = abs(atoi(str)); |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
109 |
s_set_max_slots(slots); |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
110 |
} |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
111 |
} |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
112 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
113 |
static void install_sigterm_handler() |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
114 |
{ |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
115 |
struct sigaction act; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
116 |
|
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
117 |
act.sa_handler = sigterm_handler; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
118 |
/* Reset the mask */ |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
119 |
memset(&act.sa_mask,0,sizeof(act.sa_mask)); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
120 |
act.sa_flags = 0; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
121 |
|
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
122 |
sigaction(SIGTERM, &act, NULL); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
123 |
} |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
124 |
|
94 | 125 |
static int get_max_descriptors() |
126 |
{ |
|
127 |
const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */ |
|
128 |
int max; |
|
129 |
struct rlimit rlim; |
|
130 |
int res; |
|
278 | 131 |
const char *str; |
94 | 132 |
|
133 |
max = MAXCONN; |
|
278 | 134 |
|
135 |
str = getenv("TS_MAXCONN"); |
|
136 |
if (str != NULL) |
|
137 |
{ |
|
138 |
int user_maxconn; |
|
139 |
user_maxconn = abs(atoi(str)); |
|
140 |
if (max > user_maxconn) |
|
141 |
max = user_maxconn; |
|
142 |
} |
|
143 |
||
94 | 144 |
if (max > FD_SETSIZE) |
278 | 145 |
max = FD_SETSIZE - MARGIN; |
94 | 146 |
|
147 |
/* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any |
|
148 |
* of them is POSIX compliant */ |
|
149 |
||
150 |
res = getrlimit(RLIMIT_NOFILE, &rlim); |
|
151 |
if (res != 0) |
|
152 |
warning("getrlimit for open files"); |
|
153 |
else |
|
154 |
{ |
|
155 |
if (max > rlim.rlim_cur) |
|
278 | 156 |
max = rlim.rlim_cur - MARGIN; |
94 | 157 |
} |
158 |
||
278 | 159 |
if (max < 1) |
94 | 160 |
error("Too few opened descriptors available"); |
161 |
||
278 | 162 |
return max; |
94 | 163 |
} |
1 | 164 |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
165 |
void server_main(int notify_fd, char *_path) |
1 | 166 |
{ |
44 | 167 |
int ls; |
2 | 168 |
struct sockaddr_un addr; |
169 |
int res; |
|
263 | 170 |
char *dirpath; |
1 | 171 |
|
104 | 172 |
process_type = SERVER; |
94 | 173 |
max_descriptors = get_max_descriptors(); |
174 |
||
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
175 |
/* Arbitrary number below the maximum of descriptors, |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
176 |
* to allow commands other than queuing. */ |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
177 |
max_queued = 2; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
178 |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
179 |
path = _path; |
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
180 |
|
263 | 181 |
/* Move the server to the socket directory */ |
182 |
dirpath = strdup(path); |
|
183 |
chdir(dirname(dirpath)); |
|
184 |
free(dirpath); |
|
185 |
||
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
186 |
/* superfluous */ |
3 | 187 |
nconnections = 0; |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
188 |
nqueued = 0; |
3 | 189 |
|
129
312083fb8899
Change PF_UNIX to AF_UNIX. According to socket(2), this is better.
viric@llimona
parents:
120
diff
changeset
|
190 |
ls = socket(AF_UNIX, SOCK_STREAM, 0); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
191 |
if(ls == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
192 |
error("cannot create the listen socket in the server"); |
1 | 193 |
|
2 | 194 |
addr.sun_family = AF_UNIX; |
195 |
strcpy(addr.sun_path, path); |
|
1 | 196 |
|
2 | 197 |
res = bind(ls, (struct sockaddr *) &addr, sizeof(addr)); |
198 |
if (res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
199 |
error("Error binding."); |
1 | 200 |
|
2 | 201 |
res = listen(ls, 0); |
202 |
if (res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
203 |
error("Error listening."); |
1 | 204 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
205 |
install_sigterm_handler(); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
206 |
|
239
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
207 |
set_default_maxslots(); |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
208 |
|
25 | 209 |
notify_parent(notify_fd); |
210 |
||
2 | 211 |
server_loop(ls); |
1 | 212 |
} |
213 |
||
8 | 214 |
static int get_conn_of_jobid(int jobid) |
215 |
{ |
|
216 |
int i; |
|
217 |
for(i=0; i< nconnections; ++i) |
|
218 |
if (client_cs[i].hasjob && client_cs[i].jobid == jobid) |
|
219 |
return i; |
|
220 |
return -1; |
|
221 |
} |
|
222 |
||
3 | 223 |
static void server_loop(int ls) |
1 | 224 |
{ |
2 | 225 |
fd_set readset; |
226 |
int i; |
|
227 |
int maxfd; |
|
228 |
int keep_loop = 1; |
|
8 | 229 |
int newjob; |
1 | 230 |
|
2 | 231 |
while (keep_loop) |
232 |
{ |
|
233 |
FD_ZERO(&readset); |
|
94 | 234 |
maxfd = 0; |
235 |
/* If we can accept more connections, go on. |
|
236 |
* Otherwise, the system block them (no accept will be done). */ |
|
237 |
if (nconnections < max_descriptors) |
|
238 |
{ |
|
239 |
FD_SET(ls,&readset); |
|
240 |
maxfd = ls; |
|
241 |
} |
|
2 | 242 |
for(i=0; i< nconnections; ++i) |
243 |
{ |
|
3 | 244 |
FD_SET(client_cs[i].socket, &readset); |
245 |
if (client_cs[i].socket > maxfd) |
|
246 |
maxfd = client_cs[i].socket; |
|
2 | 247 |
} |
248 |
select(maxfd + 1, &readset, NULL, NULL, NULL); |
|
249 |
if (FD_ISSET(ls,&readset)) |
|
250 |
{ |
|
251 |
int cs; |
|
252 |
cs = accept(ls, NULL, NULL); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
253 |
if (cs == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
254 |
error("Accepting from %i", ls); |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
255 |
client_cs[nconnections].hasjob = 0; |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
256 |
client_cs[nconnections].socket = cs; |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
257 |
client_cs[nconnections].waits_enqueuing = 0; |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
258 |
++nconnections; |
2 | 259 |
} |
260 |
for(i=0; i< nconnections; ++i) |
|
3 | 261 |
if (FD_ISSET(client_cs[i].socket, &readset)) |
2 | 262 |
{ |
263 |
enum Break b; |
|
3 | 264 |
b = client_read(i); |
2 | 265 |
/* Check if we should break */ |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
266 |
if (b == CLOSE) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
267 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
268 |
warning("Closing"); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
269 |
/* On unknown message, we close the client, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
270 |
or it may hang waiting for an answer */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
271 |
clean_after_client_disappeared(client_cs[i].socket, i); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
272 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
273 |
else if (b == BREAK) |
2 | 274 |
keep_loop = 0; |
275 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
276 |
/* This will return firstjob->jobid or -1 */ |
8 | 277 |
newjob = next_run_job(); |
278 |
if (newjob != -1) |
|
279 |
{ |
|
280 |
int conn; |
|
281 |
conn = get_conn_of_jobid(newjob); |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
282 |
/* This next marks the firstjob state to RUNNING */ |
218 | 283 |
s_mark_job_running(newjob); |
284 |
s_runjob(newjob, conn); |
|
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
285 |
|
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
286 |
if (nqueued < max_queued) |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
287 |
for(i=0; i< nconnections; ++i) |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
288 |
{ |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
289 |
if(client_cs[i].waits_enqueuing) |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
290 |
{ |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
291 |
client_cs[i].jobid = s_newjob( |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
292 |
client_cs[i].socket, |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
293 |
&client_cs[i].enqueue_msg); |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
294 |
client_cs[i].hasjob = 1; |
286
f648473fd056
Enabling a heavier msgdump. I still don't get what goes wrong.
viric <viriketo@gmail.com>
parents:
285
diff
changeset
|
295 |
client_cs[i].waits_enqueuing = 0; |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
296 |
s_newjob_ok(i); |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
297 |
++nqueued; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
298 |
} |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
299 |
} |
8 | 300 |
} |
2 | 301 |
} |
1 | 302 |
|
2 | 303 |
end_server(ls); |
1 | 304 |
} |
305 |
||
3 | 306 |
static void end_server(int ls) |
1 | 307 |
{ |
2 | 308 |
close(ls); |
309 |
unlink(path); |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
310 |
/* This comes from the parent, in the fork after server_main. |
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
311 |
* This is the last use of path in this process.*/ |
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
312 |
free(path); |
1 | 313 |
} |
314 |
||
3 | 315 |
static void remove_connection(int index) |
1 | 316 |
{ |
2 | 317 |
int i; |
3 | 318 |
|
319 |
if(client_cs[index].hasjob) |
|
2 | 320 |
{ |
3 | 321 |
s_removejob(client_cs[index].jobid); |
2 | 322 |
} |
3 | 323 |
|
324 |
for(i=index; i<(nconnections-1); ++i) |
|
325 |
{ |
|
326 |
memcpy(&client_cs[i], &client_cs[i+1], sizeof(client_cs[0])); |
|
327 |
} |
|
328 |
nconnections--; |
|
1 | 329 |
} |
330 |
||
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
331 |
static void |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
332 |
clean_after_client_disappeared(int socket, int index) |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
333 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
334 |
/* Act as if the job ended. */ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
335 |
int jobid = client_cs[index].jobid; |
256
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
336 |
if (client_cs[index].hasjob && job_is_running(jobid)) |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
337 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
338 |
struct Result r; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
339 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
340 |
r.errorlevel = -1; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
341 |
r.died_by_signal = 1; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
342 |
r.signal = SIGKILL; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
343 |
r.user_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
344 |
r.system_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
345 |
r.real_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
346 |
r.skipped = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
347 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
348 |
warning("JobID %i quit while running.", jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
349 |
job_finished(&r, jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
350 |
/* For the dependencies */ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
351 |
check_notify_list(jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
352 |
/* We don't want this connection to do anything |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
353 |
* more related to the jobid, secially on remove_connection |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
354 |
* when we receive the EOC. */ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
355 |
client_cs[index].hasjob = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
356 |
} |
256
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
357 |
else |
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
358 |
/* If it doesn't have a running job, |
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
359 |
* it may well be a notification */ |
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
360 |
s_remove_notification(socket); |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
361 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
362 |
close(socket); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
363 |
remove_connection(index); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
364 |
} |
3 | 365 |
|
366 |
static enum Break |
|
367 |
client_read(int index) |
|
1 | 368 |
{ |
3 | 369 |
struct msg m; |
2 | 370 |
int s; |
371 |
int res; |
|
1 | 372 |
|
3 | 373 |
s = client_cs[index].socket; |
1 | 374 |
|
2 | 375 |
/* Read the message */ |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
376 |
res = recv_msg(s, &m); |
8 | 377 |
if (res == -1) |
378 |
{ |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
379 |
warning("client recv failed"); |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
380 |
clean_after_client_disappeared(s, index); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
381 |
return NOBREAK; |
8 | 382 |
} |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
383 |
else if (res == 0) |
2 | 384 |
{ |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
385 |
clean_after_client_disappeared(s, index); |
2 | 386 |
return NOBREAK; |
387 |
} |
|
1 | 388 |
|
2 | 389 |
/* Process message */ |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
390 |
switch(m.type) |
22 | 391 |
{ |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
392 |
case KILL_SERVER: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
393 |
return BREAK; /* break in the parent*/ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
394 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
395 |
case NEWJOB: |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
396 |
if (nqueued < max_queued) |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
397 |
{ |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
398 |
client_cs[index].jobid = s_newjob(s, &m); |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
399 |
client_cs[index].hasjob = 1; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
400 |
s_newjob_ok(index); |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
401 |
++nqueued; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
402 |
} |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
403 |
else |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
404 |
{ |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
405 |
client_cs[index].waits_enqueuing = 1; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
406 |
client_cs[index].enqueue_msg = m; |
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
407 |
} |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
408 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
409 |
case RUNJOB_OK: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
410 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
411 |
char *buffer = 0; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
412 |
if (m.u.output.store_output) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
413 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
414 |
/* Receive the output filename */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
415 |
buffer = (char *) malloc(m.u.output.ofilename_size); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
416 |
res = recv_bytes(s, buffer, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
417 |
m.u.output.ofilename_size); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
418 |
if (res != m.u.output.ofilename_size) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
419 |
error("Reading the ofilename"); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
420 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
421 |
s_process_runjob_ok(client_cs[index].jobid, buffer, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
422 |
m.u.output.pid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
423 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
424 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
425 |
case LIST: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
426 |
s_list(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
427 |
/* We must actively close, meaning End of Lines */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
428 |
close(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
429 |
remove_connection(index); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
430 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
431 |
case INFO: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
432 |
s_job_info(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
433 |
close(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
434 |
remove_connection(index); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
435 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
436 |
case ENDJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
437 |
job_finished(&m.u.result, client_cs[index].jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
438 |
/* For the dependencies */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
439 |
check_notify_list(client_cs[index].jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
440 |
/* We don't want this connection to do anything |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
441 |
* more related to the jobid, secially on remove_connection |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
442 |
* when we receive the EOC. */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
443 |
client_cs[index].hasjob = 0; |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
444 |
--nqueued; |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
445 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
446 |
case CLEAR_FINISHED: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
447 |
s_clear_finished(); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
448 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
449 |
case ASK_OUTPUT: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
450 |
s_send_output(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
451 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
452 |
case REMOVEJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
453 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
454 |
int went_ok; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
455 |
went_ok = s_remove_job(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
456 |
if (went_ok) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
457 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
458 |
int i; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
459 |
for(i = 0; i < nconnections; ++i) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
460 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
461 |
if (client_cs[i].hasjob && client_cs[i].jobid == m.u.jobid) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
462 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
463 |
close(client_cs[i].socket); |
146 | 464 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
465 |
/* So remove_connection doesn't call s_removejob again */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
466 |
client_cs[i].hasjob = 0; |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
467 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
468 |
/* We don't try to remove any notification related to |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
469 |
* 'i', because it will be for sure a ts client for a job */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
470 |
remove_connection(i); |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
471 |
|
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
472 |
--nqueued; |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
473 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
474 |
} |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
475 |
} |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
476 |
} |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
477 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
478 |
case WAITJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
479 |
s_wait_job(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
480 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
481 |
case WAIT_RUNNING_JOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
482 |
s_wait_running_job(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
483 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
484 |
case URGENT: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
485 |
s_move_urgent(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
486 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
487 |
case SET_MAX_SLOTS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
488 |
s_set_max_slots(m.u.max_slots); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
489 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
490 |
case GET_MAX_SLOTS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
491 |
s_get_max_slots(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
492 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
493 |
case SWAP_JOBS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
494 |
s_swap_jobs(s, m.u.swap.jobid1, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
495 |
m.u.swap.jobid2); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
496 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
497 |
case GET_STATE: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
498 |
s_send_state(s, m.u.jobid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
499 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
500 |
case GET_VERSION: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
501 |
s_send_version(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
502 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
503 |
default: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
504 |
/* Command not supported */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
505 |
/* On unknown message, we close the client, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
506 |
or it may hang waiting for an answer */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
507 |
warning("Unknown message: %i", m.type); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
508 |
return CLOSE; |
63 | 509 |
} |
510 |
||
2 | 511 |
return NOBREAK; /* normal */ |
1 | 512 |
} |
4 | 513 |
|
218 | 514 |
static void s_runjob(int jobid, int index) |
8 | 515 |
{ |
516 |
int s; |
|
517 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
518 |
if (!client_cs[index].hasjob) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
519 |
error("Run job of the client %i which doesn't have any job", index); |
8 | 520 |
|
521 |
s = client_cs[index].socket; |
|
522 |
||
218 | 523 |
s_send_runjob(s, jobid); |
8 | 524 |
} |
525 |
||
526 |
static void s_newjob_ok(int index) |
|
4 | 527 |
{ |
528 |
int s; |
|
529 |
struct msg m; |
|
530 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
531 |
if (!client_cs[index].hasjob) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
532 |
error("Run job of the client %i which doesn't have any job", index); |
4 | 533 |
|
534 |
s = client_cs[index].socket; |
|
535 |
||
536 |
m.type = NEWJOB_OK; |
|
537 |
m.u.jobid = client_cs[index].jobid; |
|
538 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
539 |
send_msg(s, &m); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
540 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
541 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
542 |
static void dump_conn_struct(FILE *out, const struct Client_conn *p) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
543 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
544 |
fprintf(out, " new_conn\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
545 |
fprintf(out, " socket %i\n", p->socket); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
546 |
fprintf(out, " hasjob \"%i\"\n", p->hasjob); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
547 |
fprintf(out, " jobid %i\n", p->jobid); |
285
0a105f193446
Working on the queue limit. It still does not work but I don't know why. I've
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
548 |
fprintf(out, " waits_enqueuing %i\n", p->waits_enqueuing); |
4 | 549 |
} |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
550 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
551 |
void dump_conns_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
552 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
553 |
int i; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
554 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
555 |
fprintf(out, "New_conns"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
556 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
557 |
for(i=0; i < nconnections; ++i) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
558 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
559 |
dump_conn_struct(out, &client_cs[i]); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
560 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
561 |
} |