-/* $OpenBSD: lock.c,v 1.5 1996/08/06 18:10:23 deraadt Exp $ */
+/* $OpenBSD: lock.c,v 1.6 1996/09/06 01:57:15 downsj Exp $ */
/* $NetBSD: lock.c,v 1.8 1996/05/07 18:32:31 jtc Exp $ */
/*
#if 0
static char sccsid[] = "@(#)lock.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: lock.c,v 1.5 1996/08/06 18:10:23 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: lock.c,v 1.6 1996/09/06 01:57:15 downsj Exp $";
#endif /* not lint */
/*
struct timeval zerotime;
struct termios tty, ntty;
long nexttime; /* keep the timeout time */
+int no_timeout; /* lock terminal forever */
/*ARGSUSED*/
main(argc, argv)
sectimeout = TIMEOUT;
mypw = NULL;
usemine = 0;
+ no_timeout = 0;
if (!(pw = getpwuid(getuid())))
errx(1, "unknown uid %d.", getuid());
- while ((ch = getopt(argc, argv, "pt:")) != EOF)
+ while ((ch = getopt(argc, argv, "npt:")) != EOF)
switch((char)ch) {
case 't':
if ((sectimeout = atoi(optarg)) <= 0)
usemine = 1;
mypw = strdup(pw->pw_passwd);
break;
+ case 'n':
+ no_timeout = 1;
+ break;
case '?':
default:
- fprintf(stderr, "usage: lock [-p] [-t timeout]\n");
+ fprintf(stderr, "usage: lock [-n] [-p] [-t timeout]\n");
exit(1);
}
timeout.tv_sec = sectimeout * 60;
ntimer.it_interval = zerotime;
ntimer.it_value = timeout;
- setitimer(ITIMER_REAL, &ntimer, &otimer);
+ if (!no_timeout)
+ setitimer(ITIMER_REAL, &ntimer, &otimer);
/* header info */
- printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
- ttynam, hostname, sectimeout, ap, tzn, ap + 19);
+ if (no_timeout) {
+ printf("lock: %s on %s. no timeout\ntime now is %.20s%s%s",
+ ttynam, hostname, ap, tzn, ap + 19);
+ } else {
+ printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
+ ttynam, hostname, sectimeout, ap, tzn, ap + 19);
+ }
for (;;) {
printf("Key: ");
{
struct timeval timval;
- if (!gettimeofday(&timval, (struct timezone *)NULL))
- printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
- (nexttime - timval.tv_sec) / 60, (nexttime - timval.tv_sec) % 60);
+ if (!gettimeofday(&timval, (struct timezone *)NULL)) {
+ (void)printf("lock: type in the unlock key. ");
+ if (no_timeout) {
+ putchar('\n');
+ } else {
+ printf("timeout in %ld:%ld minutes\n",
+ (nexttime - timval.tv_sec) / 60,
+ (nexttime - timval.tv_sec) % 60);
+ }
+ }
}
void
void
bye()
{
- (void)tcsetattr(0, TCSADRAIN, &tty);
- printf("lock: timeout\n");
- exit(1);
+ if (!no_timeout) {
+ (void)tcsetattr(0, TCSADRAIN, &tty);
+ printf("lock: timeout\n");
+ exit(1);
+ }
}