xref: /original-bsd/usr.bin/learn/learn/wrapup.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[] = "@(#)wrapup.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include <sys/signal.h>
13 #include <stdio.h>
14 #include "lrnref.h"
15 #include "pathnames.h"
16 
17 extern char learnrc[];
18 
19 wrapup(n)
20 int n;
21 {
22 	FILE *fp;
23 /* this routine does not use 'system' because it wants interrupts turned off */
24 
25 	signal(SIGINT, SIG_IGN);
26 	chdir("..");
27 	if (fork() == 0) {
28 		signal(SIGHUP, SIG_IGN);
29 #if BSD4_2
30 		if (fork() == 0) {
31 			close(1);
32 			open(_PATH_TTY, 1);
33 			execl(_PATH_STTY, "stty", "new", 0);
34 		}
35 #endif
36 		execl(_PATH_RM, "rm", "-rf", dir, 0);
37 		perror(_PATH_RM);
38 		fprintf(stderr, "Wrapup:  can't find 'rm' command.\n");
39 		exit(0);
40 	}
41 	if (n == -1)
42 		unlink(learnrc);
43 	else if (!n && todo) {
44 		if ((fp=fopen(learnrc, "w")) == NULL)
45 			exit(0);
46 		fprintf(fp, "%s %s %d\n", sname, todo, speed);
47 		fclose(fp);
48 	}
49 	printf("Bye.\n");	/* not only does this reassure user but it
50 				stalls for time while deleting directory */
51 	fflush(stdout);
52 	wait(0);
53 	exit(n);
54 }
55