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