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