author | Lluís Batlle <viric@viric.name> |
Fri, 06 Mar 2015 23:26:50 +0100 | |
changeset 337 | 43079a99351e |
parent 329 | b01bb36b4290 |
child 340 | 11c5a9e7b9a8 |
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 |
*/ |
|
9 | 7 |
#include <stdio.h> |
44 | 8 |
#include <string.h> |
147 | 9 |
#include <unistd.h> |
44 | 10 |
#include <stdlib.h> |
11 |
#include <sys/types.h> |
|
12 |
#include <sys/socket.h> |
|
146 | 13 |
#include <sys/time.h> |
3 | 14 |
#include "main.h" |
1 | 15 |
|
110 | 16 |
static void c_end_of_job(const struct Result *res); |
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
17 |
static void c_wait_job_send(); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
18 |
static void c_wait_running_job_send(); |
8 | 19 |
|
71 | 20 |
char *build_command_string() |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
21 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
22 |
int size; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
23 |
int i; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
24 |
int num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
25 |
char **array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
26 |
char *commandstring; |
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 |
size = 0; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
29 |
num = command_line.command.num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
30 |
array = command_line.command.array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
31 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
32 |
/* Count bytes needed */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
33 |
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
|
34 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
35 |
/* 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
|
36 |
* for the null character */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
37 |
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
|
38 |
} |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
39 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
40 |
/* Alloc */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
41 |
commandstring = (char *) malloc(size); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
42 |
if(commandstring == NULL) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
43 |
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
|
44 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
45 |
/* Build the command */ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
46 |
strcpy(commandstring, array[0]); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
47 |
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
|
48 |
{ |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
49 |
strcat(commandstring, " "); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
50 |
strcat(commandstring, array[i]); |
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 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
53 |
return commandstring; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
54 |
} |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
55 |
|
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
56 |
void c_new_job() |
3 | 57 |
{ |
58 |
struct msg m; |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
59 |
char *new_command; |
147 | 60 |
char *myenv; |
3 | 61 |
|
62 |
m.type = NEWJOB; |
|
63 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
64 |
new_command = build_command_string(); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
65 |
|
147 | 66 |
myenv = get_environment(); |
67 |
||
8 | 68 |
/* global */ |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
69 |
m.u.newjob.command_size = strlen(new_command) + 1; /* add null */ |
147 | 70 |
if (myenv) |
71 |
m.u.newjob.env_size = strlen(myenv) + 1; /* add null */ |
|
72 |
else |
|
73 |
m.u.newjob.env_size = 0; |
|
150 | 74 |
if (command_line.label) |
75 |
m.u.newjob.label_size = strlen(command_line.label) + 1; /* add null */ |
|
76 |
else |
|
77 |
m.u.newjob.label_size = 0; |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
27
diff
changeset
|
78 |
m.u.newjob.store_output = command_line.store_output; |
259 | 79 |
m.u.newjob.do_depend = command_line.do_depend; |
80 |
m.u.newjob.depend_on = command_line.depend_on; |
|
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
81 |
m.u.newjob.should_keep_finished = command_line.should_keep_finished; |
147 | 82 |
m.u.newjob.command_size = strlen(new_command) + 1; /* add null */ |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
83 |
m.u.newjob.wait_enqueuing = command_line.wait_enqueuing; |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
84 |
m.u.newjob.num_slots = command_line.num_slots; |
3 | 85 |
|
18 | 86 |
/* Send the message */ |
87 |
send_msg(server_socket, &m); |
|
88 |
||
89 |
/* Send the command */ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
90 |
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
|
91 |
|
150 | 92 |
/* Send the label */ |
93 |
send_bytes(server_socket, command_line.label, m.u.newjob.label_size); |
|
94 |
||
147 | 95 |
/* Send the environment */ |
96 |
send_bytes(server_socket, myenv, m.u.newjob.env_size); |
|
97 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
98 |
free(new_command); |
147 | 99 |
free(myenv); |
3 | 100 |
} |
101 |
||
62 | 102 |
int c_wait_newjob_ok() |
103 |
{ |
|
104 |
struct msg m; |
|
105 |
int res; |
|
106 |
||
107 |
res = recv_msg(server_socket, &m); |
|
108 |
if(res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
109 |
error("Error in wait_newjob_ok"); |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
110 |
if(m.type == NEWJOB_NOK) |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
111 |
{ |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
112 |
fprintf(stderr, "Error, queue full\n"); |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
113 |
exit(EXITCODE_QUEUE_FULL); |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
114 |
} |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
115 |
if(m.type != NEWJOB_OK) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
116 |
error("Error getting the newjob_ok"); |
62 | 117 |
|
118 |
return m.u.jobid; |
|
119 |
} |
|
120 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
63
diff
changeset
|
121 |
int c_wait_server_commands() |
3 | 122 |
{ |
123 |
struct msg m; |
|
124 |
int res; |
|
125 |
||
126 |
while (1) |
|
127 |
{ |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
128 |
res = recv_msg(server_socket, &m); |
3 | 129 |
if(res == -1) |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
130 |
error("Error in wait_server_commands"); |
3 | 131 |
|
132 |
if (res == 0) |
|
133 |
break; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
134 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
135 |
error("Error in wait_server_commands"); |
8 | 136 |
if (m.type == RUNJOB) |
5 | 137 |
{ |
110 | 138 |
struct Result res; |
156 | 139 |
res.skipped = 0; |
155 | 140 |
/* These will send RUNJOB_OK */ |
259 | 141 |
if (command_line.do_depend && m.u.last_errorlevel != 0) |
156 | 142 |
{ |
143 |
res.errorlevel = -1; |
|
144 |
res.user_ms = 0.; |
|
145 |
res.system_ms = 0.; |
|
146 |
res.real_ms = 0.; |
|
147 |
res.skipped = 1; |
|
148 |
c_send_runjob_ok(0, -1); |
|
149 |
} |
|
150 |
else |
|
151 |
run_job(&res); |
|
110 | 152 |
c_end_of_job(&res); |
153 |
return res.errorlevel; |
|
5 | 154 |
} |
155 |
} |
|
38
768d009604b3
The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents:
35
diff
changeset
|
156 |
return -1; |
5 | 157 |
} |
158 |
||
159 |
void c_wait_server_lines() |
|
160 |
{ |
|
161 |
struct msg m; |
|
162 |
int res; |
|
163 |
||
164 |
while (1) |
|
165 |
{ |
|
21 | 166 |
res = recv_msg(server_socket, &m); |
5 | 167 |
if(res == -1) |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
168 |
error("Error in wait_server_lines"); |
5 | 169 |
|
170 |
if (res == 0) |
|
171 |
break; |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
172 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
173 |
error("Error in wait_server_lines 2"); |
5 | 174 |
if (m.type == LIST_LINE) |
175 |
{ |
|
21 | 176 |
char * buffer; |
146 | 177 |
buffer = (char *) malloc(m.u.size); |
178 |
recv_bytes(server_socket, buffer, m.u.size); |
|
21 | 179 |
printf("%s", buffer); |
180 |
free(buffer); |
|
5 | 181 |
} |
3 | 182 |
} |
183 |
} |
|
184 |
||
8 | 185 |
void c_list_jobs() |
3 | 186 |
{ |
187 |
struct msg m; |
|
188 |
||
189 |
m.type = LIST; |
|
190 |
||
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
191 |
send_msg(server_socket, &m); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
192 |
} |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
193 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
194 |
/* Exits if wrong */ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
195 |
void c_check_version() |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
196 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
197 |
struct msg m; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
198 |
int res; |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
199 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
200 |
m.type = GET_VERSION; |
282
835551fcecb7
Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents:
276
diff
changeset
|
201 |
/* Double send, so an old ts will answer for sure at least once */ |
835551fcecb7
Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents:
276
diff
changeset
|
202 |
send_msg(server_socket, &m); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
203 |
send_msg(server_socket, &m); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
204 |
|
265
8c16cd53f772
Making the check_version coep well with old ts servers.
viric@mandarina
parents:
260
diff
changeset
|
205 |
/* Set up a 2 second timeout to receive the |
8c16cd53f772
Making the check_version coep well with old ts servers.
viric@mandarina
parents:
260
diff
changeset
|
206 |
version msg. */ |
8c16cd53f772
Making the check_version coep well with old ts servers.
viric@mandarina
parents:
260
diff
changeset
|
207 |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
208 |
res = recv_msg(server_socket, &m); |
329
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
209 |
if(res == -1) |
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
210 |
error("Error calling recv_msg in c_check_version"); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
211 |
if (m.type != VERSION || m.u.version != PROTOCOL_VERSION) |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
212 |
{ |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
213 |
printf("Wrong server version. Received %i, expecting %i\n", |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
214 |
m.u.version, PROTOCOL_VERSION); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
215 |
|
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
216 |
error("Wrong server version. Received %i, expecting %i", |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
217 |
m.u.version, PROTOCOL_VERSION); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
218 |
} |
282
835551fcecb7
Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents:
276
diff
changeset
|
219 |
|
835551fcecb7
Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents:
276
diff
changeset
|
220 |
/* Receive also the 2nd send_msg if we got the right version */ |
835551fcecb7
Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents:
276
diff
changeset
|
221 |
res = recv_msg(server_socket, &m); |
329
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
222 |
if(res == -1) |
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
223 |
error("Error calling the 2nd recv_msg in c_check_version"); |
3 | 224 |
} |
225 |
||
146 | 226 |
void c_show_info() |
227 |
{ |
|
228 |
struct msg m; |
|
229 |
int res; |
|
230 |
||
231 |
m.type = INFO; |
|
232 |
m.u.jobid = command_line.jobid; |
|
233 |
||
234 |
send_msg(server_socket, &m); |
|
235 |
||
236 |
while (1) |
|
237 |
{ |
|
238 |
res = recv_msg(server_socket, &m); |
|
239 |
if(res == -1) |
|
240 |
error("Error in wait_server_lines"); |
|
241 |
||
242 |
if (res == 0) |
|
243 |
break; |
|
244 |
if(res != sizeof(m)) |
|
245 |
error("Error in wait_server_lines 2"); |
|
246 |
if (m.type == INFO_DATA) |
|
247 |
{ |
|
248 |
char * buffer; |
|
249 |
enum { DSIZE = 1000 }; |
|
250 |
||
147 | 251 |
/* We're going to output data using the stdout fd */ |
252 |
fflush(stdout); |
|
146 | 253 |
buffer = (char *) malloc(DSIZE); |
254 |
do |
|
255 |
{ |
|
256 |
res = recv(server_socket, buffer, DSIZE, 0); |
|
257 |
if (res > 0) |
|
147 | 258 |
write(1, buffer, res); |
146 | 259 |
} while(res > 0); |
260 |
free(buffer); |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
||
35 | 265 |
void c_send_runjob_ok(const char *ofname, int pid) |
22 | 266 |
{ |
267 |
struct msg m; |
|
268 |
||
269 |
/* Prepare the message */ |
|
270 |
m.type = RUNJOB_OK; |
|
155 | 271 |
if (ofname) /* ofname == 0, skipped execution */ |
272 |
m.u.output.store_output = command_line.store_output; |
|
273 |
else |
|
274 |
m.u.output.store_output = 0; |
|
35 | 275 |
m.u.output.pid = pid; |
155 | 276 |
if (m.u.output.store_output) |
32 | 277 |
m.u.output.ofilename_size = strlen(ofname) + 1; |
22 | 278 |
else |
32 | 279 |
m.u.output.ofilename_size = 0; |
22 | 280 |
|
281 |
send_msg(server_socket, &m); |
|
282 |
||
283 |
/* Send the filename */ |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
27
diff
changeset
|
284 |
if (command_line.store_output) |
32 | 285 |
send_bytes(server_socket, ofname, m.u.output.ofilename_size); |
22 | 286 |
} |
287 |
||
110 | 288 |
static void c_end_of_job(const struct Result *res) |
8 | 289 |
{ |
290 |
struct msg m; |
|
291 |
||
292 |
m.type = ENDJOB; |
|
110 | 293 |
m.u.result = *res; /* struct copy */ |
8 | 294 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
295 |
send_msg(server_socket, &m); |
8 | 296 |
} |
297 |
||
44 | 298 |
void c_shutdown_server() |
1 | 299 |
{ |
2 | 300 |
struct msg m; |
1 | 301 |
|
31 | 302 |
m.type = KILL_SERVER; |
32 | 303 |
send_msg(server_socket, &m); |
1 | 304 |
} |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
305 |
|
44 | 306 |
void c_clear_finished() |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
307 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
308 |
struct msg m; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
309 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
310 |
m.type = CLEAR_FINISHED; |
32 | 311 |
send_msg(server_socket, &m); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
312 |
} |
32 | 313 |
|
35 | 314 |
static char * get_output_file(int *pid) |
32 | 315 |
{ |
316 |
struct msg m; |
|
317 |
int res; |
|
318 |
char *string = 0; |
|
319 |
||
320 |
/* Send the request */ |
|
321 |
m.type = ASK_OUTPUT; |
|
322 |
m.u.jobid = command_line.jobid; |
|
323 |
send_msg(server_socket, &m); |
|
324 |
||
325 |
/* Receive the answer */ |
|
326 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
327 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
328 |
error("Error in get_output_file"); |
32 | 329 |
switch(m.type) |
330 |
{ |
|
331 |
case ANSWER_OUTPUT: |
|
332 |
if (m.u.output.store_output) |
|
333 |
{ |
|
334 |
/* Receive the output file name */ |
|
146 | 335 |
string = 0; |
336 |
if (m.u.output.ofilename_size > 0) |
|
337 |
{ |
|
338 |
string = (char *) malloc(m.u.output.ofilename_size); |
|
339 |
recv_bytes(server_socket, string, m.u.output.ofilename_size); |
|
340 |
} |
|
35 | 341 |
*pid = m.u.output.pid; |
33 | 342 |
return string; |
32 | 343 |
} |
35 | 344 |
*pid = m.u.output.pid; |
345 |
return 0; |
|
32 | 346 |
/* WILL NOT GO FURTHER */ |
347 |
case LIST_LINE: /* Only ONE line accepted */ |
|
146 | 348 |
string = (char *) malloc(m.u.size); |
349 |
res = recv_bytes(server_socket, string, m.u.size); |
|
350 |
if(res != m.u.size) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
351 |
error("Error in get_output_file line size"); |
32 | 352 |
fprintf(stderr, "Error in the request: %s", |
353 |
string); |
|
354 |
exit(-1); |
|
355 |
/* WILL NOT GO FURTHER */ |
|
44 | 356 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
357 |
warning("Wrong internal message in get_output_file line size"); |
32 | 358 |
} |
33 | 359 |
/* This will never be reached */ |
360 |
return 0; |
|
32 | 361 |
} |
33 | 362 |
|
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
363 |
int c_tail() |
33 | 364 |
{ |
365 |
char *str; |
|
35 | 366 |
int pid; |
367 |
str = get_output_file(&pid); |
|
368 |
if (str == 0) |
|
369 |
{ |
|
370 |
fprintf(stderr, "The output is not stored. Cannot tail.\n"); |
|
371 |
exit(-1); |
|
372 |
} |
|
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
373 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
374 |
c_wait_running_job_send(); |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
375 |
|
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
180
diff
changeset
|
376 |
return tail_file(str, 10 /* Last lines to show */); |
33 | 377 |
} |
378 |
||
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
180
diff
changeset
|
379 |
int c_cat() |
33 | 380 |
{ |
381 |
char *str; |
|
35 | 382 |
int pid; |
383 |
str = get_output_file(&pid); |
|
384 |
if (str == 0) |
|
385 |
{ |
|
153 | 386 |
fprintf(stderr, "The output is not stored. Cannot cat.\n"); |
35 | 387 |
exit(-1); |
388 |
} |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
389 |
c_wait_running_job_send(); |
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
180
diff
changeset
|
390 |
|
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
180
diff
changeset
|
391 |
return tail_file(str, -1 /* All the lines */); |
33 | 392 |
} |
393 |
||
394 |
void c_show_output_file() |
|
395 |
{ |
|
396 |
char *str; |
|
35 | 397 |
int pid; |
398 |
/* This will exit if there is any error */ |
|
399 |
str = get_output_file(&pid); |
|
400 |
if (str == 0) |
|
401 |
{ |
|
146 | 402 |
fprintf(stderr, "The output is not stored.\n"); |
35 | 403 |
exit(-1); |
404 |
} |
|
33 | 405 |
printf("%s\n", str); |
35 | 406 |
free(str); |
33 | 407 |
} |
35 | 408 |
|
409 |
void c_show_pid() |
|
410 |
{ |
|
411 |
int pid; |
|
412 |
/* This will exit if there is any error */ |
|
329
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
315
diff
changeset
|
413 |
get_output_file(&pid); |
35 | 414 |
printf("%i\n", pid); |
415 |
} |
|
41 | 416 |
|
417 |
void c_remove_job() |
|
418 |
{ |
|
419 |
struct msg m; |
|
420 |
int res; |
|
421 |
char *string = 0; |
|
422 |
||
423 |
/* Send the request */ |
|
424 |
m.type = REMOVEJOB; |
|
425 |
m.u.jobid = command_line.jobid; |
|
426 |
send_msg(server_socket, &m); |
|
427 |
||
428 |
/* Receive the answer */ |
|
429 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
430 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
431 |
error("Error in remove_job"); |
41 | 432 |
switch(m.type) |
433 |
{ |
|
434 |
case REMOVEJOB_OK: |
|
435 |
return; |
|
436 |
/* WILL NOT GO FURTHER */ |
|
437 |
case LIST_LINE: /* Only ONE line accepted */ |
|
146 | 438 |
string = (char *) malloc(m.u.size); |
439 |
res = recv_bytes(server_socket, string, m.u.size); |
|
41 | 440 |
fprintf(stderr, "Error in the request: %s", |
441 |
string); |
|
442 |
exit(-1); |
|
443 |
/* WILL NOT GO FURTHER */ |
|
44 | 444 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
445 |
warning("Wrong internal message in remove_job"); |
41 | 446 |
} |
447 |
/* This will never be reached */ |
|
448 |
} |
|
42 | 449 |
|
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
450 |
int c_wait_job_recv() |
42 | 451 |
{ |
452 |
struct msg m; |
|
453 |
int res; |
|
454 |
char *string = 0; |
|
455 |
||
456 |
/* Receive the answer */ |
|
457 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
458 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
459 |
error("Error in wait_job"); |
42 | 460 |
switch(m.type) |
461 |
{ |
|
462 |
case WAITJOB_OK: |
|
110 | 463 |
return m.u.result.errorlevel; |
42 | 464 |
/* WILL NOT GO FURTHER */ |
465 |
case LIST_LINE: /* Only ONE line accepted */ |
|
146 | 466 |
string = (char *) malloc(m.u.size); |
467 |
res = recv_bytes(server_socket, string, m.u.size); |
|
468 |
if(res != m.u.size) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
469 |
error("Error in wait_job - line size"); |
42 | 470 |
fprintf(stderr, "Error in the request: %s", |
471 |
string); |
|
472 |
exit(-1); |
|
473 |
/* WILL NOT GO FURTHER */ |
|
44 | 474 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
475 |
warning("Wrong internal message in c_wait_job"); |
42 | 476 |
} |
477 |
/* This will never be reached */ |
|
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
478 |
return -1; |
42 | 479 |
} |
53 | 480 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
481 |
static void c_wait_job_send() |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
482 |
{ |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
483 |
struct msg m; |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
484 |
|
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
485 |
/* Send the request */ |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
486 |
m.type = WAITJOB; |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
487 |
m.u.jobid = command_line.jobid; |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
488 |
send_msg(server_socket, &m); |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
489 |
} |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
490 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
491 |
static void c_wait_running_job_send() |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
492 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
493 |
struct msg m; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
494 |
|
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
495 |
/* Send the request */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
496 |
m.type = WAIT_RUNNING_JOB; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
497 |
m.u.jobid = command_line.jobid; |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
498 |
send_msg(server_socket, &m); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
499 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
500 |
|
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
501 |
/* Returns the errorlevel */ |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
502 |
int c_wait_job() |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
503 |
{ |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
504 |
c_wait_job_send(); |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
505 |
return c_wait_job_recv(); |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
506 |
} |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
156
diff
changeset
|
507 |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
508 |
/* Returns the errorlevel */ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
509 |
int c_wait_running_job() |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
510 |
{ |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
511 |
c_wait_running_job_send(); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
512 |
return c_wait_job_recv(); |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
513 |
} |
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
514 |
|
219 | 515 |
void c_send_max_slots(int max_slots) |
516 |
{ |
|
517 |
struct msg m; |
|
518 |
||
519 |
/* Send the request */ |
|
520 |
m.type = SET_MAX_SLOTS; |
|
521 |
m.u.max_slots = command_line.max_slots; |
|
522 |
send_msg(server_socket, &m); |
|
523 |
} |
|
524 |
||
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
525 |
void c_get_max_slots() |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
526 |
{ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
527 |
struct msg m; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
528 |
int res; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
529 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
530 |
/* Send the request */ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
531 |
m.type = GET_MAX_SLOTS; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
532 |
m.u.max_slots = command_line.max_slots; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
533 |
send_msg(server_socket, &m); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
534 |
|
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
535 |
/* Receive the answer */ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
536 |
res = recv_msg(server_socket, &m); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
537 |
if(res != sizeof(m)) |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
538 |
error("Error in move_urgent"); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
539 |
switch(m.type) |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
540 |
{ |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
541 |
case GET_MAX_SLOTS_OK: |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
542 |
printf("%i\n", m.u.max_slots); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
543 |
return; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
544 |
default: |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
545 |
warning("Wrong internal message in get_max_slots"); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
546 |
} |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
547 |
} |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
231
diff
changeset
|
548 |
|
53 | 549 |
void c_move_urgent() |
550 |
{ |
|
551 |
struct msg m; |
|
552 |
int res; |
|
553 |
char *string = 0; |
|
554 |
||
555 |
/* Send the request */ |
|
556 |
m.type = URGENT; |
|
557 |
m.u.jobid = command_line.jobid; |
|
558 |
send_msg(server_socket, &m); |
|
559 |
||
560 |
/* Receive the answer */ |
|
561 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
562 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
563 |
error("Error in move_urgent"); |
53 | 564 |
switch(m.type) |
565 |
{ |
|
566 |
case URGENT_OK: |
|
567 |
return; |
|
568 |
/* WILL NOT GO FURTHER */ |
|
569 |
case LIST_LINE: /* Only ONE line accepted */ |
|
146 | 570 |
string = (char *) malloc(m.u.size); |
571 |
res = recv_bytes(server_socket, string, m.u.size); |
|
572 |
if(res != m.u.size) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
573 |
error("Error in move_urgent - line size"); |
53 | 574 |
fprintf(stderr, "Error in the request: %s", |
575 |
string); |
|
576 |
exit(-1); |
|
577 |
/* WILL NOT GO FURTHER */ |
|
578 |
default: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
579 |
warning("Wrong internal message in move_urgent"); |
53 | 580 |
} |
581 |
/* This will never be reached */ |
|
582 |
return; |
|
583 |
} |
|
63 | 584 |
|
585 |
void c_get_state() |
|
586 |
{ |
|
587 |
struct msg m; |
|
588 |
int res; |
|
589 |
char *string = 0; |
|
590 |
||
591 |
/* Send the request */ |
|
592 |
m.type = GET_STATE; |
|
593 |
m.u.jobid = command_line.jobid; |
|
594 |
send_msg(server_socket, &m); |
|
595 |
||
596 |
/* Receive the answer */ |
|
597 |
res = recv_msg(server_socket, &m); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
598 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
599 |
error("Error in get_state - line size"); |
63 | 600 |
switch(m.type) |
601 |
{ |
|
602 |
case ANSWER_STATE: |
|
603 |
printf("%s\n", jstate2string(m.u.state)); |
|
604 |
return; |
|
605 |
/* WILL NOT GO FURTHER */ |
|
606 |
case LIST_LINE: /* Only ONE line accepted */ |
|
146 | 607 |
string = (char *) malloc(m.u.size); |
608 |
res = recv_bytes(server_socket, string, m.u.size); |
|
609 |
if(res != m.u.size) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
610 |
error("Error in get_state - line size"); |
63 | 611 |
fprintf(stderr, "Error in the request: %s", |
612 |
string); |
|
613 |
exit(-1); |
|
614 |
/* WILL NOT GO FURTHER */ |
|
615 |
default: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
616 |
warning("Wrong internal message in get_state"); |
63 | 617 |
} |
618 |
/* This will never be reached */ |
|
619 |
return; |
|
620 |
} |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
621 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
622 |
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
|
623 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
624 |
struct msg m; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
625 |
int res; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
626 |
char *string = 0; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
627 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
628 |
/* Send the request */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
629 |
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
|
630 |
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
|
631 |
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
|
632 |
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
|
633 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
634 |
/* Receive the answer */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
635 |
res = recv_msg(server_socket, &m); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
636 |
if(res != sizeof(m)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
637 |
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
|
638 |
switch(m.type) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
639 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
640 |
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
|
641 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
642 |
/* 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
|
643 |
case LIST_LINE: /* Only ONE line accepted */ |
146 | 644 |
string = (char *) malloc(m.u.size); |
645 |
res = recv_bytes(server_socket, string, m.u.size); |
|
646 |
if(res != m.u.size) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
647 |
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
|
648 |
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
|
649 |
string); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
650 |
exit(-1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
651 |
/* 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
|
652 |
default: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
71
diff
changeset
|
653 |
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
|
654 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
655 |
/* 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
|
656 |
return; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
63
diff
changeset
|
657 |
} |