author | viric@mandarina |
Mon, 05 May 2008 23:14:22 +0200 | |
changeset 216 | b4476e12a717 |
parent 203 | 664044b1de73 |
child 218 | f084c8de313f |
permissions | -rw-r--r-- |
117 | 1 |
enum |
2 |
{ |
|
3 |
CMD_LEN=500 |
|
4 |
}; |
|
5 |
||
6 |
enum msg_types |
|
7 |
{ |
|
8 |
KILL_SERVER, |
|
9 |
NEWJOB, |
|
10 |
NEWJOB_OK, |
|
11 |
RUNJOB, |
|
12 |
RUNJOB_OK, |
|
13 |
ENDJOB, |
|
14 |
LIST, |
|
15 |
LIST_LINE, |
|
16 |
CLEAR_FINISHED, |
|
17 |
ASK_OUTPUT, |
|
18 |
ANSWER_OUTPUT, |
|
19 |
REMOVEJOB, |
|
20 |
REMOVEJOB_OK, |
|
21 |
WAITJOB, |
|
22 |
WAITJOB_OK, |
|
23 |
URGENT, |
|
24 |
URGENT_OK, |
|
25 |
GET_STATE, |
|
26 |
ANSWER_STATE, |
|
27 |
SWAP_JOBS, |
|
146 | 28 |
SWAP_JOBS_OK, |
29 |
INFO, |
|
30 |
INFO_DATA |
|
117 | 31 |
}; |
32 |
||
31 | 33 |
enum Request |
34 |
{ |
|
35 |
c_QUEUE, |
|
36 |
c_TAIL, |
|
37 |
c_KILL_SERVER, |
|
38 |
c_LIST, |
|
39 |
c_CLEAR_FINISHED, |
|
40 |
c_SHOW_HELP, |
|
37 | 41 |
c_SHOW_VERSION, |
33 | 42 |
c_CAT, |
43 |
c_SHOW_OUTPUT_FILE, |
|
35 | 44 |
c_SHOW_PID, |
42 | 45 |
c_REMOVEJOB, |
53 | 46 |
c_WAITJOB, |
63 | 47 |
c_URGENT, |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
48 |
c_GET_STATE, |
146 | 49 |
c_SWAP_JOBS, |
50 |
c_INFO |
|
31 | 51 |
}; |
52 |
||
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
53 |
struct Command_line { |
31 | 54 |
enum Request request; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
55 |
int need_server; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
56 |
int store_output; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
57 |
int should_go_background; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
58 |
int should_keep_finished; |
71 | 59 |
int send_output_by_mail; |
65 | 60 |
int gzip; |
155 | 61 |
int depend; |
71 | 62 |
int jobid; /* When queuing a job, main.c will fill it automatically from |
63 |
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
|
64 |
int jobid2; |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
65 |
struct { |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
66 |
char **array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
67 |
int num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
68 |
} command; |
150 | 69 |
char *label; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
70 |
}; |
3 | 71 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
72 |
enum Process_type { |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
73 |
CLIENT, |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
74 |
SERVER |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
75 |
}; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
76 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
77 |
extern struct Command_line command_line; |
32 | 78 |
extern int server_socket; |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
79 |
extern enum Process_type process_type; |
117 | 80 |
extern int server_socket; /* Used in the client */ |
3 | 81 |
|
82 |
struct msg; |
|
83 |
||
117 | 84 |
enum Jobstate |
85 |
{ |
|
86 |
QUEUED, |
|
87 |
RUNNING, |
|
156 | 88 |
FINISHED, |
89 |
SKIPPED |
|
117 | 90 |
}; |
91 |
||
92 |
struct msg |
|
93 |
{ |
|
94 |
enum msg_types type; |
|
95 |
||
96 |
union |
|
97 |
{ |
|
98 |
struct { |
|
99 |
int command_size; |
|
100 |
int store_output; |
|
101 |
int should_keep_finished; |
|
150 | 102 |
int label_size; |
147 | 103 |
int env_size; |
155 | 104 |
int depend; |
117 | 105 |
} newjob; |
106 |
struct { |
|
107 |
int ofilename_size; |
|
108 |
int store_output; |
|
109 |
int pid; |
|
110 |
} output; |
|
111 |
int jobid; |
|
112 |
struct Result { |
|
113 |
int errorlevel; |
|
114 |
float user_ms; |
|
115 |
float system_ms; |
|
116 |
float real_ms; |
|
156 | 117 |
int skipped; |
117 | 118 |
} result; |
146 | 119 |
int size; |
117 | 120 |
enum Jobstate state; |
121 |
struct { |
|
122 |
int jobid1; |
|
123 |
int jobid2; |
|
124 |
} swap; |
|
155 | 125 |
int last_errorlevel; |
117 | 126 |
} u; |
127 |
}; |
|
128 |
||
146 | 129 |
struct Procinfo |
130 |
{ |
|
131 |
char *ptr; |
|
132 |
int nchars; |
|
133 |
int allocchars; |
|
134 |
struct timeval enqueue_time; |
|
135 |
struct timeval start_time; |
|
136 |
struct timeval end_time; |
|
137 |
}; |
|
138 |
||
117 | 139 |
struct Job |
140 |
{ |
|
141 |
struct Job *next; |
|
142 |
int jobid; |
|
143 |
char *command; |
|
144 |
enum Jobstate state; |
|
145 |
struct Result result; /* Defined in msg.h */ |
|
146 |
char *output_filename; |
|
147 |
int store_output; |
|
148 |
int pid; |
|
149 |
int should_keep_finished; |
|
155 | 150 |
int depend; |
150 | 151 |
char *label; |
146 | 152 |
struct Procinfo info; |
117 | 153 |
}; |
154 |
||
155 |
||
3 | 156 |
/* client.c */ |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
157 |
void c_new_job(); |
8 | 158 |
void c_list_jobs(); |
44 | 159 |
void c_shutdown_server(); |
5 | 160 |
void c_wait_server_lines(); |
44 | 161 |
void c_clear_finished(); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
162 |
int c_wait_server_commands(); |
35 | 163 |
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
|
164 |
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
|
165 |
int c_cat(); |
33 | 166 |
void c_show_output_file(); |
41 | 167 |
void c_remove_job(); |
44 | 168 |
void c_show_pid(); |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
44
diff
changeset
|
169 |
int c_wait_job(); |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
173
diff
changeset
|
170 |
int c_wait_job_recv(); |
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
173
diff
changeset
|
171 |
void c_wait_job_send(); |
53 | 172 |
void c_move_urgent(); |
62 | 173 |
int c_wait_newjob_ok(); |
63 | 174 |
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
|
175 |
void c_swap_jobs(); |
146 | 176 |
void c_show_info(); |
71 | 177 |
char *build_command_string(); |
3 | 178 |
|
179 |
/* jobs.c */ |
|
180 |
void s_list(int s); |
|
18 | 181 |
int s_newjob(int s, struct msg *m); |
3 | 182 |
void s_removejob(int jobid); |
114 | 183 |
void job_finished(const struct Result *result); |
8 | 184 |
int next_run_job(); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
185 |
void s_mark_job_running(); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
186 |
void s_clear_finished(); |
35 | 187 |
void s_process_runjob_ok(int jobid, char *oname, int pid); |
32 | 188 |
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
|
189 |
int s_remove_job(int s, int jobid); |
42 | 190 |
void s_remove_notification(int s); |
44 | 191 |
void check_notify_list(int jobid); |
192 |
void s_wait_job(int s, int jobid); |
|
53 | 193 |
void s_move_urgent(int s, int jobid); |
63 | 194 |
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
|
195 |
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
|
196 |
void dump_jobs_struct(FILE *out); |
120 | 197 |
void joblist_dump(int fd); |
198 |
const char * jstate2string(enum Jobstate s); |
|
147 | 199 |
void s_job_info(int s, int jobid); |
3 | 200 |
|
201 |
/* server.c */ |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
27
diff
changeset
|
202 |
void server_main(int notify_fd, char *_path); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
203 |
void dump_conns_struct(FILE *out); |
3 | 204 |
|
205 |
/* server_start.c */ |
|
206 |
int try_connect(int s); |
|
207 |
void wait_server_up(); |
|
208 |
int ensure_server_up(); |
|
25 | 209 |
void notify_parent(int fd); |
8 | 210 |
|
211 |
/* execute.c */ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
212 |
int run_job(); |
32 | 213 |
|
33 | 214 |
/* client_run.c */ |
32 | 215 |
void c_run_tail(const char *filename); |
33 | 216 |
void c_run_cat(const char *filename); |
71 | 217 |
|
218 |
/* mail.c */ |
|
219 |
void send_mail(int jobid, int errorlevel, const char *ofname, |
|
220 |
const char *command); |
|
73 | 221 |
void hook_on_finish(int jobid, int errorlevel, const char *ofname, |
222 |
const char *command); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
223 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
224 |
/* error.c */ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
225 |
void error(const char *str, ...); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
226 |
void warning(const char *str, ...); |
95 | 227 |
|
228 |
/* signals.c */ |
|
229 |
void ignore_sigpipe(); |
|
230 |
void restore_sigmask(); |
|
138 | 231 |
void block_sigint(); |
232 |
void unblock_sigint_and_install_handler(); |
|
117 | 233 |
|
234 |
/* msg.c */ |
|
235 |
void send_bytes(const int fd, const char *data, const int bytes); |
|
236 |
int recv_bytes(const int fd, char *data, const int bytes); |
|
237 |
void send_msg(const int fd, const struct msg *m); |
|
238 |
int recv_msg(const int fd, struct msg *m); |
|
239 |
||
240 |
/* msgdump.c */ |
|
241 |
void msgdump(FILE *, const struct msg *m); |
|
242 |
||
243 |
/* error.c */ |
|
244 |
void error_msg(const struct msg *m, const char *str, ...); |
|
245 |
void warning_msg(const struct msg *m, const char *str, ...); |
|
246 |
||
247 |
/* list.c */ |
|
248 |
char * joblist_headers(); |
|
249 |
char * joblist_line(const struct Job *p); |
|
120 | 250 |
char * joblistdump_torun(const struct Job *p); |
251 |
char * joblistdump_headers(); |
|
146 | 252 |
|
253 |
/* print.c */ |
|
254 |
int fd_nprintf(int fd, int maxsize, const char *fmt, ...); |
|
255 |
||
256 |
/* info.c */ |
|
257 |
||
258 |
void pinfo_dump(const struct Procinfo *p, int fd); |
|
147 | 259 |
void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...); |
146 | 260 |
void pinfo_free(struct Procinfo *p); |
261 |
int pinfo_size(const struct Procinfo *p); |
|
262 |
void pinfo_set_enqueue_time(struct Procinfo *p); |
|
263 |
void pinfo_set_start_time(struct Procinfo *p); |
|
264 |
void pinfo_set_end_time(struct Procinfo *p); |
|
265 |
float pinfo_time_until_now(const struct Procinfo *p); |
|
266 |
float pinfo_time_run(const struct Procinfo *p); |
|
147 | 267 |
void pinfo_init(struct Procinfo *p); |
268 |
||
269 |
/* env.c */ |
|
270 |
char * get_environment(); |
|
173
b572fdd206f4
Adding some code base for our implementation of 'tail'.
viric@llimona
parents:
156
diff
changeset
|
271 |
|
b572fdd206f4
Adding some code base for our implementation of 'tail'.
viric@llimona
parents:
156
diff
changeset
|
272 |
/* 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
|
273 |
int tail_file(const char *fname, int last_lines); |