xref: /titanic_53/usr/src/cmd/refer/refer3.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate 
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
7*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*7c478bd9Sstevel@tonic-gate  */
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate /*
12*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13*7c478bd9Sstevel@tonic-gate  * All Rights Reserved.
14*7c478bd9Sstevel@tonic-gate  */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate #include "refer..c"
19*7c478bd9Sstevel@tonic-gate #define move(x, y) close(y); dup(x); close(x);
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate corout(in, out, rprog, arg, outlen)
22*7c478bd9Sstevel@tonic-gate char *in, *out, *rprog;
23*7c478bd9Sstevel@tonic-gate {
24*7c478bd9Sstevel@tonic-gate 	int pipev[2], fr1, fr2, fw1, fw2, n;
25*7c478bd9Sstevel@tonic-gate 	int status;
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate 	pipe(pipev);
28*7c478bd9Sstevel@tonic-gate 	fr1 = pipev[0];
29*7c478bd9Sstevel@tonic-gate 	fw1 = pipev[1];
30*7c478bd9Sstevel@tonic-gate 	pipe(pipev);
31*7c478bd9Sstevel@tonic-gate 	fr2 = pipev[0];
32*7c478bd9Sstevel@tonic-gate 	fw2 = pipev[1];
33*7c478bd9Sstevel@tonic-gate 	if (fork() == 0)
34*7c478bd9Sstevel@tonic-gate 	{
35*7c478bd9Sstevel@tonic-gate 		close(fw1);
36*7c478bd9Sstevel@tonic-gate 		close(fr2);
37*7c478bd9Sstevel@tonic-gate 		move(fr1, 0);
38*7c478bd9Sstevel@tonic-gate 		move(fw2, 1);
39*7c478bd9Sstevel@tonic-gate 		execl(rprog, "deliv", arg, 0);
40*7c478bd9Sstevel@tonic-gate 		err("Can't run %s", rprog);
41*7c478bd9Sstevel@tonic-gate 	}
42*7c478bd9Sstevel@tonic-gate 	close(fw2);
43*7c478bd9Sstevel@tonic-gate 	close(fr1);
44*7c478bd9Sstevel@tonic-gate 	write(fw1, in , strlen(in));
45*7c478bd9Sstevel@tonic-gate 	close(fw1);
46*7c478bd9Sstevel@tonic-gate 	wait(&status);
47*7c478bd9Sstevel@tonic-gate 	n = read(fr2, out, outlen);
48*7c478bd9Sstevel@tonic-gate 	out[n] = 0;
49*7c478bd9Sstevel@tonic-gate 	close(fr2);
50*7c478bd9Sstevel@tonic-gate 	return(n);
51*7c478bd9Sstevel@tonic-gate }
52