summaryrefslogtreecommitdiff
path: root/usr.bin/lock/lock.c
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1996-09-06 01:57:16 +0000
committerJason Downs <downsj@cvs.openbsd.org>1996-09-06 01:57:16 +0000
commit700e161ba362e86b77c24b80e9a47a8def3347b8 (patch)
tree40e6b0f01c331e53ace350346068362fbca58601 /usr.bin/lock/lock.c
parentf85c556d4c3e61eb22703dd355af7d25b5d7859e (diff)
Add -n/no timeout option. FreeBSD PR bin/1567, obrien@Nuxi.cs.ucdavis.edu.
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);
+ }
}