xref: /csrg-svn/usr.bin/lock/lock.c (revision 1041)
1*1041Sbill static char *sccsid = "@(#)lock.c	4.1 (Berkeley) 10/01/80";
2*1041Sbill #include <stdio.h>
3*1041Sbill #include <sys/types.h>
4*1041Sbill #include <stat.h>
5*1041Sbill #include <signal.h>
6*1041Sbill #include <sgtty.h>
7*1041Sbill 
8*1041Sbill /*
9*1041Sbill  * Lock a terminal up until the knowledgeable Joe returns.
10*1041Sbill  */
11*1041Sbill char	masterp[] =	"hasta la vista\n";
12*1041Sbill struct	sgttyb tty, ntty;
13*1041Sbill char	s[BUFSIZ], s1[BUFSIZ];
14*1041Sbill 
15*1041Sbill main(argc, argv)
16*1041Sbill 	char **argv;
17*1041Sbill {
18*1041Sbill 	register int t;
19*1041Sbill 	struct stat statb;
20*1041Sbill 
21*1041Sbill 	for (t = 1; t <= 16; t++)
22*1041Sbill 		if (t != SIGHUP)
23*1041Sbill 		signal(t, SIG_IGN);
24*1041Sbill 	if (argc > 0)
25*1041Sbill 		argv[0] = 0;
26*1041Sbill 	if (gtty(0, &tty))
27*1041Sbill 		exit(1);
28*1041Sbill 	ntty = tty; ntty.sg_flags &= ~ECHO;
29*1041Sbill 	stty(0, &ntty);
30*1041Sbill 	printf("Key: ");
31*1041Sbill 	fgets(s, sizeof s, stdin);
32*1041Sbill 	printf("\nAgain: ");
33*1041Sbill 	fgets(s1, sizeof s1, stdin);
34*1041Sbill 	putchar('\n');
35*1041Sbill 	if (strcmp(s1, s)) {
36*1041Sbill 		putchar(07);
37*1041Sbill 		stty(0, &tty);
38*1041Sbill 		exit(1);
39*1041Sbill 	}
40*1041Sbill 	s[0] = 0;
41*1041Sbill 	for (;;) {
42*1041Sbill 		fgets(s, sizeof s, stdin);
43*1041Sbill 		if (strcmp(s1, s) == 0)
44*1041Sbill 			break;
45*1041Sbill 		if (strcmp(s, masterp) == 0)
46*1041Sbill 			break;
47*1041Sbill 		putchar(07);
48*1041Sbill 		if (gtty(0, &ntty))
49*1041Sbill 			exit(1);
50*1041Sbill 	}
51*1041Sbill 	stty(0, &tty);
52*1041Sbill }
53