xref: /illumos-gate/usr/src/cmd/refer/refer3.c (revision b3385a702fe5f8caba5ad4c451836514efff0bfa)
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 #include "refer..c"
16 #define	move(x, y) close(y); dup(x); close(x);
17 
18 extern void err();
19 
20 int
21 corout(char *in, char *out, char *rprog, char *arg, int outlen)
22 {
23 	int pipev[2], fr1, fr2, fw1, fw2, n;
24 	int status;
25 
26 	pipe(pipev);
27 	fr1 = pipev[0];
28 	fw1 = pipev[1];
29 	pipe(pipev);
30 	fr2 = pipev[0];
31 	fw2 = pipev[1];
32 	if (fork() == 0) {
33 		close(fw1);
34 		close(fr2);
35 		move(fr1, 0);
36 		move(fw2, 1);
37 		execl(rprog, "deliv", arg, 0);
38 		err("Can't run %s", rprog);
39 	}
40 	close(fw2);
41 	close(fr1);
42 	write(fw1, in, strlen(in));
43 	close(fw1);
44 	wait(&status);
45 	n = read(fr2, out, outlen);
46 	out[n] = 0;
47 	close(fr2);
48 	return (n);
49 }
50