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