xref: /titanic_52/usr/src/cmd/refer/refer3.c (revision 11a8fa6cb17403e630122ac19b39a323c6e64142)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include "refer..c"
187c478bd9Sstevel@tonic-gate #define	move(x, y) close(y); dup(x); close(x);
197c478bd9Sstevel@tonic-gate 
20*11a8fa6cSceastha extern void err();
21*11a8fa6cSceastha 
22*11a8fa6cSceastha int
23*11a8fa6cSceastha corout(char *in, char *out, char *rprog, char *arg, int outlen)
247c478bd9Sstevel@tonic-gate {
257c478bd9Sstevel@tonic-gate 	int pipev[2], fr1, fr2, fw1, fw2, n;
267c478bd9Sstevel@tonic-gate 	int status;
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate 	pipe(pipev);
297c478bd9Sstevel@tonic-gate 	fr1 = pipev[0];
307c478bd9Sstevel@tonic-gate 	fw1 = pipev[1];
317c478bd9Sstevel@tonic-gate 	pipe(pipev);
327c478bd9Sstevel@tonic-gate 	fr2 = pipev[0];
337c478bd9Sstevel@tonic-gate 	fw2 = pipev[1];
34*11a8fa6cSceastha 	if (fork() == 0) {
357c478bd9Sstevel@tonic-gate 		close(fw1);
367c478bd9Sstevel@tonic-gate 		close(fr2);
377c478bd9Sstevel@tonic-gate 		move(fr1, 0);
387c478bd9Sstevel@tonic-gate 		move(fw2, 1);
397c478bd9Sstevel@tonic-gate 		execl(rprog, "deliv", arg, 0);
407c478bd9Sstevel@tonic-gate 		err("Can't run %s", rprog);
417c478bd9Sstevel@tonic-gate 	}
427c478bd9Sstevel@tonic-gate 	close(fw2);
437c478bd9Sstevel@tonic-gate 	close(fr1);
447c478bd9Sstevel@tonic-gate 	write(fw1, in, strlen(in));
457c478bd9Sstevel@tonic-gate 	close(fw1);
467c478bd9Sstevel@tonic-gate 	wait(&status);
477c478bd9Sstevel@tonic-gate 	n = read(fr2, out, outlen);
487c478bd9Sstevel@tonic-gate 	out[n] = 0;
497c478bd9Sstevel@tonic-gate 	close(fr2);
507c478bd9Sstevel@tonic-gate 	return (n);
517c478bd9Sstevel@tonic-gate }
52