author | Lluís Batlle <viric@viric.name> |
Fri, 06 Mar 2015 23:26:50 +0100 | |
changeset 337 | 43079a99351e |
parent 329 | b01bb36b4290 |
child 347 | 79b87e385bc5 |
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 |
*/ |
|
8 | 7 |
#include <unistd.h> |
8 |
#include <stdio.h> |
|
9 | 9 |
#include <signal.h> |
44 | 10 |
#include <string.h> |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
11 |
#include <sys/types.h> |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
12 |
#include <sys/wait.h> |
44 | 13 |
#include <stdlib.h> |
95 | 14 |
#include <signal.h> |
110 | 15 |
#include <time.h> |
16 |
#include <sys/times.h> |
|
112 | 17 |
#include <sys/time.h> |
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
18 |
#include <sys/types.h> |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
19 |
#include <fcntl.h> |
8 | 20 |
|
21 |
#include "main.h" |
|
22 |
||
138 | 23 |
/* from signals.c */ |
24 |
extern int signals_child_pid; /* 0, not set. otherwise, set. */ |
|
25 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
26 |
/* Returns errorlevel */ |
112 | 27 |
static void run_parent(int fd_read_filename, int pid, struct Result *result) |
8 | 28 |
{ |
29 |
int status; |
|
22 | 30 |
char *ofname = 0; |
31 |
int namesize; |
|
32 |
int res; |
|
73 | 33 |
char *command; |
110 | 34 |
struct timeval starttv; |
35 |
struct timeval endtv; |
|
36 |
struct tms cpu_times; |
|
22 | 37 |
|
38 |
/* Read the filename */ |
|
39 |
/* This is linked with the write() in this same file, in run_child() */ |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
40 |
if (command_line.store_output) { |
22 | 41 |
res = read(fd_read_filename, &namesize, sizeof(namesize)); |
42 |
if (res == -1) |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
43 |
error("read the filename from %i", fd_read_filename); |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
44 |
if (res != sizeof(namesize)) |
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
45 |
error("Reading the size of the name"); |
22 | 46 |
ofname = (char *) malloc(namesize); |
47 |
res = read(fd_read_filename, ofname, namesize); |
|
107
c0a1c1e98b6a
Fixed a bug in execute, calling error(). Wrong release again.
viric@llimona
parents:
99
diff
changeset
|
48 |
if (res != namesize) |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
49 |
error("Reading the the out file name"); |
22 | 50 |
} |
116 | 51 |
res = read(fd_read_filename, &starttv, sizeof(starttv)); |
52 |
if (res != sizeof(starttv)) |
|
53 |
error("Reading the the struct timeval"); |
|
22 | 54 |
close(fd_read_filename); |
55 |
||
138 | 56 |
/* All went fine - prepare the SIGINT and send runjob_ok */ |
57 |
signals_child_pid = pid; |
|
58 |
unblock_sigint_and_install_handler(); |
|
59 |
||
35 | 60 |
c_send_runjob_ok(ofname, pid); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
61 |
|
8 | 62 |
wait(&status); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
63 |
|
115
367ada1cb69b
Fixed the errorlevel/times on signal received on the child.
viric@mandarina
parents:
114
diff
changeset
|
64 |
/* Set the errorlevel */ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
65 |
if (WIFEXITED(status)) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
66 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
67 |
/* We force the proper cast */ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
68 |
signed char tmp; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
69 |
tmp = WEXITSTATUS(status); |
115
367ada1cb69b
Fixed the errorlevel/times on signal received on the child.
viric@mandarina
parents:
114
diff
changeset
|
70 |
result->errorlevel = tmp; |
246
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
71 |
result->died_by_signal = 0; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
72 |
} |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
73 |
else if (WIFSIGNALED(status)) |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
74 |
{ |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
75 |
signed char tmp; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
76 |
tmp = WTERMSIG(status); |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
77 |
result->signal = tmp; |
112 | 78 |
result->errorlevel = -1; |
246
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
79 |
result->died_by_signal = 1; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
80 |
} |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
81 |
else |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
82 |
{ |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
83 |
result->died_by_signal = 0; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
84 |
result->errorlevel = -1; |
239b28c0cca9
Adding information on the exit status (signal/exit code).
viric@mandarina
parents:
231
diff
changeset
|
85 |
} |
71 | 86 |
|
73 | 87 |
command = build_command_string(); |
71 | 88 |
if (command_line.send_output_by_mail) |
89 |
{ |
|
115
367ada1cb69b
Fixed the errorlevel/times on signal received on the child.
viric@mandarina
parents:
114
diff
changeset
|
90 |
send_mail(command_line.jobid, result->errorlevel, ofname, command); |
71 | 91 |
} |
115
367ada1cb69b
Fixed the errorlevel/times on signal received on the child.
viric@mandarina
parents:
114
diff
changeset
|
92 |
hook_on_finish(command_line.jobid, result->errorlevel, ofname, command); |
73 | 93 |
free(command); |
71 | 94 |
|
95 |
free(ofname); |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
96 |
|
110 | 97 |
/* Calculate times */ |
98 |
gettimeofday(&endtv, NULL); |
|
112 | 99 |
result->real_ms = endtv.tv_sec - starttv.tv_sec + |
114 | 100 |
((float) (endtv.tv_usec - starttv.tv_usec) / 1000000.); |
110 | 101 |
times(&cpu_times); |
114 | 102 |
/* The times are given in clock ticks. The number of clock ticks per second |
103 |
* is obtained in POSIX using sysconf(). */ |
|
104 |
result->user_ms = (float) cpu_times.tms_cutime / |
|
105 |
(float) sysconf(_SC_CLK_TCK); |
|
106 |
result->system_ms = (float) cpu_times.tms_cstime / |
|
107 |
(float) sysconf(_SC_CLK_TCK); |
|
44 | 108 |
} |
8 | 109 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
110 |
void create_closed_read_on(int dest) |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
111 |
{ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
112 |
int p[2]; |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
113 |
/* Closing input */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
114 |
pipe(p); |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
115 |
close(p[1]); /* closing the write handle */ |
76
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
116 |
dup2(p[0], dest); /* the pipe reading goes to dest */ |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
117 |
if(p[0] != dest) |
14bc35eee745
Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
viric@mandarina
parents:
73
diff
changeset
|
118 |
close(p[0]); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
119 |
} |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
120 |
|
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
121 |
/* This will close fd_out and fd_in in the parent */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
122 |
static void run_gzip(int fd_out, int fd_in) |
65 | 123 |
{ |
124 |
int pid; |
|
125 |
pid = fork(); |
|
126 |
||
127 |
switch(pid) |
|
128 |
{ |
|
129 |
case 0: /* child */ |
|
95 | 130 |
restore_sigmask(); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
131 |
dup2(fd_in,0); /* stdout */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
132 |
dup2(fd_out,1); /* stdout */ |
65 | 133 |
close(fd_in); |
134 |
close(fd_out); |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
135 |
/* Without stderr */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
136 |
close(2); |
65 | 137 |
execlp("gzip", "gzip", NULL); |
138 |
exit(-1); |
|
139 |
/* Won't return */ |
|
140 |
case -1: |
|
141 |
exit(-1); /* Fork error */ |
|
142 |
default: |
|
143 |
close(fd_in); |
|
144 |
close(fd_out); |
|
145 |
} |
|
146 |
} |
|
147 |
||
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
148 |
static void run_child(int fd_send_filename) |
8 | 149 |
{ |
28
107abb4ec98a
Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents:
22
diff
changeset
|
150 |
char outfname[] = "/tmp/ts-out.XXXXXX"; |
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
151 |
char errfname[sizeof outfname + 2]; /* .e */ |
22 | 152 |
int namesize; |
153 |
int outfd; |
|
110 | 154 |
struct timeval starttv; |
22 | 155 |
|
30
ab88478a7e9b
The commandline parameters are centered in a struct.
viric@llimona
parents:
28
diff
changeset
|
156 |
if (command_line.store_output) |
22 | 157 |
{ |
65 | 158 |
if (command_line.gzip) |
159 |
{ |
|
160 |
int p[2]; |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
161 |
/* We assume that all handles are closed*/ |
65 | 162 |
pipe(p); |
163 |
||
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
164 |
/* gzip output goes to the filename */ |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
165 |
/* This will be the handle other than 0,1,2 */ |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
166 |
outfd = mkstemp(outfname); /* stdout */ |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
167 |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
168 |
/* Program stdout and stderr */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
169 |
/* which go to pipe write handle */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
170 |
dup2(p[1], 1); |
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
171 |
if (command_line.stderr_apart) |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
172 |
{ |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
173 |
int errfd; |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
174 |
strncpy(errfname, outfname, sizeof errfname); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
175 |
strncat(errfname, ".e", 2); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
176 |
errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
177 |
dup2(errfd, 2); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
178 |
close(errfd); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
179 |
} |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
180 |
else |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
181 |
dup2(p[1], 2); |
65 | 182 |
close(p[1]); |
183 |
||
184 |
/* run gzip. |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
185 |
* This wants p[0] in 0, so gzip will read |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
186 |
* from it */ |
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
187 |
run_gzip(outfd, p[0]); |
65 | 188 |
} |
189 |
else |
|
190 |
{ |
|
191 |
/* Prepare the filename */ |
|
192 |
outfd = mkstemp(outfname); /* stdout */ |
|
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
193 |
dup2(outfd, 1); /* stdout */ |
305
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
194 |
if (command_line.stderr_apart) |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
195 |
{ |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
196 |
int errfd; |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
197 |
strncpy(errfname, outfname, sizeof errfname); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
198 |
strncat(errfname, ".e", 2); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
199 |
errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
200 |
dup2(errfd, 2); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
201 |
close(errfd); |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
202 |
} |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
203 |
else |
365f3598d010
Adding the functionality of keeping stderr apart. For Jan Šmydke.
viric <viriketo@gmail.com>
parents:
295
diff
changeset
|
204 |
dup2(outfd, 2); |
66
f70a27afd92e
Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents:
65
diff
changeset
|
205 |
close(outfd); |
65 | 206 |
} |
22 | 207 |
|
208 |
/* Send the filename */ |
|
209 |
namesize = sizeof(outfname); |
|
329
b01bb36b4290
Fixing some code based on gcc warnings.
viric <viriketo@gmail.com>
parents:
305
diff
changeset
|
210 |
write(fd_send_filename, (char *)&namesize, sizeof(namesize)); |
22 | 211 |
write(fd_send_filename, outfname, sizeof(outfname)); |
212 |
} |
|
116 | 213 |
/* Times */ |
214 |
gettimeofday(&starttv, NULL); |
|
215 |
write(fd_send_filename, &starttv, sizeof(starttv)); |
|
22 | 216 |
close(fd_send_filename); |
217 |
||
9 | 218 |
/* Closing input */ |
70
8c244f28224e
Fixed "-f". Now it doesn't close stdin in this case.
viric@llimona
parents:
69
diff
changeset
|
219 |
if (command_line.should_go_background) |
8c244f28224e
Fixed "-f". Now it doesn't close stdin in this case.
viric@llimona
parents:
69
diff
changeset
|
220 |
create_closed_read_on(0); |
9 | 221 |
|
168
02b699d307fd
Comment on setsid for the job execution.
lbatlle@npdl268.bpo.hp.com
parents:
167
diff
changeset
|
222 |
/* We create a new session, so we can kill process groups as: |
02b699d307fd
Comment on setsid for the job execution.
lbatlle@npdl268.bpo.hp.com
parents:
167
diff
changeset
|
223 |
kill -- -`ts -p` */ |
167 | 224 |
setsid(); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
225 |
execvp(command_line.command.array[0], command_line.command.array); |
8 | 226 |
} |
227 |
||
110 | 228 |
int run_job(struct Result *res) |
8 | 229 |
{ |
230 |
int pid; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
231 |
int errorlevel; |
22 | 232 |
int p[2]; |
8 | 233 |
|
234 |
||
9 | 235 |
/* For the parent */ |
236 |
/*program_signal(); Still not needed*/ |
|
237 |
||
138 | 238 |
block_sigint(); |
239 |
||
22 | 240 |
/* Prepare the output filename sending */ |
241 |
pipe(p); |
|
242 |
||
243 |
pid = fork(); |
|
244 |
||
8 | 245 |
switch(pid) |
246 |
{ |
|
247 |
case 0: |
|
95 | 248 |
restore_sigmask(); |
9 | 249 |
close(server_socket); |
22 | 250 |
close(p[0]); |
68
3ae9b38d7d30
Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents:
65
diff
changeset
|
251 |
run_child(p[1]); |
69 | 252 |
/* Not reachable, if the 'exec' of the command |
253 |
* works. Thus, command exists, etc. */ |
|
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
254 |
fprintf(stderr, "ts could not run the command\n"); |
69 | 255 |
exit(-1); |
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
256 |
/* To avoid a compiler warning */ |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
257 |
errorlevel = 0; |
8 | 258 |
break; |
259 |
case -1: |
|
295
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
260 |
/* To avoid a compiler warning */ |
a63f43a17fd7
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents:
267
diff
changeset
|
261 |
errorlevel = 0; |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
77
diff
changeset
|
262 |
error("forking"); |
8 | 263 |
default: |
22 | 264 |
close(p[1]); |
110 | 265 |
run_parent(p[0], pid, res); |
8 | 266 |
break; |
267 |
} |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
268 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
269 |
return errorlevel; |
8 | 270 |
} |
9 | 271 |
|
95 | 272 |
#if 0 |
273 |
Not needed |
|
9 | 274 |
static void sigchld_handler(int val) |
275 |
{ |
|
276 |
} |
|
277 |
||
278 |
static void program_signal() |
|
279 |
{ |
|
280 |
struct sigaction act; |
|
281 |
||
282 |
act.sa_handler = sigchld_handler; |
|
283 |
/* Reset the mask */ |
|
284 |
memset(&act.sa_mask,0,sizeof(act.sa_mask)); |
|
285 |
act.sa_flags = SA_NOCLDSTOP; |
|
286 |
||
287 |
sigaction(SIGCHLD, &act, NULL); |
|
288 |
} |
|
95 | 289 |
#endif |