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