author | viric <viriketo@gmail.com> |
Sat, 26 May 2012 16:51:50 +0200 | |
branch | jobslots |
changeset 321 | f11428870f06 |
parent 315 | 2b3ed8fdfb12 |
child 328 | 7f066fdc43c5 |
permissions | -rw-r--r-- |
117 | 1 |
enum |
2 |
{ |
|
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
3 |
CMD_LEN=500, |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
314
diff
changeset
|
4 |
PROTOCOL_VERSION=710 |
117 | 5 |
}; |
6 |
||
7 |
enum msg_types |
|
8 |
{ |
|
9 |
KILL_SERVER, |
|
10 |
NEWJOB, |
|
11 |
NEWJOB_OK, |
|
12 |
RUNJOB, |
|
13 |
RUNJOB_OK, |
|
14 |
ENDJOB, |
|
15 |
LIST, |
|
16 |
LIST_LINE, |
|
17 |
CLEAR_FINISHED, |
|
18 |
ASK_OUTPUT, |
|
19 |
ANSWER_OUTPUT, |
|
20 |
REMOVEJOB, |
|
21 |
REMOVEJOB_OK, |
|
22 |
WAITJOB, |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
23 |
WAIT_RUNNING_JOB, |
117 | 24 |
WAITJOB_OK, |
25 |
URGENT, |
|
26 |
URGENT_OK, |
|
27 |
GET_STATE, |
|
28 |
ANSWER_STATE, |
|
29 |
SWAP_JOBS, |
|
146 | 30 |
SWAP_JOBS_OK, |
31 |
INFO, |
|
219 | 32 |
INFO_DATA, |
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
33 |
SET_MAX_SLOTS, |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
34 |
GET_MAX_SLOTS, |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
35 |
GET_MAX_SLOTS_OK, |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
36 |
GET_VERSION, |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
37 |
VERSION, |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
38 |
NEWJOB_NOK |
117 | 39 |
}; |
40 |
||
31 | 41 |
enum Request |
42 |
{ |
|
43 |
c_QUEUE, |
|
44 |
c_TAIL, |
|
45 |
c_KILL_SERVER, |
|
46 |
c_LIST, |
|
47 |
c_CLEAR_FINISHED, |
|
48 |
c_SHOW_HELP, |
|
37 | 49 |
c_SHOW_VERSION, |
33 | 50 |
c_CAT, |
51 |
c_SHOW_OUTPUT_FILE, |
|
35 | 52 |
c_SHOW_PID, |
42 | 53 |
c_REMOVEJOB, |
53 | 54 |
c_WAITJOB, |
63 | 55 |
c_URGENT, |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
56 |
c_GET_STATE, |
146 | 57 |
c_SWAP_JOBS, |
219 | 58 |
c_INFO, |
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
59 |
c_SET_MAX_SLOTS, |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
60 |
c_GET_MAX_SLOTS |
31 | 61 |
}; |
62 |
||
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
63 |
struct Command_line { |
31 | 64 |
enum Request request; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
65 |
int need_server; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
66 |
int store_output; |
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Ć mydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
67 |
int stderr_apart; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
68 |
int should_go_background; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
69 |
int should_keep_finished; |
71 | 70 |
int send_output_by_mail; |
65 | 71 |
int gzip; |
259 | 72 |
int do_depend; |
73 |
int depend_on; /* -1 means depend on previous */ |
|
219 | 74 |
int max_slots; /* How many jobs to run at once */ |
71 | 75 |
int jobid; /* When queuing a job, main.c will fill it automatically from |
76 |
the server answer to NEWJOB */ |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
77 |
int jobid2; |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
78 |
int wait_enqueuing; |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
79 |
struct { |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
80 |
char **array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
81 |
int num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
82 |
} command; |
150 | 83 |
char *label; |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
314
diff
changeset
|
84 |
int num_slots; /* Slots for the job to use. Default 1 */ |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
85 |
}; |
3 | 86 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
87 |
enum Process_type { |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
88 |
CLIENT, |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
89 |
SERVER |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
90 |
}; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
91 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
92 |
extern struct Command_line command_line; |
32 | 93 |
extern int server_socket; |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
94 |
extern enum Process_type process_type; |
117 | 95 |
extern int server_socket; /* Used in the client */ |
3 | 96 |
|
97 |
struct msg; |
|
98 |
||
117 | 99 |
enum Jobstate |
100 |
{ |
|
101 |
QUEUED, |
|
102 |
RUNNING, |
|
156 | 103 |
FINISHED, |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
104 |
SKIPPED, |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
105 |
HOLDING_CLIENT |
117 | 106 |
}; |
107 |
||
108 |
struct msg |
|
109 |
{ |
|
110 |
enum msg_types type; |
|
111 |
||
112 |
union |
|
113 |
{ |
|
114 |
struct { |
|
115 |
int command_size; |
|
116 |
int store_output; |
|
117 |
int should_keep_finished; |
|
150 | 118 |
int label_size; |
147 | 119 |
int env_size; |
259 | 120 |
int do_depend; |
121 |
int depend_on; /* -1 means depend on previous */ |
|
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
122 |
int wait_enqueuing; |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
314
diff
changeset
|
123 |
int num_slots; |
117 | 124 |
} newjob; |
125 |
struct { |
|
126 |
int ofilename_size; |
|
127 |
int store_output; |
|
128 |
int pid; |
|
129 |
} output; |
|
130 |
int jobid; |
|
131 |
struct Result { |
|
132 |
int errorlevel; |
|
246
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
235
diff
changeset
|
133 |
int died_by_signal; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
235
diff
changeset
|
134 |
int signal; |
117 | 135 |
float user_ms; |
136 |
float system_ms; |
|
137 |
float real_ms; |
|
156 | 138 |
int skipped; |
117 | 139 |
} result; |
146 | 140 |
int size; |
117 | 141 |
enum Jobstate state; |
142 |
struct { |
|
143 |
int jobid1; |
|
144 |
int jobid2; |
|
145 |
} swap; |
|
314 | 146 |
int last_errorlevel; |
147 |
int max_slots; |
|
148 |
int version; |
|
117 | 149 |
} u; |
150 |
}; |
|
151 |
||
146 | 152 |
struct Procinfo |
153 |
{ |
|
154 |
char *ptr; |
|
155 |
int nchars; |
|
156 |
int allocchars; |
|
157 |
struct timeval enqueue_time; |
|
158 |
struct timeval start_time; |
|
159 |
struct timeval end_time; |
|
160 |
}; |
|
161 |
||
117 | 162 |
struct Job |
163 |
{ |
|
164 |
struct Job *next; |
|
165 |
int jobid; |
|
166 |
char *command; |
|
167 |
enum Jobstate state; |
|
168 |
struct Result result; /* Defined in msg.h */ |
|
169 |
char *output_filename; |
|
170 |
int store_output; |
|
171 |
int pid; |
|
172 |
int should_keep_finished; |
|
259 | 173 |
int do_depend; |
218 | 174 |
int depend_on; |
259 | 175 |
int *notify_errorlevel_to; |
176 |
int notify_errorlevel_to_size; |
|
218 | 177 |
int dependency_errorlevel; |
150 | 178 |
char *label; |
146 | 179 |
struct Procinfo info; |
315
2b3ed8fdfb12
Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents:
314
diff
changeset
|
180 |
int num_slots; |
117 | 181 |
}; |
182 |
||
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
183 |
enum ExitCodes |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
184 |
{ |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
185 |
EXITCODE_OK = 0, |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
186 |
EXITCODE_UNKNOWN_ERROR = -1, |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
187 |
EXITCODE_QUEUE_FULL = 2 |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
188 |
}; |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
287
diff
changeset
|
189 |
|
117 | 190 |
|
3 | 191 |
/* client.c */ |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
192 |
void c_new_job(); |
8 | 193 |
void c_list_jobs(); |
44 | 194 |
void c_shutdown_server(); |
5 | 195 |
void c_wait_server_lines(); |
44 | 196 |
void c_clear_finished(); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
197 |
int c_wait_server_commands(); |
35 | 198 |
void c_send_runjob_ok(const char *ofname, int pid); |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
173
diff
changeset
|
199 |
int c_tail(); |
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
174
diff
changeset
|
200 |
int c_cat(); |
33 | 201 |
void c_show_output_file(); |
41 | 202 |
void c_remove_job(); |
44 | 203 |
void c_show_pid(); |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
44
diff
changeset
|
204 |
int c_wait_job(); |
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
205 |
int c_wait_running_job(); |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
173
diff
changeset
|
206 |
int c_wait_job_recv(); |
53 | 207 |
void c_move_urgent(); |
62 | 208 |
int c_wait_newjob_ok(); |
63 | 209 |
void c_get_state(); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
210 |
void c_swap_jobs(); |
146 | 211 |
void c_show_info(); |
71 | 212 |
char *build_command_string(); |
219 | 213 |
void c_send_max_slots(int max_slots); |
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
214 |
void c_get_max_slots(); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
215 |
void c_check_version(); |
3 | 216 |
|
217 |
/* jobs.c */ |
|
218 |
void s_list(int s); |
|
18 | 219 |
int s_newjob(int s, struct msg *m); |
3 | 220 |
void s_removejob(int jobid); |
218 | 221 |
void job_finished(const struct Result *result, int jobid); |
8 | 222 |
int next_run_job(); |
218 | 223 |
void s_mark_job_running(int jobid); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
224 |
void s_clear_finished(); |
35 | 225 |
void s_process_runjob_ok(int jobid, char *oname, int pid); |
32 | 226 |
void s_send_output(int socket, int jobid); |
134
5a6b8bb1f7a8
Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents:
120
diff
changeset
|
227 |
int s_remove_job(int s, int jobid); |
42 | 228 |
void s_remove_notification(int s); |
44 | 229 |
void check_notify_list(int jobid); |
230 |
void s_wait_job(int s, int jobid); |
|
226
472ab90fd6a1
Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents:
219
diff
changeset
|
231 |
void s_wait_running_job(int s, int jobid); |
53 | 232 |
void s_move_urgent(int s, int jobid); |
63 | 233 |
void s_send_state(int s, int jobid); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
234 |
void s_swap_jobs(int s, int jobid1, int jobid2); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
235 |
void dump_jobs_struct(FILE *out); |
254
41252d5e85f5
Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents:
253
diff
changeset
|
236 |
void dump_notifies_struct(FILE *out); |
120 | 237 |
void joblist_dump(int fd); |
238 |
const char * jstate2string(enum Jobstate s); |
|
147 | 239 |
void s_job_info(int s, int jobid); |
218 | 240 |
void s_send_runjob(int s, int jobid); |
219 | 241 |
void s_set_max_slots(int new_max_slots); |
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
252
diff
changeset
|
242 |
void s_get_max_slots(int s); |
252
f0af96f58947
Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents:
251
diff
changeset
|
243 |
int job_is_running(int jobid); |
287
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
244 |
int job_is_holding_client(int jobid); |
b3c38ff8f41a
An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents:
282
diff
changeset
|
245 |
int wake_hold_client(); |
3 | 246 |
|
247 |
/* server.c */ |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
27
diff
changeset
|
248 |
void server_main(int notify_fd, char *_path); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
249 |
void dump_conns_struct(FILE *out); |
3 | 250 |
|
251 |
/* server_start.c */ |
|
252 |
int try_connect(int s); |
|
253 |
void wait_server_up(); |
|
254 |
int ensure_server_up(); |
|
25 | 255 |
void notify_parent(int fd); |
251
5e0802df5788
Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents:
246
diff
changeset
|
256 |
void create_socket_path(char **path); |
8 | 257 |
|
258 |
/* execute.c */ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
259 |
int run_job(); |
32 | 260 |
|
33 | 261 |
/* client_run.c */ |
32 | 262 |
void c_run_tail(const char *filename); |
33 | 263 |
void c_run_cat(const char *filename); |
71 | 264 |
|
265 |
/* mail.c */ |
|
266 |
void send_mail(int jobid, int errorlevel, const char *ofname, |
|
267 |
const char *command); |
|
73 | 268 |
void hook_on_finish(int jobid, int errorlevel, const char *ofname, |
269 |
const char *command); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
270 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
271 |
/* error.c */ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
272 |
void error(const char *str, ...); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
273 |
void warning(const char *str, ...); |
95 | 274 |
|
275 |
/* signals.c */ |
|
276 |
void ignore_sigpipe(); |
|
277 |
void restore_sigmask(); |
|
138 | 278 |
void block_sigint(); |
279 |
void unblock_sigint_and_install_handler(); |
|
117 | 280 |
|
281 |
/* msg.c */ |
|
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
226
diff
changeset
|
282 |
void send_bytes(const int fd, const char *data, int bytes); |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
226
diff
changeset
|
283 |
int recv_bytes(const int fd, char *data, int bytes); |
117 | 284 |
void send_msg(const int fd, const struct msg *m); |
285 |
int recv_msg(const int fd, struct msg *m); |
|
286 |
||
287 |
/* msgdump.c */ |
|
288 |
void msgdump(FILE *, const struct msg *m); |
|
289 |
||
290 |
/* error.c */ |
|
291 |
void error_msg(const struct msg *m, const char *str, ...); |
|
292 |
void warning_msg(const struct msg *m, const char *str, ...); |
|
293 |
||
294 |
/* list.c */ |
|
295 |
char * joblist_headers(); |
|
296 |
char * joblist_line(const struct Job *p); |
|
120 | 297 |
char * joblistdump_torun(const struct Job *p); |
298 |
char * joblistdump_headers(); |
|
146 | 299 |
|
300 |
/* print.c */ |
|
301 |
int fd_nprintf(int fd, int maxsize, const char *fmt, ...); |
|
302 |
||
303 |
/* info.c */ |
|
304 |
||
305 |
void pinfo_dump(const struct Procinfo *p, int fd); |
|
147 | 306 |
void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...); |
146 | 307 |
void pinfo_free(struct Procinfo *p); |
308 |
int pinfo_size(const struct Procinfo *p); |
|
309 |
void pinfo_set_enqueue_time(struct Procinfo *p); |
|
310 |
void pinfo_set_start_time(struct Procinfo *p); |
|
311 |
void pinfo_set_end_time(struct Procinfo *p); |
|
312 |
float pinfo_time_until_now(const struct Procinfo *p); |
|
313 |
float pinfo_time_run(const struct Procinfo *p); |
|
147 | 314 |
void pinfo_init(struct Procinfo *p); |
315 |
||
316 |
/* env.c */ |
|
317 |
char * get_environment(); |
|
173
b572fdd206f4
Adding some code base for our implementation of 'tail'.
viric@llimona
parents:
156
diff
changeset
|
318 |
|
b572fdd206f4
Adding some code base for our implementation of 'tail'.
viric@llimona
parents:
156
diff
changeset
|
319 |
/* tail.c */ |
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
174
diff
changeset
|
320 |
int tail_file(const char *fname, int last_lines); |