author | viric <viriketo@gmail.com> |
Mon, 18 Jul 2011 22:45:13 +0200 | |
branch | queuelimit2 |
changeset 292 | 72419de39d72 |
parent 290 | eefb37e0a8fe |
child 295 | a63f43a17fd7 |
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; |
|
54 |
}; |
|
55 |
||
56 |
/* Globals */ |
|
57 |
static struct Client_conn client_cs[MAXCONN]; |
|
58 |
static int nconnections; |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
59 |
static char *path; |
94 | 60 |
static int max_descriptors; |
61 |
||
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
62 |
/* in jobs.c */ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
63 |
extern int max_jobs; |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
64 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
65 |
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
|
66 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
67 |
struct msg m; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
68 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
69 |
m.type = VERSION; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
70 |
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
|
71 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
72 |
send_msg(s, &m); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
73 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
74 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
75 |
static void sigterm_handler(int n) |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
76 |
{ |
120 | 77 |
const char *dumpfilename; |
78 |
int fd; |
|
79 |
||
80 |
/* Dump the job list if we should to */ |
|
81 |
dumpfilename = getenv("TS_SAVELIST"); |
|
82 |
if (dumpfilename != NULL) |
|
83 |
{ |
|
84 |
fd = open(dumpfilename, O_WRONLY | O_APPEND | O_CREAT, 0600); |
|
85 |
if (fd != -1) |
|
86 |
{ |
|
87 |
joblist_dump(fd); |
|
88 |
close(fd); |
|
89 |
} else |
|
90 |
warning("The TS_SAVELIST file \"%s\" cannot be opened", |
|
91 |
dumpfilename); |
|
92 |
} |
|
93 |
||
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
94 |
/* 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
|
95 |
unlink(path); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
96 |
exit(1); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
97 |
} |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
98 |
|
239
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
99 |
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
|
100 |
{ |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
101 |
char *str; |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
102 |
|
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
103 |
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
|
104 |
if (str != NULL) |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
105 |
{ |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
106 |
int slots; |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
} |
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 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
112 |
static void install_sigterm_handler() |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
113 |
{ |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
114 |
struct sigaction act; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
115 |
|
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
116 |
act.sa_handler = sigterm_handler; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
117 |
/* Reset the mask */ |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
118 |
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
|
119 |
act.sa_flags = 0; |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
120 |
|
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
121 |
sigaction(SIGTERM, &act, NULL); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
122 |
} |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
123 |
|
94 | 124 |
static int get_max_descriptors() |
125 |
{ |
|
126 |
const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */ |
|
127 |
int max; |
|
128 |
struct rlimit rlim; |
|
129 |
int res; |
|
278 | 130 |
const char *str; |
94 | 131 |
|
132 |
max = MAXCONN; |
|
278 | 133 |
|
134 |
str = getenv("TS_MAXCONN"); |
|
135 |
if (str != NULL) |
|
136 |
{ |
|
137 |
int user_maxconn; |
|
138 |
user_maxconn = abs(atoi(str)); |
|
139 |
if (max > user_maxconn) |
|
140 |
max = user_maxconn; |
|
141 |
} |
|
142 |
||
94 | 143 |
if (max > FD_SETSIZE) |
278 | 144 |
max = FD_SETSIZE - MARGIN; |
94 | 145 |
|
146 |
/* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any |
|
147 |
* of them is POSIX compliant */ |
|
148 |
||
149 |
res = getrlimit(RLIMIT_NOFILE, &rlim); |
|
150 |
if (res != 0) |
|
151 |
warning("getrlimit for open files"); |
|
152 |
else |
|
153 |
{ |
|
154 |
if (max > rlim.rlim_cur) |
|
278 | 155 |
max = rlim.rlim_cur - MARGIN; |
94 | 156 |
} |
157 |
||
278 | 158 |
if (max < 1) |
94 | 159 |
error("Too few opened descriptors available"); |
160 |
||
278 | 161 |
return max; |
94 | 162 |
} |
1 | 163 |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
164 |
void server_main(int notify_fd, char *_path) |
1 | 165 |
{ |
44 | 166 |
int ls; |
2 | 167 |
struct sockaddr_un addr; |
168 |
int res; |
|
263 | 169 |
char *dirpath; |
1 | 170 |
|
104 | 171 |
process_type = SERVER; |
94 | 172 |
max_descriptors = get_max_descriptors(); |
173 |
||
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
174 |
/* Arbitrary limit, that will block the enqueuing, but should allow space |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
175 |
* for usual ts queries */ |
290
eefb37e0a8fe
Restoring the max_jobs to a reasonable value, not only for testing.
viric <viriketo@gmail.com>
parents:
288
diff
changeset
|
176 |
max_jobs = max_descriptors - 5; |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
177 |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
178 |
path = _path; |
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
179 |
|
263 | 180 |
/* Move the server to the socket directory */ |
181 |
dirpath = strdup(path); |
|
182 |
chdir(dirname(dirpath)); |
|
183 |
free(dirpath); |
|
184 |
||
3 | 185 |
nconnections = 0; |
186 |
||
129
312083fb8899
Change PF_UNIX to AF_UNIX. According to socket(2), this is better.
viric@llimona
parents:
120
diff
changeset
|
187 |
ls = socket(AF_UNIX, SOCK_STREAM, 0); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
188 |
if(ls == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
189 |
error("cannot create the listen socket in the server"); |
1 | 190 |
|
2 | 191 |
addr.sun_family = AF_UNIX; |
192 |
strcpy(addr.sun_path, path); |
|
1 | 193 |
|
2 | 194 |
res = bind(ls, (struct sockaddr *) &addr, sizeof(addr)); |
195 |
if (res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
196 |
error("Error binding."); |
1 | 197 |
|
2 | 198 |
res = listen(ls, 0); |
199 |
if (res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
200 |
error("Error listening."); |
1 | 201 |
|
99
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
202 |
install_sigterm_handler(); |
88d96be4e0e9
Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents:
94
diff
changeset
|
203 |
|
239
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
204 |
set_default_maxslots(); |
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
231
diff
changeset
|
205 |
|
25 | 206 |
notify_parent(notify_fd); |
207 |
||
2 | 208 |
server_loop(ls); |
1 | 209 |
} |
210 |
||
8 | 211 |
static int get_conn_of_jobid(int jobid) |
212 |
{ |
|
213 |
int i; |
|
214 |
for(i=0; i< nconnections; ++i) |
|
215 |
if (client_cs[i].hasjob && client_cs[i].jobid == jobid) |
|
216 |
return i; |
|
217 |
return -1; |
|
218 |
} |
|
219 |
||
3 | 220 |
static void server_loop(int ls) |
1 | 221 |
{ |
2 | 222 |
fd_set readset; |
223 |
int i; |
|
224 |
int maxfd; |
|
225 |
int keep_loop = 1; |
|
8 | 226 |
int newjob; |
1 | 227 |
|
2 | 228 |
while (keep_loop) |
229 |
{ |
|
230 |
FD_ZERO(&readset); |
|
94 | 231 |
maxfd = 0; |
232 |
/* If we can accept more connections, go on. |
|
233 |
* Otherwise, the system block them (no accept will be done). */ |
|
234 |
if (nconnections < max_descriptors) |
|
235 |
{ |
|
236 |
FD_SET(ls,&readset); |
|
237 |
maxfd = ls; |
|
238 |
} |
|
2 | 239 |
for(i=0; i< nconnections; ++i) |
240 |
{ |
|
3 | 241 |
FD_SET(client_cs[i].socket, &readset); |
242 |
if (client_cs[i].socket > maxfd) |
|
243 |
maxfd = client_cs[i].socket; |
|
2 | 244 |
} |
245 |
select(maxfd + 1, &readset, NULL, NULL, NULL); |
|
246 |
if (FD_ISSET(ls,&readset)) |
|
247 |
{ |
|
248 |
int cs; |
|
249 |
cs = accept(ls, NULL, NULL); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
250 |
if (cs == -1) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
client_cs[nconnections].socket = cs; |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
254 |
++nconnections; |
2 | 255 |
} |
256 |
for(i=0; i< nconnections; ++i) |
|
3 | 257 |
if (FD_ISSET(client_cs[i].socket, &readset)) |
2 | 258 |
{ |
259 |
enum Break b; |
|
3 | 260 |
b = client_read(i); |
2 | 261 |
/* 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
|
262 |
if (b == CLOSE) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
263 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
264 |
warning("Closing"); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
265 |
/* 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
|
266 |
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
|
267 |
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
|
268 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
269 |
else if (b == BREAK) |
2 | 270 |
keep_loop = 0; |
271 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
272 |
/* This will return firstjob->jobid or -1 */ |
8 | 273 |
newjob = next_run_job(); |
274 |
if (newjob != -1) |
|
275 |
{ |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
276 |
int conn, awaken_job; |
8 | 277 |
conn = get_conn_of_jobid(newjob); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
278 |
/* This next marks the firstjob state to RUNNING */ |
218 | 279 |
s_mark_job_running(newjob); |
280 |
s_runjob(newjob, conn); |
|
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
281 |
|
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
282 |
while ((awaken_job = wake_hold_client()) != -1) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
283 |
{ |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
284 |
int wake_conn = get_conn_of_jobid(awaken_job); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
285 |
if (wake_conn == -1) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
286 |
error("The job awaken does not have a connection open"); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
287 |
s_newjob_ok(wake_conn); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
288 |
} |
8 | 289 |
} |
2 | 290 |
} |
1 | 291 |
|
2 | 292 |
end_server(ls); |
1 | 293 |
} |
294 |
||
3 | 295 |
static void end_server(int ls) |
1 | 296 |
{ |
2 | 297 |
close(ls); |
298 |
unlink(path); |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
26
diff
changeset
|
299 |
/* 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
|
300 |
* 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
|
301 |
free(path); |
1 | 302 |
} |
303 |
||
3 | 304 |
static void remove_connection(int index) |
1 | 305 |
{ |
2 | 306 |
int i; |
3 | 307 |
|
308 |
if(client_cs[index].hasjob) |
|
2 | 309 |
{ |
3 | 310 |
s_removejob(client_cs[index].jobid); |
2 | 311 |
} |
3 | 312 |
|
313 |
for(i=index; i<(nconnections-1); ++i) |
|
314 |
{ |
|
315 |
memcpy(&client_cs[i], &client_cs[i+1], sizeof(client_cs[0])); |
|
316 |
} |
|
317 |
nconnections--; |
|
1 | 318 |
} |
319 |
||
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
320 |
static void |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
321 |
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
|
322 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
323 |
/* 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
|
324 |
int jobid = client_cs[index].jobid; |
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
|
325 |
if (client_cs[index].hasjob) |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
326 |
{ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
327 |
struct Result r; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
328 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
329 |
r.errorlevel = -1; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
330 |
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
|
331 |
r.signal = SIGKILL; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
332 |
r.user_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
333 |
r.system_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
334 |
r.real_ms = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
335 |
r.skipped = 0; |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
336 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
337 |
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
|
338 |
job_finished(&r, jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
339 |
/* For the dependencies */ |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
340 |
check_notify_list(jobid); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
341 |
/* 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
|
342 |
* 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
|
343 |
* 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
|
344 |
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
|
345 |
} |
256
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
346 |
else |
638fcfee37c6
In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents:
253
diff
changeset
|
347 |
/* 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
|
348 |
* 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
|
349 |
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
|
350 |
|
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
351 |
close(socket); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
352 |
remove_connection(index); |
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
353 |
} |
3 | 354 |
|
355 |
static enum Break |
|
356 |
client_read(int index) |
|
1 | 357 |
{ |
3 | 358 |
struct msg m; |
2 | 359 |
int s; |
360 |
int res; |
|
1 | 361 |
|
3 | 362 |
s = client_cs[index].socket; |
1 | 363 |
|
2 | 364 |
/* Read the message */ |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
365 |
res = recv_msg(s, &m); |
8 | 366 |
if (res == -1) |
367 |
{ |
|
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
368 |
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
|
369 |
clean_after_client_disappeared(s, index); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
370 |
return NOBREAK; |
8 | 371 |
} |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
372 |
else if (res == 0) |
2 | 373 |
{ |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
239
diff
changeset
|
374 |
clean_after_client_disappeared(s, index); |
2 | 375 |
return NOBREAK; |
376 |
} |
|
1 | 377 |
|
2 | 378 |
/* Process message */ |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
379 |
switch(m.type) |
22 | 380 |
{ |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
381 |
case KILL_SERVER: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
382 |
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
|
383 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
384 |
case NEWJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
385 |
client_cs[index].jobid = s_newjob(s, &m); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
386 |
client_cs[index].hasjob = 1; |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
387 |
if (!job_is_holding_client(client_cs[index].jobid)) |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
278
diff
changeset
|
388 |
s_newjob_ok(index); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
389 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
390 |
case RUNJOB_OK: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
391 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
392 |
char *buffer = 0; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
393 |
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
|
394 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
395 |
/* Receive the output filename */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
error("Reading the ofilename"); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
401 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
402 |
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
|
403 |
m.u.output.pid); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
404 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
405 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
406 |
case LIST: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
407 |
s_list(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
408 |
/* 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
|
409 |
close(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
410 |
remove_connection(index); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
411 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
412 |
case INFO: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
413 |
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
|
414 |
close(s); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
415 |
remove_connection(index); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
416 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
417 |
case ENDJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
418 |
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
|
419 |
/* For the dependencies */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
420 |
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
|
421 |
/* 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
|
422 |
* 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
|
423 |
* 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
|
424 |
client_cs[index].hasjob = 0; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
425 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
426 |
case CLEAR_FINISHED: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
427 |
s_clear_finished(); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
428 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
429 |
case ASK_OUTPUT: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
430 |
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
|
431 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
432 |
case REMOVEJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
433 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
434 |
int went_ok; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
435 |
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
|
436 |
if (went_ok) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
437 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
438 |
int i; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
439 |
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
|
440 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
441 |
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
|
442 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
443 |
close(client_cs[i].socket); |
146 | 444 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
445 |
/* 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
|
446 |
client_cs[i].hasjob = 0; |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
447 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
448 |
/* 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
|
449 |
* '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
|
450 |
remove_connection(i); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
451 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
452 |
} |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
453 |
} |
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
129
diff
changeset
|
454 |
} |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
455 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
456 |
case WAITJOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
457 |
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
|
458 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
459 |
case WAIT_RUNNING_JOB: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
460 |
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
|
461 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
462 |
case URGENT: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
463 |
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
|
464 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
465 |
case SET_MAX_SLOTS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
466 |
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
|
467 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
468 |
case GET_MAX_SLOTS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
469 |
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
|
470 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
471 |
case SWAP_JOBS: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
472 |
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
|
473 |
m.u.swap.jobid2); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
474 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
475 |
case GET_STATE: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
476 |
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
|
477 |
break; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
478 |
case GET_VERSION: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
479 |
s_send_version(s); |
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 |
default: |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
482 |
/* Command not supported */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
256
diff
changeset
|
483 |
/* 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
|
484 |
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
|
485 |
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
|
486 |
return CLOSE; |
63 | 487 |
} |
488 |
||
2 | 489 |
return NOBREAK; /* normal */ |
1 | 490 |
} |
4 | 491 |
|
218 | 492 |
static void s_runjob(int jobid, int index) |
8 | 493 |
{ |
494 |
int s; |
|
495 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
496 |
if (!client_cs[index].hasjob) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
497 |
error("Run job of the client %i which doesn't have any job", index); |
8 | 498 |
|
499 |
s = client_cs[index].socket; |
|
500 |
||
218 | 501 |
s_send_runjob(s, jobid); |
8 | 502 |
} |
503 |
||
504 |
static void s_newjob_ok(int index) |
|
4 | 505 |
{ |
506 |
int s; |
|
507 |
struct msg m; |
|
508 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
509 |
if (!client_cs[index].hasjob) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
510 |
error("Run job of the client %i which doesn't have any job", index); |
4 | 511 |
|
512 |
s = client_cs[index].socket; |
|
513 |
||
514 |
m.type = NEWJOB_OK; |
|
515 |
m.u.jobid = client_cs[index].jobid; |
|
516 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
517 |
send_msg(s, &m); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
518 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
519 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
520 |
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
|
521 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
522 |
fprintf(out, " new_conn\n"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
523 |
fprintf(out, " socket %i\n", p->socket); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
524 |
fprintf(out, " hasjob \"%i\"\n", p->hasjob); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
525 |
fprintf(out, " jobid %i\n", p->jobid); |
4 | 526 |
} |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
527 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
528 |
void dump_conns_struct(FILE *out) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
529 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
530 |
int i; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
531 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
532 |
fprintf(out, "New_conns"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
533 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
534 |
for(i=0; i < nconnections; ++i) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
535 |
{ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
536 |
dump_conn_struct(out, &client_cs[i]); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
537 |
} |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
66
diff
changeset
|
538 |
} |