date and time created 83/02/11 15:45:08 by rrh
[unix-history] / usr / src / usr.bin / lock / lock.c
CommitLineData
36e4dcd1 1static char *sccsid = "@(#)lock.c 4.2 (Berkeley) %G%";
d97d0c53
BJ
2#include <stdio.h>
3#include <sys/types.h>
36e4dcd1 4#include <sys/stat.h>
d97d0c53
BJ
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
36e4dcd1
BJ
21
22 /*
23 * Ignore signals generated from tty keyboard. These signals
24 * are for xBSD only. This program should be compiled with
25 * the jobs library (cc ... -ljobs).
26 */
27 sigset( SIGINT, SIG_IGN );
28 sigset( SIGQUIT, SIG_IGN );
29 sigset( SIGTSTP, SIG_IGN );
30
d97d0c53
BJ
31 if (argc > 0)
32 argv[0] = 0;
33 if (gtty(0, &tty))
34 exit(1);
35 ntty = tty; ntty.sg_flags &= ~ECHO;
36 stty(0, &ntty);
37 printf("Key: ");
38 fgets(s, sizeof s, stdin);
39 printf("\nAgain: ");
40 fgets(s1, sizeof s1, stdin);
41 putchar('\n');
42 if (strcmp(s1, s)) {
43 putchar(07);
44 stty(0, &tty);
45 exit(1);
46 }
47 s[0] = 0;
48 for (;;) {
49 fgets(s, sizeof s, stdin);
50 if (strcmp(s1, s) == 0)
51 break;
52 if (strcmp(s, masterp) == 0)
53 break;
54 putchar(07);
55 if (gtty(0, &ntty))
56 exit(1);
57 }
58 stty(0, &tty);
59}