Commit | Line | Data |
---|---|---|
4ca10280 SL |
1 | #ifndef lint |
2 | static char *sccsid = "@(#)lock.c 4.3 (Berkeley) %G%"; | |
3 | #endif | |
4 | ||
5 | /* | |
6 | * Lock a terminal up until the knowledgeable Joe returns. | |
7 | */ | |
d97d0c53 BJ |
8 | #include <stdio.h> |
9 | #include <sys/types.h> | |
36e4dcd1 | 10 | #include <sys/stat.h> |
d97d0c53 BJ |
11 | #include <signal.h> |
12 | #include <sgtty.h> | |
13 | ||
d97d0c53 BJ |
14 | char masterp[] = "hasta la vista\n"; |
15 | struct sgttyb tty, ntty; | |
16 | char s[BUFSIZ], s1[BUFSIZ]; | |
17 | ||
18 | main(argc, argv) | |
19 | char **argv; | |
20 | { | |
21 | register int t; | |
22 | struct stat statb; | |
23 | ||
4ca10280 SL |
24 | signal(SIGINT, SIG_IGN); |
25 | signal(SIGQUIT, SIG_IGN); | |
26 | signal(SIGTSTP, SIG_IGN); | |
d97d0c53 BJ |
27 | if (argc > 0) |
28 | argv[0] = 0; | |
4ca10280 | 29 | if (ioctl(0, TIOCGETP, &tty)) |
d97d0c53 BJ |
30 | exit(1); |
31 | ntty = tty; ntty.sg_flags &= ~ECHO; | |
4ca10280 | 32 | ioctl(0, TIOCSETN, &ntty); |
d97d0c53 BJ |
33 | printf("Key: "); |
34 | fgets(s, sizeof s, stdin); | |
35 | printf("\nAgain: "); | |
36 | fgets(s1, sizeof s1, stdin); | |
37 | putchar('\n'); | |
38 | if (strcmp(s1, s)) { | |
39 | putchar(07); | |
40 | stty(0, &tty); | |
41 | exit(1); | |
42 | } | |
43 | s[0] = 0; | |
44 | for (;;) { | |
45 | fgets(s, sizeof s, stdin); | |
46 | if (strcmp(s1, s) == 0) | |
47 | break; | |
48 | if (strcmp(s, masterp) == 0) | |
49 | break; | |
50 | putchar(07); | |
4ca10280 | 51 | if (ioctl(0, TIOCGETP, &ntty)) |
d97d0c53 BJ |
52 | exit(1); |
53 | } | |
4ca10280 | 54 | ioctl(0, TIOCSETN, &tty); |
d97d0c53 | 55 | } |