From dde5a60363e2170422f1619395f01b9586e8a8f1 Mon Sep 17 00:00:00 2001 From: downsj Date: Fri, 6 Sep 1996 01:57:15 +0000 Subject: [PATCH] Add -n/no timeout option. FreeBSD PR bin/1567, obrien@Nuxi.cs.ucdavis.edu. --- usr.bin/lock/lock.1 | 5 ++++- usr.bin/lock/lock.c | 46 ++++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/usr.bin/lock/lock.1 b/usr.bin/lock/lock.1 index fc422c87f20..ad4ba6725ef 100644 --- a/usr.bin/lock/lock.1 +++ b/usr.bin/lock/lock.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: lock.1,v 1.2 1996/06/26 05:35:55 deraadt Exp $ +.\" $OpenBSD: lock.1,v 1.3 1996/09/06 01:57:15 downsj Exp $ .\" $NetBSD: lock.1,v 1.4 1994/12/22 01:16:21 jtc Exp $ .\" .\" Copyright (c) 1987, 1990, 1993 @@ -42,6 +42,7 @@ .Nd reserve a terminal .Sh SYNOPSIS .Nm lock +.Op Fl n .Op Fl p .Op Fl t Ar timeout .Sh DESCRIPTION @@ -56,6 +57,8 @@ with the appropriate permission. Options: .Pp .Bl -tag -width Fl +.It Fl n +Don't use a timeout value. Terminal will be locked forever. .It Fl p A password is not requested, instead the user's current login password is used. diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c index cf100454cbf..8ce04e64e6a 100644 --- a/usr.bin/lock/lock.c +++ b/usr.bin/lock/lock.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #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 */ /* @@ -80,6 +80,7 @@ struct timeval timeout; struct timeval zerotime; struct termios tty, ntty; long nexttime; /* keep the timeout time */ +int no_timeout; /* lock terminal forever */ /*ARGSUSED*/ main(argc, argv) @@ -100,11 +101,12 @@ 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) @@ -114,9 +116,12 @@ main(argc, argv) 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; @@ -170,11 +175,17 @@ main(argc, argv) 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: "); @@ -236,9 +247,16 @@ hi() { 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 @@ -252,7 +270,9 @@ quit() 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); + } } -- 2.20.1