xref: /original-bsd/usr.bin/learn/learn/maktee.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)maktee.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include "stdio.h"
13 #include "signal.h"
14 #include "lrnref.h"
15 
16 static int oldout;
17 static char tee[50];
18 
19 maktee()
20 {
21 	int fpip[2], in, out;
22 
23 	if (tee[0] == 0)
24 		sprintf(tee, "%s/bin/lrntee", direct);
25 	pipe(fpip);
26 	in = fpip[0];
27 	out= fpip[1];
28 	if (fork() == 0) {
29 		signal(SIGINT, SIG_IGN);
30 		close(0);
31 		close(out);
32 		dup(in);
33 		close(in);
34 		execl (tee, "lrntee", 0);
35 		perror(tee);
36 		fprintf(stderr, "Maktee:  lrntee exec failed\n");
37 		exit(1);
38 	}
39 	close(in);
40 	fflush(stdout);
41 	oldout = dup(1);
42 	close(1);
43 	if (dup(out) != 1) {
44 		perror("dup");
45 		fprintf(stderr, "Maktee:  error making tee for copyout\n");
46 	}
47 	close(out);
48 	return(1);
49 }
50 
51 untee()
52 {
53 	int x;
54 
55 	fflush(stdout);
56 	close(1);
57 	dup(oldout);
58 	close(oldout);
59 	wait(&x);
60 }
61