-
Notifications
You must be signed in to change notification settings - Fork 0
/
fork_passthru.c
68 lines (51 loc) · 1.11 KB
/
fork_passthru.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <string.h>
#include <unistd.h>
#include "minimisc.h"
#if 0
*** fork_passthru *** [sic]
gather a specified amount of input data, fork, and pass it through to
another program. Zero said input data upon fork().
#endif
extern void fork_zerodata();
extern void fork_errpipe();
static char *input;
static unsigned int ibytes;
static void (*_f_errpipe)();
char fork_passthru (argv, readfd, buf, bytes, pid, f_errpipe)
char **argv;
int readfd;
char *buf;
unsigned int bytes;
int *pid;
void (*f_errpipe)();
{
int pipefd[2];
input = buf;
ibytes = bytes;
switch (gather_input(readfd, input, ibytes)) {
case READ_ERROR:
case READ_EXCESS: return 1;
}
close (readfd);
_f_errpipe = f_errpipe;
sig_catch_pipe(fork_errpipe);
if (fork_pipefdout (argv, (int *)pipefd, readfd, pid, fork_zerodata)) {
fork_zerodata();
return 1;
}
if (write (pipefd[1], input, ibytes) <= 0) return 1;
close (pipefd[1]);
sig_default_pipe();
fork_zerodata();
return 0;
}
extern void *memset();
void fork_zerodata (void) {
memset (input, 0, ibytes);
}
void fork_errpipe (sig)
int sig;
{
fork_zerodata();
_f_errpipe();
}