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