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