1*12989Ssam #ifndef lint 2*12989Ssam static char *sccsid = "@(#)lock.c 4.3 (Berkeley) 06/10/83"; 3*12989Ssam #endif 4*12989Ssam 5*12989Ssam /* 6*12989Ssam * Lock a terminal up until the knowledgeable Joe returns. 7*12989Ssam */ 81041Sbill #include <stdio.h> 91041Sbill #include <sys/types.h> 105748Sroot #include <sys/stat.h> 111041Sbill #include <signal.h> 121041Sbill #include <sgtty.h> 131041Sbill 141041Sbill char masterp[] = "hasta la vista\n"; 151041Sbill struct sgttyb tty, ntty; 161041Sbill char s[BUFSIZ], s1[BUFSIZ]; 171041Sbill 181041Sbill main(argc, argv) 191041Sbill char **argv; 201041Sbill { 211041Sbill register int t; 221041Sbill struct stat statb; 231041Sbill 24*12989Ssam signal(SIGINT, SIG_IGN); 25*12989Ssam signal(SIGQUIT, SIG_IGN); 26*12989Ssam signal(SIGTSTP, SIG_IGN); 271041Sbill if (argc > 0) 281041Sbill argv[0] = 0; 29*12989Ssam if (ioctl(0, TIOCGETP, &tty)) 301041Sbill exit(1); 311041Sbill ntty = tty; ntty.sg_flags &= ~ECHO; 32*12989Ssam ioctl(0, TIOCSETN, &ntty); 331041Sbill printf("Key: "); 341041Sbill fgets(s, sizeof s, stdin); 351041Sbill printf("\nAgain: "); 361041Sbill fgets(s1, sizeof s1, stdin); 371041Sbill putchar('\n'); 381041Sbill if (strcmp(s1, s)) { 391041Sbill putchar(07); 401041Sbill stty(0, &tty); 411041Sbill exit(1); 421041Sbill } 431041Sbill s[0] = 0; 441041Sbill for (;;) { 451041Sbill fgets(s, sizeof s, stdin); 461041Sbill if (strcmp(s1, s) == 0) 471041Sbill break; 481041Sbill if (strcmp(s, masterp) == 0) 491041Sbill break; 501041Sbill putchar(07); 51*12989Ssam if (ioctl(0, TIOCGETP, &ntty)) 521041Sbill exit(1); 531041Sbill } 54*12989Ssam ioctl(0, TIOCSETN, &tty); 551041Sbill } 56