author | viric <viriketo@gmail.com> |
Tue, 11 Oct 2011 19:50:10 +0200 | |
changeset 303 | 2edd42e77392 |
parent 297 | d7d0074df110 |
child 305 | 365f3598d010 |
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 |
*/ |
|
1 | 7 |
#include <unistd.h> |
44 | 8 |
#include <stdlib.h> |
9 |
#include <string.h> |
|
95 | 10 |
#include <signal.h> |
1 | 11 |
|
12 |
#include <stdio.h> |
|
146 | 13 |
#include <sys/time.h> |
1 | 14 |
|
3 | 15 |
#include "main.h" |
16 |
||
1 | 17 |
extern char *optarg; |
18 |
extern int optind, opterr, optopt; |
|
19 |
||
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
20 |
/* Globals */ |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
21 |
struct Command_line command_line; |
1 | 22 |
int server_socket; |
23 |
||
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
24 |
/* Globals for the environment of getopt */ |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
25 |
static char getopt_env[] = "POSIXLY_CORRECT=YES"; |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
26 |
static char *old_getopt_env; |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
27 |
|
303
2edd42e77392
Updating the version to 0.7.1, for a release.
viric <viriketo@gmail.com>
parents:
297
diff
changeset
|
28 |
static char version[] = "Task Spooler v0.7.1 - a task queue system for the unix user.\n" |
2edd42e77392
Updating the version to 0.7.1, for a release.
viric <viriketo@gmail.com>
parents:
297
diff
changeset
|
29 |
"Copyright (C) 2007-2011 Lluis Batlle i Rossell"; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
30 |
|
95 | 31 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
32 |
static void default_command_line() |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
33 |
{ |
36 | 34 |
command_line.request = c_LIST; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
35 |
command_line.need_server = 0; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
36 |
command_line.store_output = 1; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
37 |
command_line.should_go_background = 1; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
38 |
command_line.should_keep_finished = 1; |
65 | 39 |
command_line.gzip = 0; |
71 | 40 |
command_line.send_output_by_mail = 0; |
150 | 41 |
command_line.label = 0; |
259 | 42 |
command_line.do_depend = 0; |
43 |
command_line.depend_on = -1; /* -1 means depend on previous */ |
|
219 | 44 |
command_line.max_slots = 1; |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
45 |
command_line.wait_enqueuing = 1; |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
46 |
} |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
47 |
|
18 | 48 |
void get_command(int index, int argc, char **argv) |
49 |
{ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
50 |
command_line.command.array = &(argv[index]); |
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
51 |
command_line.command.num = argc - index; |
18 | 52 |
} |
3 | 53 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
54 |
static int get_two_jobs(const char *str, int *j1, int *j2) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
55 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
56 |
char tmp[50]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
57 |
char *tmp2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
58 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
59 |
if(strlen(str) >= 50) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
60 |
return 0; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
61 |
strcpy(tmp, str); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
62 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
63 |
tmp2 = strchr(tmp , '-'); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
64 |
if (tmp2 == NULL) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
65 |
return 0; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
66 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
67 |
/* We change the '-' to '\0', so we have a delimiter, |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
68 |
* and we can access the two strings for the ids */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
69 |
*tmp2 = '\0'; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
70 |
/* Skip the '\0', and point tmp2 to the second id */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
71 |
++tmp2; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
72 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
73 |
*j1 = atoi(tmp); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
74 |
*j2 = atoi(tmp2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
75 |
return 1; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
76 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
77 |
|
1 | 78 |
void parse_opts(int argc, char **argv) |
79 |
{ |
|
2 | 80 |
int c; |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
81 |
int res; |
1 | 82 |
|
2 | 83 |
/* Parse options */ |
84 |
while(1) { |
|
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
85 |
c = getopt(argc, argv, ":VhKgClnfmBr:t:c:o:p:w:u:s:U:i:L:dS:D:"); |
1 | 86 |
|
2 | 87 |
if (c == -1) |
88 |
break; |
|
1 | 89 |
|
2 | 90 |
switch(c) |
91 |
{ |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
92 |
case 'K': |
31 | 93 |
command_line.request = c_KILL_SERVER; |
95 | 94 |
command_line.should_go_background = 0; |
2 | 95 |
break; |
3 | 96 |
case 'l': |
31 | 97 |
command_line.request = c_LIST; |
3 | 98 |
break; |
36 | 99 |
case 'h': |
100 |
command_line.request = c_SHOW_HELP; |
|
101 |
break; |
|
155 | 102 |
case 'd': |
259 | 103 |
command_line.do_depend = 1; |
104 |
command_line.depend_on = -1; |
|
155 | 105 |
break; |
37 | 106 |
case 'V': |
107 |
command_line.request = c_SHOW_VERSION; |
|
108 |
break; |
|
33 | 109 |
case 'C': |
110 |
command_line.request = c_CLEAR_FINISHED; |
|
111 |
break; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
18
diff
changeset
|
112 |
case 'c': |
33 | 113 |
command_line.request = c_CAT; |
114 |
command_line.jobid = atoi(optarg); |
|
115 |
break; |
|
116 |
case 'o': |
|
117 |
command_line.request = c_SHOW_OUTPUT_FILE; |
|
118 |
command_line.jobid = atoi(optarg); |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
18
diff
changeset
|
119 |
break; |
22 | 120 |
case 'n': |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
121 |
command_line.store_output = 0; |
22 | 122 |
break; |
150 | 123 |
case 'L': |
124 |
command_line.label = optarg; |
|
125 |
break; |
|
65 | 126 |
case 'g': |
127 |
command_line.gzip = 1; |
|
128 |
break; |
|
31 | 129 |
case 'f': |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
130 |
command_line.should_go_background = 0; |
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
131 |
break; |
71 | 132 |
case 'm': |
133 |
command_line.send_output_by_mail = 1; |
|
134 |
break; |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
135 |
case 't': |
31 | 136 |
command_line.request = c_TAIL; |
32 | 137 |
command_line.jobid = atoi(optarg); |
29
ca47653a4cbc
Add an option for electing not to go into background.
viric@llimona
parents:
27
diff
changeset
|
138 |
break; |
35 | 139 |
case 'p': |
140 |
command_line.request = c_SHOW_PID; |
|
141 |
command_line.jobid = atoi(optarg); |
|
142 |
break; |
|
146 | 143 |
case 'i': |
144 |
command_line.request = c_INFO; |
|
145 |
command_line.jobid = atoi(optarg); |
|
146 |
break; |
|
41 | 147 |
case 'r': |
148 |
command_line.request = c_REMOVEJOB; |
|
149 |
command_line.jobid = atoi(optarg); |
|
150 |
break; |
|
42 | 151 |
case 'w': |
152 |
command_line.request = c_WAITJOB; |
|
153 |
command_line.jobid = atoi(optarg); |
|
154 |
break; |
|
53 | 155 |
case 'u': |
156 |
command_line.request = c_URGENT; |
|
157 |
command_line.jobid = atoi(optarg); |
|
158 |
break; |
|
63 | 159 |
case 's': |
160 |
command_line.request = c_GET_STATE; |
|
161 |
command_line.jobid = atoi(optarg); |
|
162 |
break; |
|
218 | 163 |
case 'S': |
219 | 164 |
command_line.request = c_SET_MAX_SLOTS; |
165 |
command_line.max_slots = atoi(optarg); |
|
166 |
if (command_line.max_slots < 1) |
|
167 |
{ |
|
168 |
fprintf(stderr, "You should set at minimum 1 slot.\n"); |
|
169 |
exit(-1); |
|
170 |
} |
|
218 | 171 |
break; |
259 | 172 |
case 'D': |
173 |
command_line.do_depend = 1; |
|
174 |
command_line.depend_on = atoi(optarg); |
|
175 |
break; |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
176 |
case 'U': |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
177 |
command_line.request = c_SWAP_JOBS; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
178 |
res = get_two_jobs(optarg, &command_line.jobid, |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
179 |
&command_line.jobid2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
180 |
if (!res) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
181 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
182 |
fprintf(stderr, "Wrong <id-id> for -U.\n"); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
183 |
exit(-1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
184 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
185 |
if (command_line.jobid == command_line.jobid2) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
186 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
187 |
fprintf(stderr, "Wrong <id-id> for -U. " |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
188 |
"Use different ids.\n"); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
189 |
exit(-1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
190 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
191 |
break; |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
192 |
case 'B': |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
193 |
/* I picked 'B' quite at random among the letters left */ |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
194 |
command_line.wait_enqueuing = 0; |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
283
diff
changeset
|
195 |
break; |
31 | 196 |
case ':': |
197 |
switch(optopt) |
|
198 |
{ |
|
199 |
case 't': |
|
32 | 200 |
command_line.request = c_TAIL; |
31 | 201 |
command_line.jobid = -1; /* This means the 'last' job */ |
202 |
break; |
|
33 | 203 |
case 'c': |
204 |
command_line.request = c_CAT; |
|
205 |
command_line.jobid = -1; /* This means the 'last' job */ |
|
206 |
break; |
|
207 |
case 'o': |
|
208 |
command_line.request = c_SHOW_OUTPUT_FILE; |
|
209 |
command_line.jobid = -1; /* This means the 'last' job */ |
|
210 |
break; |
|
35 | 211 |
case 'p': |
212 |
command_line.request = c_SHOW_PID; |
|
213 |
command_line.jobid = -1; /* This means the 'last' job */ |
|
214 |
break; |
|
146 | 215 |
case 'i': |
216 |
command_line.request = c_INFO; |
|
217 |
command_line.jobid = -1; /* This means the 'last' job */ |
|
218 |
break; |
|
41 | 219 |
case 'r': |
220 |
command_line.request = c_REMOVEJOB; |
|
221 |
command_line.jobid = -1; /* This means the 'last' |
|
222 |
added job */ |
|
223 |
break; |
|
42 | 224 |
case 'w': |
225 |
command_line.request = c_WAITJOB; |
|
226 |
command_line.jobid = -1; /* This means the 'last' |
|
227 |
added job */ |
|
228 |
break; |
|
53 | 229 |
case 'u': |
230 |
command_line.request = c_URGENT; |
|
231 |
command_line.jobid = -1; /* This means the 'last' |
|
232 |
added job */ |
|
233 |
break; |
|
63 | 234 |
case 's': |
235 |
command_line.request = c_GET_STATE; |
|
236 |
command_line.jobid = -1; /* This means the 'last' |
|
237 |
added job */ |
|
238 |
break; |
|
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
239 |
case 'S': |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
240 |
command_line.request = c_GET_MAX_SLOTS; |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
241 |
break; |
31 | 242 |
default: |
150 | 243 |
fprintf(stderr, "Option %c missing argument.\n", |
244 |
optopt); |
|
31 | 245 |
exit(-1); |
246 |
} |
|
247 |
break; |
|
248 |
case '?': |
|
249 |
fprintf(stderr, "Wrong option %c.\n", optopt); |
|
250 |
exit(-1); |
|
2 | 251 |
} |
252 |
} |
|
1 | 253 |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
254 |
command_line.command.num = 0; |
18 | 255 |
|
37 | 256 |
/* if the request is still the default option... |
257 |
* (the default values should be centralized) */ |
|
258 |
if (optind < argc && command_line.request == c_LIST) |
|
31 | 259 |
{ |
260 |
command_line.request = c_QUEUE; |
|
18 | 261 |
get_command(optind, argc, argv); |
31 | 262 |
} |
3 | 263 |
|
37 | 264 |
if (command_line.request != c_SHOW_HELP && |
265 |
command_line.request != c_SHOW_VERSION) |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
266 |
command_line.need_server = 1; |
55
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
267 |
|
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
268 |
if ( ! command_line.store_output && ! command_line.should_go_background ) |
678ca291d545
Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents:
53
diff
changeset
|
269 |
command_line.should_keep_finished = 0; |
71 | 270 |
|
271 |
if ( command_line.send_output_by_mail && ((! command_line.store_output) || |
|
272 |
command_line.gzip) ) |
|
273 |
{ |
|
274 |
fprintf(stderr, |
|
275 |
"For e-mail, you should store the output (not through gzip)\n"); |
|
276 |
exit(-1); |
|
277 |
} |
|
1 | 278 |
} |
279 |
||
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
280 |
static void fill_first_3_handles() |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
281 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
282 |
int tmp_pipe1[2]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
283 |
int tmp_pipe2[2]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
284 |
/* This will fill handles 0 and 1 */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
285 |
pipe(tmp_pipe1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
286 |
/* This will fill handles 2 and 3 */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
287 |
pipe(tmp_pipe2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
288 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
289 |
close(tmp_pipe2[1]); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
290 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
291 |
|
44 | 292 |
static void go_background() |
11
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
293 |
{ |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
294 |
int pid; |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
295 |
pid = fork(); |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
296 |
|
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
297 |
switch(pid) |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
298 |
{ |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
299 |
case -1: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
300 |
error("fork failed"); |
11
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
301 |
break; |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
302 |
case 0: |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
303 |
close(0); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
304 |
close(1); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
305 |
close(2); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
306 |
/* This is a weird thing. But we will later want to |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
307 |
* allocate special files to the 0, 1 or 2 fds. It's |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
308 |
* almost impossible, if other important things got |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
309 |
* allocated here. */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
310 |
fill_first_3_handles(); |
133 | 311 |
setsid(); |
11
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
312 |
break; |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
313 |
default: |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
314 |
exit(0); |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
315 |
} |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
316 |
} |
bb94b9890001
Going to background at for new command queued.
lbatlle@npdl268.bpo.hp.com
parents:
8
diff
changeset
|
317 |
|
37 | 318 |
static void print_help(const char *cmd) |
36 | 319 |
{ |
266
e35af91aa426
Fixing the help messages and man page for 0.6.3.
viric@mandarina
parents:
263
diff
changeset
|
320 |
printf("usage: %s [action] [-ngfmd] [-L <lab>] [-D <id>] [cmd...]\n", cmd); |
73 | 321 |
printf("Env vars:\n"); |
183
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
322 |
printf(" TS_SOCKET the path to the unix socket used by the ts command.\n"); |
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
323 |
printf(" TS_MAILTO where to mail the result (on -m). Local user by default.\n"); |
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
324 |
printf(" TS_MAXFINISHED maximum finished jobs in the queue.\n"); |
278 | 325 |
printf(" TS_MAXCONN maximum number of ts connections at once.\n"); |
183
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
326 |
printf(" TS_ONFINISH binary called on job end (passes jobid, error, outfile, command).\n"); |
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
327 |
printf(" TS_ENV command called on enqueue. Its output determines the job information.\n"); |
95d49e8a8cec
Updating 'help' and some other related files to 0.5
viric@llimona
parents:
174
diff
changeset
|
328 |
printf(" TS_SAVELIST filename which will store the list, if the server dies.\n"); |
239
18301d7a56d4
As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents:
237
diff
changeset
|
329 |
printf(" TS_SLOTS amount of jobs which can run at once, read on server start.\n"); |
52 | 330 |
printf("Actions:\n"); |
36 | 331 |
printf(" -K kill the task spooler server\n"); |
332 |
printf(" -C clear the list of finished jobs\n"); |
|
333 |
printf(" -l show the job list (default action)\n"); |
|
263 | 334 |
printf(" -S [num] get/set the number of max simultaneous jobs of the server.\n"); |
204
cd474500b9e1
Removing the code related to tail -f and cat. Updated help.
lbatlle@npdl268.bpo.hp.com
parents:
203
diff
changeset
|
335 |
printf(" -t [id] \"tail -n 10 -f\" the output of the job. Last run if not specified.\n"); |
cd474500b9e1
Removing the code related to tail -f and cat. Updated help.
lbatlle@npdl268.bpo.hp.com
parents:
203
diff
changeset
|
336 |
printf(" -c [id] like -t, but shows all the lines. Last run if not specified.\n"); |
132 | 337 |
printf(" -p [id] show the pid of the job. Last run if not specified.\n"); |
61 | 338 |
printf(" -o [id] show the output file. Of last job run, if not specified.\n"); |
151 | 339 |
printf(" -i [id] show job information. Of last job run, if not specified.\n"); |
78 | 340 |
printf(" -s [id] show the job state. Of the last added, if not specified.\n"); |
42 | 341 |
printf(" -r [id] remove a job. The last added, if not specified.\n"); |
342 |
printf(" -w [id] wait for a job. The last added, if not specified.\n"); |
|
53 | 343 |
printf(" -u [id] put that job first. The last added, if not specified.\n"); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
344 |
printf(" -U <id-id> swap two jobs in the queue.\n"); |
296 | 345 |
printf(" -B in case of full queue on the server, quit (2) instead of waiting.\n"); |
37 | 346 |
printf(" -h show this help\n"); |
347 |
printf(" -V show the program version\n"); |
|
52 | 348 |
printf("Options adding jobs:\n"); |
36 | 349 |
printf(" -n don't store the output of the command.\n"); |
65 | 350 |
printf(" -g gzip the stored output (if not -n).\n"); |
36 | 351 |
printf(" -f don't fork into background.\n"); |
71 | 352 |
printf(" -m send the output by e-mail (uses sendmail).\n"); |
158 | 353 |
printf(" -d the job will be run only if the job before ends well\n"); |
259 | 354 |
printf(" -D <id> the job will be run only if the job of given id ends well \n"); |
159 | 355 |
printf(" -L <lab> name this task with a label, to be distinguished on listing.\n"); |
36 | 356 |
} |
357 |
||
37 | 358 |
static void print_version() |
359 |
{ |
|
360 |
puts(version); |
|
44 | 361 |
} |
37 | 362 |
|
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
363 |
static void set_getopt_env() |
48 | 364 |
{ |
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
365 |
old_getopt_env = getenv("POSIXLY_CORRECT"); |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
366 |
putenv(getopt_env); |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
367 |
} |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
368 |
|
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
369 |
static void unset_getopt_env() |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
370 |
{ |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
371 |
if (old_getopt_env == NULL) |
87
18dc656315eb
Finally fixed the POSIXLY_CORRECT env problem
lbatlle@npdl268.bpo.hp.com
parents:
81
diff
changeset
|
372 |
{ |
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
373 |
/* Wipe the string from the environment */ |
87
18dc656315eb
Finally fixed the POSIXLY_CORRECT env problem
lbatlle@npdl268.bpo.hp.com
parents:
81
diff
changeset
|
374 |
putenv("POSIXLY_CORRECT"); |
18dc656315eb
Finally fixed the POSIXLY_CORRECT env problem
lbatlle@npdl268.bpo.hp.com
parents:
81
diff
changeset
|
375 |
} |
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
376 |
else |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
377 |
sprintf(getopt_env, "POSIXLY_CORRECT=%s", old_getopt_env); |
48 | 378 |
} |
379 |
||
1 | 380 |
int main(int argc, char **argv) |
381 |
{ |
|
38
768d009604b3
The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents:
37
diff
changeset
|
382 |
int errorlevel = 0; |
41 | 383 |
|
104 | 384 |
process_type = CLIENT; |
385 |
||
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
386 |
set_getopt_env(); |
41 | 387 |
/* This is needed in a gnu system, so getopt works well */ |
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
388 |
default_command_line(); |
2 | 389 |
parse_opts(argc, argv); |
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
390 |
unset_getopt_env(); |
1 | 391 |
|
95 | 392 |
/* This will be inherited by the server, if it's run */ |
393 |
ignore_sigpipe(); |
|
394 |
||
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
395 |
if (command_line.need_server) |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
396 |
{ |
3 | 397 |
ensure_server_up(); |
260
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
398 |
c_check_version(); |
ecd09b351170
Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents:
259
diff
changeset
|
399 |
} |
3 | 400 |
|
31 | 401 |
switch(command_line.request) |
3 | 402 |
{ |
37 | 403 |
case c_SHOW_VERSION: |
404 |
print_version(argv[0]); |
|
405 |
break; |
|
36 | 406 |
case c_SHOW_HELP: |
407 |
print_help(argv[0]); |
|
37 | 408 |
break; |
31 | 409 |
case c_QUEUE: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
410 |
if (command_line.command.num <= 0) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
411 |
error("Tried to queue a void command. parameters: %i", |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
412 |
command_line.command.num); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
413 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
414 |
error("The command %i needs the server", command_line.request); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
415 |
c_new_job(); |
71 | 416 |
command_line.jobid = c_wait_newjob_ok(); |
62 | 417 |
if (command_line.store_output) |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
418 |
{ |
71 | 419 |
printf("%i\n", command_line.jobid); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
420 |
fflush(stdout); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
421 |
} |
62 | 422 |
if (command_line.should_go_background) |
423 |
{ |
|
424 |
go_background(); |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
425 |
c_wait_server_commands(); |
62 | 426 |
} else |
427 |
{ |
|
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
428 |
errorlevel = c_wait_server_commands(); |
62 | 429 |
} |
31 | 430 |
break; |
431 |
case c_LIST: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
432 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
433 |
error("The command %i needs the server", command_line.request); |
8 | 434 |
c_list_jobs(); |
5 | 435 |
c_wait_server_lines(); |
31 | 436 |
break; |
437 |
case c_KILL_SERVER: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
438 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
439 |
error("The command %i needs the server", command_line.request); |
3 | 440 |
c_shutdown_server(); |
31 | 441 |
break; |
442 |
case c_CLEAR_FINISHED: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
443 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
444 |
error("The command %i needs the server", command_line.request); |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
18
diff
changeset
|
445 |
c_clear_finished(); |
31 | 446 |
break; |
32 | 447 |
case c_TAIL: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
448 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
449 |
error("The command %i needs the server", command_line.request); |
174
c112f67965fb
Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents:
166
diff
changeset
|
450 |
errorlevel = c_tail(); |
32 | 451 |
/* This will not return! */ |
452 |
break; |
|
33 | 453 |
case c_CAT: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
454 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
455 |
error("The command %i needs the server", command_line.request); |
203
664044b1de73
Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents:
199
diff
changeset
|
456 |
errorlevel = c_cat(); |
33 | 457 |
/* This will not return! */ |
458 |
break; |
|
459 |
case c_SHOW_OUTPUT_FILE: |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
460 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
461 |
error("The command %i needs the server", command_line.request); |
33 | 462 |
c_show_output_file(); |
463 |
break; |
|
35 | 464 |
case c_SHOW_PID: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
465 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
466 |
error("The command %i needs the server", command_line.request); |
35 | 467 |
c_show_pid(); |
468 |
break; |
|
146 | 469 |
case c_INFO: |
470 |
if (!command_line.need_server) |
|
471 |
error("The command %i needs the server", command_line.request); |
|
472 |
c_show_info(); |
|
473 |
break; |
|
41 | 474 |
case c_REMOVEJOB: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
475 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
476 |
error("The command %i needs the server", command_line.request); |
41 | 477 |
c_remove_job(); |
478 |
break; |
|
42 | 479 |
case c_WAITJOB: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
480 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
481 |
error("The command %i needs the server", command_line.request); |
51
aa6e05d77537
'-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents:
49
diff
changeset
|
482 |
errorlevel = c_wait_job(); |
42 | 483 |
break; |
53 | 484 |
case c_URGENT: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
485 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
486 |
error("The command %i needs the server", command_line.request); |
53 | 487 |
c_move_urgent(); |
488 |
break; |
|
219 | 489 |
case c_SET_MAX_SLOTS: |
490 |
c_send_max_slots(command_line.max_slots); |
|
491 |
break; |
|
253
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
492 |
case c_GET_MAX_SLOTS: |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
493 |
c_get_max_slots(); |
e9b153f4ae40
Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents:
247
diff
changeset
|
494 |
break; |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
495 |
case c_SWAP_JOBS: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
496 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
497 |
error("The command %i needs the server", command_line.request); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
498 |
c_swap_jobs(); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
499 |
break; |
63 | 500 |
case c_GET_STATE: |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
501 |
if (!command_line.need_server) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
87
diff
changeset
|
502 |
error("The command %i needs the server", command_line.request); |
63 | 503 |
/* This will also print the state into stdout */ |
504 |
c_get_state(); |
|
505 |
break; |
|
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
18
diff
changeset
|
506 |
} |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
18
diff
changeset
|
507 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
29
diff
changeset
|
508 |
if (command_line.need_server) |
2 | 509 |
{ |
3 | 510 |
close(server_socket); |
2 | 511 |
} |
1 | 512 |
|
38
768d009604b3
The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents:
37
diff
changeset
|
513 |
return errorlevel; |
1 | 514 |
} |