summaryrefslogtreecommitdiff
path: root/usr.bin/lock/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/lock/lock.c')
-rw-r--r--usr.bin/lock/lock.c46
1 files changed, 33 insertions, 13 deletions
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);
+ }
}