author | viric@llimona |
Fri, 13 Apr 2007 20:52:28 +0200 | |
changeset 127 | c620eacd7630 |
parent 120 | 790bc4cecd3b |
child 134 | 5a6b8bb1f7a8 |
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, |
|
28 |
SWAP_JOBS_OK |
|
29 |
}; |
|
30 |
||
31 | 31 |
enum Request |
32 |
{ |
|
33 |
c_QUEUE, |
|
34 |
c_TAIL, |
|
35 |
c_KILL_SERVER, |
|
36 |
c_LIST, |
|
37 |
c_CLEAR_FINISHED, |
|
38 |
c_SHOW_HELP, |
|
37 | 39 |
c_SHOW_VERSION, |
33 | 40 |
c_CAT, |
41 |
c_SHOW_OUTPUT_FILE, |
|
35 | 42 |
c_SHOW_PID, |
42 | 43 |
c_REMOVEJOB, |
53 | 44 |
c_WAITJOB, |
63 | 45 |
c_URGENT, |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
46 |
c_GET_STATE, |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
47 |
c_SWAP_JOBS |
31 | 48 |
}; |
49 |
||
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
50 |
struct Command_line { |
31 | 51 |
enum Request request; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
52 |
int need_server; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
53 |
int store_output; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
54 |
int should_go_background; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
55 |
int should_keep_finished; |
71 | 56 |
int send_output_by_mail; |
65 | 57 |
int gzip; |
71 | 58 |
int jobid; /* When queuing a job, main.c will fill it automatically from |
59 |
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
|
60 |
int jobid2; |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
61 |
struct { |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
62 |
char **array; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
63 |
int num; |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
64 |
} command; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
65 |
}; |
3 | 66 |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
67 |
enum Process_type { |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
68 |
CLIENT, |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
69 |
SERVER |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
70 |
}; |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
71 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
72 |
extern struct Command_line command_line; |
32 | 73 |
extern int server_socket; |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
74 |
extern enum Process_type process_type; |
117 | 75 |
extern int server_socket; /* Used in the client */ |
3 | 76 |
|
77 |
struct msg; |
|
78 |
||
117 | 79 |
enum Jobstate |
80 |
{ |
|
81 |
QUEUED, |
|
82 |
RUNNING, |
|
83 |
FINISHED |
|
84 |
}; |
|
85 |
||
86 |
struct msg |
|
87 |
{ |
|
88 |
enum msg_types type; |
|
89 |
||
90 |
union |
|
91 |
{ |
|
92 |
struct { |
|
93 |
int command_size; |
|
94 |
int store_output; |
|
95 |
int should_keep_finished; |
|
96 |
} newjob; |
|
97 |
struct { |
|
98 |
int ofilename_size; |
|
99 |
int store_output; |
|
100 |
int pid; |
|
101 |
} output; |
|
102 |
int jobid; |
|
103 |
struct Result { |
|
104 |
int errorlevel; |
|
105 |
float user_ms; |
|
106 |
float system_ms; |
|
107 |
float real_ms; |
|
108 |
} result; |
|
109 |
int line_size; |
|
110 |
enum Jobstate state; |
|
111 |
struct { |
|
112 |
int jobid1; |
|
113 |
int jobid2; |
|
114 |
} swap; |
|
115 |
} u; |
|
116 |
}; |
|
117 |
||
118 |
struct Job |
|
119 |
{ |
|
120 |
struct Job *next; |
|
121 |
int jobid; |
|
122 |
char *command; |
|
123 |
enum Jobstate state; |
|
124 |
struct Result result; /* Defined in msg.h */ |
|
125 |
char *output_filename; |
|
126 |
int store_output; |
|
127 |
int pid; |
|
128 |
int should_keep_finished; |
|
129 |
}; |
|
130 |
||
131 |
||
3 | 132 |
/* client.c */ |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
133 |
void c_new_job(); |
8 | 134 |
void c_list_jobs(); |
44 | 135 |
void c_shutdown_server(); |
5 | 136 |
void c_wait_server_lines(); |
44 | 137 |
void c_clear_finished(); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
138 |
int c_wait_server_commands(); |
35 | 139 |
void c_send_runjob_ok(const char *ofname, int pid); |
32 | 140 |
void c_tail(); |
33 | 141 |
void c_cat(); |
142 |
void c_show_output_file(); |
|
41 | 143 |
void c_remove_job(); |
44 | 144 |
void c_show_pid(); |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
44
diff
changeset
|
145 |
int c_wait_job(); |
53 | 146 |
void c_move_urgent(); |
62 | 147 |
int c_wait_newjob_ok(); |
63 | 148 |
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
|
149 |
void c_swap_jobs(); |
71 | 150 |
char *build_command_string(); |
3 | 151 |
|
152 |
/* jobs.c */ |
|
153 |
void s_list(int s); |
|
18 | 154 |
int s_newjob(int s, struct msg *m); |
3 | 155 |
void s_removejob(int jobid); |
114 | 156 |
void job_finished(const struct Result *result); |
8 | 157 |
int next_run_job(); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
158 |
void s_mark_job_running(); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
159 |
void s_clear_finished(); |
35 | 160 |
void s_process_runjob_ok(int jobid, char *oname, int pid); |
32 | 161 |
void s_send_output(int socket, int jobid); |
41 | 162 |
void s_remove_job(int s, int jobid); |
42 | 163 |
void s_remove_notification(int s); |
44 | 164 |
void check_notify_list(int jobid); |
165 |
void s_wait_job(int s, int jobid); |
|
53 | 166 |
void s_move_urgent(int s, int jobid); |
63 | 167 |
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
|
168 |
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
|
169 |
void dump_jobs_struct(FILE *out); |
120 | 170 |
void joblist_dump(int fd); |
171 |
const char * jstate2string(enum Jobstate s); |
|
3 | 172 |
|
173 |
/* server.c */ |
|
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
27
diff
changeset
|
174 |
void server_main(int notify_fd, char *_path); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
175 |
void dump_conns_struct(FILE *out); |
3 | 176 |
|
177 |
/* server_start.c */ |
|
178 |
int try_connect(int s); |
|
179 |
void wait_server_up(); |
|
180 |
int ensure_server_up(); |
|
25 | 181 |
void notify_parent(int fd); |
8 | 182 |
|
183 |
/* execute.c */ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
184 |
int run_job(); |
32 | 185 |
|
33 | 186 |
/* client_run.c */ |
32 | 187 |
void c_run_tail(const char *filename); |
33 | 188 |
void c_run_cat(const char *filename); |
71 | 189 |
|
190 |
/* mail.c */ |
|
191 |
void send_mail(int jobid, int errorlevel, const char *ofname, |
|
192 |
const char *command); |
|
73 | 193 |
void hook_on_finish(int jobid, int errorlevel, const char *ofname, |
194 |
const char *command); |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
195 |
|
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
196 |
/* error.c */ |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
197 |
void error(const char *str, ...); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
73
diff
changeset
|
198 |
void warning(const char *str, ...); |
95 | 199 |
|
200 |
/* signals.c */ |
|
201 |
void ignore_sigpipe(); |
|
202 |
void restore_sigmask(); |
|
117 | 203 |
|
204 |
/* msg.c */ |
|
205 |
void send_bytes(const int fd, const char *data, const int bytes); |
|
206 |
int recv_bytes(const int fd, char *data, const int bytes); |
|
207 |
void send_msg(const int fd, const struct msg *m); |
|
208 |
int recv_msg(const int fd, struct msg *m); |
|
209 |
||
210 |
/* msgdump.c */ |
|
211 |
void msgdump(FILE *, const struct msg *m); |
|
212 |
||
213 |
/* error.c */ |
|
214 |
void error_msg(const struct msg *m, const char *str, ...); |
|
215 |
void warning_msg(const struct msg *m, const char *str, ...); |
|
216 |
||
217 |
/* list.c */ |
|
218 |
char * joblist_headers(); |
|
219 |
char * joblist_line(const struct Job *p); |
|
120 | 220 |
char * joblistdump_torun(const struct Job *p); |
221 |
char * joblistdump_headers(); |