author | viric@llimona |
Mon, 12 Nov 2007 09:57:46 +0100 | |
changeset 140 | 0b99d94818d1 |
parent 117 | db479ef293d3 |
child 146 | 5e689cb593aa |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
|
4 |
||
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
9 | 7 |
#include <stdio.h> |
44 | 8 |
#include <string.h> |
9 |
#include <stdlib.h> |
|
10 |
#include <sys/types.h> |
|
11 |
#include <sys/socket.h> |
|
3 | 12 |
#include "main.h" |
1 | 13 |
|
110 | 14 |
static void c_end_of_job(const struct Result *res); |
8 | 15 |
|
71 | 16 |
char *build_command_string() |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
17 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
18 |
int size; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
19 |
int i; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
20 |
int num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
21 |
char **array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
22 |
char *commandstring; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
23 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
24 |
size = 0; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
25 |
num = command_line.command.num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
26 |
array = command_line.command.array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
27 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
28 |
/* Count bytes needed */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
29 |
for (i = 0; i < num; ++i) |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
30 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
31 |
/* The '1' is for spaces, and at the last i, |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
32 |
* for the null character */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
33 |
size = size + strlen(array[i]) + 1; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
34 |
} |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
35 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
36 |
/* Alloc */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
37 |
commandstring = (char *) malloc(size); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
38 |
if(commandstring == NULL) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
39 |
error("Error in malloc for commandstring"); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
40 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
41 |
/* Build the command */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
42 |
strcpy(commandstring, array[0]); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
43 |
for (i = 1; i < num; ++i) |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
44 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
45 |
strcat(commandstring, " "); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
46 |
strcat(commandstring, array[i]); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
47 |
} |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
48 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
49 |
return commandstring; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
50 |
} |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
51 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
52 |
void c_new_job() |
3 | 53 |
{ |
54 |
struct msg m; |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
55 |
char *new_command; |
3 | 56 |
|
57 |
m.type = NEWJOB; |
|
58 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
59 |
new_command = build_command_string(); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
60 |
|
8 | 61 |
/* global */ |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
62 |
m.u.newjob.command_size = strlen(new_command) + 1; /* add null */ |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
27
diff
changeset
|
63 |
m.u.newjob.store_output = command_line.store_output; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
64 |
m.u.newjob.should_keep_finished = command_line.should_keep_finished; |
3 | 65 |
|
18 | 66 |
/* Send the message */ |
67 |
send_msg(server_socket, &m); |
|
68 |
||
69 |
/* Send the command */ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
70 |
send_bytes(server_socket, new_command, m.u.newjob.command_size); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
71 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
72 |
free(new_command); |
3 | 73 |
} |
74 |
||
62 | 75 |
int c_wait_newjob_ok() |
76 |
{ |
|
77 |
struct msg m; |
|
78 |
int res; |
|
79 |
||
80 |
res = recv_msg(server_socket, &m); |
|
81 |
if(res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
82 |
error("Error in wait_newjob_ok"); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
83 |
if(m.type != NEWJOB_OK) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
84 |
error("Error getting the newjob_ok"); |
62 | 85 |
|
86 |
return m.u.jobid; |
|
87 |
} |
|
88 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
89 |
int c_wait_server_commands() |
3 | 90 |
{ |
91 |
struct msg m; |
|
92 |
int res; |
|
93 |
||
94 |
while (1) |
|
95 |
{ |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
96 |
res = recv_msg(server_socket, &m); |
3 | 97 |
if(res == -1) |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
98 |
error("Error in wait_server_commands"); |
3 | 99 |
|
100 |
if (res == 0) |
|
101 |
break; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
102 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
103 |
error("Error in wait_server_commands"); |
8 | 104 |
if (m.type == RUNJOB) |
5 | 105 |
{ |
110 | 106 |
struct Result res; |
22 | 107 |
/* This will send RUNJOB_OK */ |
110 | 108 |
run_job(&res); |
109 |
c_end_of_job(&res); |
|
110 |
return res.errorlevel; |
|
5 | 111 |
} |
112 |
} |
|
38
768d009604b3
The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents:
35
diff
changeset
|
113 |
return -1; |
5 | 114 |
} |
115 |
||
116 |
void c_wait_server_lines() |
|
117 |
{ |
|
118 |
struct msg m; |
|
119 |
int res; |
|
120 |
||
121 |
while (1) |
|
122 |
{ |
|
21 | 123 |
res = recv_msg(server_socket, &m); |
5 | 124 |
if(res == -1) |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
125 |
error("Error in wait_server_lines"); |
5 | 126 |
|
127 |
if (res == 0) |
|
128 |
break; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
129 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
130 |
error("Error in wait_server_lines 2"); |
5 | 131 |
if (m.type == LIST_LINE) |
132 |
{ |
|
21 | 133 |
char * buffer; |
134 |
buffer = (char *) malloc(m.u.line_size); |
|
135 |
recv_bytes(server_socket, buffer, m.u.line_size); |
|
136 |
printf("%s", buffer); |
|
137 |
free(buffer); |
|
5 | 138 |
} |
3 | 139 |
} |
140 |
} |
|
141 |
||
8 | 142 |
void c_list_jobs() |
3 | 143 |
{ |
144 |
struct msg m; |
|
145 |
||
146 |
m.type = LIST; |
|
147 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
148 |
send_msg(server_socket, &m); |
3 | 149 |
} |
150 |
||
35 | 151 |
void c_send_runjob_ok(const char *ofname, int pid) |
22 | 152 |
{ |
153 |
struct msg m; |
|
154 |
||
155 |
/* Prepare the message */ |
|
156 |
m.type = RUNJOB_OK; |
|
32 | 157 |
m.u.output.store_output = command_line.store_output; |
35 | 158 |
m.u.output.pid = pid; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
27
diff
changeset
|
159 |
if (command_line.store_output) |
32 | 160 |
m.u.output.ofilename_size = strlen(ofname) + 1; |
22 | 161 |
else |
32 | 162 |
m.u.output.ofilename_size = 0; |
22 | 163 |
|
164 |
send_msg(server_socket, &m); |
|
165 |
||
166 |
/* Send the filename */ |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
27
diff
changeset
|
167 |
if (command_line.store_output) |
32 | 168 |
send_bytes(server_socket, ofname, m.u.output.ofilename_size); |
22 | 169 |
} |
170 |
||
110 | 171 |
static void c_end_of_job(const struct Result *res) |
8 | 172 |
{ |
173 |
struct msg m; |
|
174 |
||
175 |
m.type = ENDJOB; |
|
110 | 176 |
m.u.result = *res; /* struct copy */ |
8 | 177 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
178 |
send_msg(server_socket, &m); |
8 | 179 |
} |
180 |
||
44 | 181 |
void c_shutdown_server() |
1 | 182 |
{ |
2 | 183 |
struct msg m; |
1 | 184 |
|
31 | 185 |
m.type = KILL_SERVER; |
32 | 186 |
send_msg(server_socket, &m); |
1 | 187 |
} |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
188 |
|
44 | 189 |
void c_clear_finished() |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
190 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
191 |
struct msg m; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
192 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
193 |
m.type = CLEAR_FINISHED; |
32 | 194 |
send_msg(server_socket, &m); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
195 |
} |
32 | 196 |
|
35 | 197 |
static char * get_output_file(int *pid) |
32 | 198 |
{ |
199 |
struct msg m; |
|
200 |
int res; |
|
201 |
char *string = 0; |
|
202 |
||
203 |
/* Send the request */ |
|
204 |
m.type = ASK_OUTPUT; |
|
205 |
m.u.jobid = command_line.jobid; |
|
206 |
send_msg(server_socket, &m); |
|
207 |
||
208 |
/* Receive the answer */ |
|
209 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
210 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
211 |
error("Error in get_output_file"); |
32 | 212 |
switch(m.type) |
213 |
{ |
|
214 |
case ANSWER_OUTPUT: |
|
215 |
if (m.u.output.store_output) |
|
216 |
{ |
|
217 |
/* Receive the output file name */ |
|
218 |
string = (char *) malloc(m.u.output.ofilename_size); |
|
219 |
recv_bytes(server_socket, string, m.u.output.ofilename_size); |
|
35 | 220 |
*pid = m.u.output.pid; |
33 | 221 |
return string; |
32 | 222 |
} |
35 | 223 |
*pid = m.u.output.pid; |
224 |
return 0; |
|
32 | 225 |
/* WILL NOT GO FURTHER */ |
226 |
case LIST_LINE: /* Only ONE line accepted */ |
|
227 |
string = (char *) malloc(m.u.line_size); |
|
228 |
res = recv_bytes(server_socket, string, m.u.line_size); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
229 |
if(res != m.u.line_size) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
230 |
error("Error in get_output_file line size"); |
32 | 231 |
fprintf(stderr, "Error in the request: %s", |
232 |
string); |
|
233 |
exit(-1); |
|
234 |
/* WILL NOT GO FURTHER */ |
|
44 | 235 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
236 |
warning("Wrong internal message in get_output_file line size"); |
32 | 237 |
} |
33 | 238 |
/* This will never be reached */ |
239 |
return 0; |
|
32 | 240 |
} |
33 | 241 |
|
242 |
void c_tail() |
|
243 |
{ |
|
244 |
char *str; |
|
35 | 245 |
int pid; |
246 |
str = get_output_file(&pid); |
|
247 |
if (str == 0) |
|
248 |
{ |
|
249 |
fprintf(stderr, "The output is not stored. Cannot tail.\n"); |
|
250 |
exit(-1); |
|
251 |
} |
|
33 | 252 |
c_run_tail(str); |
253 |
} |
|
254 |
||
255 |
void c_cat() |
|
256 |
{ |
|
257 |
char *str; |
|
35 | 258 |
int pid; |
259 |
str = get_output_file(&pid); |
|
260 |
if (str == 0) |
|
261 |
{ |
|
262 |
fprintf(stderr, "The output is not stored. Cannot tail.\n"); |
|
263 |
exit(-1); |
|
264 |
} |
|
33 | 265 |
c_run_cat(str); |
266 |
} |
|
267 |
||
268 |
void c_show_output_file() |
|
269 |
{ |
|
270 |
char *str; |
|
35 | 271 |
int pid; |
272 |
/* This will exit if there is any error */ |
|
273 |
str = get_output_file(&pid); |
|
274 |
if (str == 0) |
|
275 |
{ |
|
276 |
fprintf(stderr, "The output is not stored. Cannot tail.\n"); |
|
277 |
exit(-1); |
|
278 |
} |
|
33 | 279 |
printf("%s\n", str); |
35 | 280 |
free(str); |
33 | 281 |
} |
35 | 282 |
|
283 |
void c_show_pid() |
|
284 |
{ |
|
285 |
char *str; |
|
286 |
int pid; |
|
287 |
/* This will exit if there is any error */ |
|
288 |
str = get_output_file(&pid); |
|
289 |
printf("%i\n", pid); |
|
290 |
} |
|
41 | 291 |
|
292 |
void c_remove_job() |
|
293 |
{ |
|
294 |
struct msg m; |
|
295 |
int res; |
|
296 |
char *string = 0; |
|
297 |
||
298 |
/* Send the request */ |
|
299 |
m.type = REMOVEJOB; |
|
300 |
m.u.jobid = command_line.jobid; |
|
301 |
send_msg(server_socket, &m); |
|
302 |
||
303 |
/* Receive the answer */ |
|
304 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
305 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
306 |
error("Error in remove_job"); |
41 | 307 |
switch(m.type) |
308 |
{ |
|
309 |
case REMOVEJOB_OK: |
|
310 |
return; |
|
311 |
/* WILL NOT GO FURTHER */ |
|
312 |
case LIST_LINE: /* Only ONE line accepted */ |
|
313 |
string = (char *) malloc(m.u.line_size); |
|
314 |
res = recv_bytes(server_socket, string, m.u.line_size); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
315 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
316 |
error("Error in remove_job"); |
41 | 317 |
fprintf(stderr, "Error in the request: %s", |
318 |
string); |
|
319 |
exit(-1); |
|
320 |
/* WILL NOT GO FURTHER */ |
|
44 | 321 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
322 |
warning("Wrong internal message in remove_job"); |
41 | 323 |
} |
324 |
/* This will never be reached */ |
|
325 |
} |
|
42 | 326 |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
327 |
/* Returns the errorlevel */ |
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
328 |
int c_wait_job() |
42 | 329 |
{ |
330 |
struct msg m; |
|
331 |
int res; |
|
332 |
char *string = 0; |
|
333 |
||
334 |
/* Send the request */ |
|
335 |
m.type = WAITJOB; |
|
336 |
m.u.jobid = command_line.jobid; |
|
337 |
send_msg(server_socket, &m); |
|
338 |
||
339 |
/* Receive the answer */ |
|
340 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
341 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
342 |
error("Error in wait_job"); |
42 | 343 |
switch(m.type) |
344 |
{ |
|
345 |
case WAITJOB_OK: |
|
110 | 346 |
return m.u.result.errorlevel; |
42 | 347 |
/* WILL NOT GO FURTHER */ |
348 |
case LIST_LINE: /* Only ONE line accepted */ |
|
349 |
string = (char *) malloc(m.u.line_size); |
|
350 |
res = recv_bytes(server_socket, string, m.u.line_size); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
351 |
if(res != m.u.line_size) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
352 |
error("Error in wait_job - line size"); |
42 | 353 |
fprintf(stderr, "Error in the request: %s", |
354 |
string); |
|
355 |
exit(-1); |
|
356 |
/* WILL NOT GO FURTHER */ |
|
44 | 357 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
358 |
warning("Wrong internal message in c_wait_job"); |
42 | 359 |
} |
360 |
/* This will never be reached */ |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
361 |
return -1; |
42 | 362 |
} |
53 | 363 |
|
364 |
void c_move_urgent() |
|
365 |
{ |
|
366 |
struct msg m; |
|
367 |
int res; |
|
368 |
char *string = 0; |
|
369 |
||
370 |
/* Send the request */ |
|
371 |
m.type = URGENT; |
|
372 |
m.u.jobid = command_line.jobid; |
|
373 |
send_msg(server_socket, &m); |
|
374 |
||
375 |
/* Receive the answer */ |
|
376 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
377 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
378 |
error("Error in move_urgent"); |
53 | 379 |
switch(m.type) |
380 |
{ |
|
381 |
case URGENT_OK: |
|
382 |
return; |
|
383 |
/* WILL NOT GO FURTHER */ |
|
384 |
case LIST_LINE: /* Only ONE line accepted */ |
|
385 |
string = (char *) malloc(m.u.line_size); |
|
386 |
res = recv_bytes(server_socket, string, m.u.line_size); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
387 |
if(res != m.u.line_size) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
388 |
error("Error in move_urgent - line size"); |
53 | 389 |
fprintf(stderr, "Error in the request: %s", |
390 |
string); |
|
391 |
exit(-1); |
|
392 |
/* WILL NOT GO FURTHER */ |
|
393 |
default: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
394 |
warning("Wrong internal message in move_urgent"); |
53 | 395 |
} |
396 |
/* This will never be reached */ |
|
397 |
return; |
|
398 |
} |
|
63 | 399 |
|
400 |
void c_get_state() |
|
401 |
{ |
|
402 |
struct msg m; |
|
403 |
int res; |
|
404 |
char *string = 0; |
|
405 |
||
406 |
/* Send the request */ |
|
407 |
m.type = GET_STATE; |
|
408 |
m.u.jobid = command_line.jobid; |
|
409 |
send_msg(server_socket, &m); |
|
410 |
||
411 |
/* Receive the answer */ |
|
412 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
413 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
414 |
error("Error in get_state - line size"); |
63 | 415 |
switch(m.type) |
416 |
{ |
|
417 |
case ANSWER_STATE: |
|
418 |
printf("%s\n", jstate2string(m.u.state)); |
|
419 |
return; |
|
420 |
/* WILL NOT GO FURTHER */ |
|
421 |
case LIST_LINE: /* Only ONE line accepted */ |
|
422 |
string = (char *) malloc(m.u.line_size); |
|
423 |
res = recv_bytes(server_socket, string, m.u.line_size); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
424 |
if(res != m.u.line_size) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
425 |
error("Error in get_state - line size"); |
63 | 426 |
fprintf(stderr, "Error in the request: %s", |
427 |
string); |
|
428 |
exit(-1); |
|
429 |
/* WILL NOT GO FURTHER */ |
|
430 |
default: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
431 |
warning("Wrong internal message in get_state"); |
63 | 432 |
} |
433 |
/* This will never be reached */ |
|
434 |
return; |
|
435 |
} |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
436 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
437 |
void c_swap_jobs() |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
438 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
439 |
struct msg m; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
440 |
int res; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
441 |
char *string = 0; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
442 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
443 |
/* Send the request */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
444 |
m.type = SWAP_JOBS; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
445 |
m.u.swap.jobid1 = command_line.jobid; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
446 |
m.u.swap.jobid2 = command_line.jobid2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
447 |
send_msg(server_socket, &m); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
448 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
449 |
/* Receive the answer */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
450 |
res = recv_msg(server_socket, &m); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
451 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
452 |
error("Error in swap_jobs"); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
453 |
switch(m.type) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
454 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
455 |
case SWAP_JOBS_OK: |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
456 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
457 |
/* WILL NOT GO FURTHER */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
458 |
case LIST_LINE: /* Only ONE line accepted */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
459 |
string = (char *) malloc(m.u.line_size); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
460 |
res = recv_bytes(server_socket, string, m.u.line_size); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
461 |
if(res != m.u.line_size) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
462 |
error("Error in swap_jobs - line size"); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
463 |
fprintf(stderr, "Error in the request: %s", |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
464 |
string); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
465 |
exit(-1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
466 |
/* WILL NOT GO FURTHER */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
467 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
468 |
warning("Wrong internal message in swap_jobs"); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
469 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
470 |
/* This will never be reached */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
471 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
472 |
} |