require -t flag for command line timeout value
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 6 Dec 1988 13:37:37 +0000 (05:37 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 6 Dec 1988 13:37:37 +0000 (05:37 -0800)
SCCS-vsn: usr.bin/lock/lock.c 5.7
SCCS-vsn: usr.bin/lock/lock.1 6.4

usr/src/usr.bin/lock/lock.1
usr/src/usr.bin/lock/lock.c

index 3b28f78..c4ac6a0 100644 (file)
@@ -1,8 +1,19 @@
-.\" Copyright (c) 1980 Regents of the University of California.
-.\" All rights reserved.  The Berkeley software License Agreement
-.\" specifies the terms and conditions for redistribution.
+.\" Copyright (c) 1987 The Regents of the University of California.
+.\" All rights reserved.
 .\"
 .\"
-.\"    @(#)lock.1      6.3 (Berkeley) %G%
+.\" Redistribution and use in source and binary forms are permitted
+.\" provided that the above copyright notice and this paragraph are
+.\" duplicated in all such forms and that any documentation,
+.\" advertising materials, and other materials related to such
+.\" distribution and use acknowledge that the software was developed
+.\" by the University of California, Berkeley.  The name of the
+.\" University may not be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+.\"
+.\"    @(#)lock.1      6.4 (Berkeley) %G%
 .\"
 .TH LOCK 1 ""
 .UC
 .\"
 .TH LOCK 1 ""
 .UC
@@ -13,7 +24,7 @@ lock \- reserve a terminal
 [
 .B -p
 ] [
 [
 .B -p
 ] [
-.B -number
+.B -t timeout
 ]
 .br
 .SH DESCRIPTION
 ]
 .br
 .SH DESCRIPTION
@@ -23,6 +34,6 @@ repeated.  There are three other conditions under which it will terminate: it
 accepts the password for root as an alternative to the one given by the
 user, it will timeout after some interval of time, and it may be killed by
 somebody with the appropriate permission. The default time limit is 15 minutes
 accepts the password for root as an alternative to the one given by the
 user, it will timeout after some interval of time, and it may be killed by
 somebody with the appropriate permission. The default time limit is 15 minutes
-but it may be changed with the \fI-number\fP option where \fInumber\fP is the
+but it may be changed with the \fI-t\fP option where \fItimeout\fP is the
 time limit in minutes.  The \fI-p\fP option has \fIlock\fP use the user's
 standard password instead of requesting another one.
 time limit in minutes.  The \fI-p\fP option has \fIlock\fP use the user's
 standard password instead of requesting another one.
index 308db37..01fe469 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)lock.c     5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)lock.c     5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -43,8 +43,6 @@ static char sccsid[] = "@(#)lock.c    5.6 (Berkeley) %G%";
 #include <ctype.h>
 
 #define        TIMEOUT 15
 #include <ctype.h>
 
 #define        TIMEOUT 15
-#define        YES     1
-#define        NO      0
 
 int    quit(), bye(), hi();
 
 
 int    quit(), bye(), hi();
 
@@ -55,31 +53,35 @@ long        nexttime;                       /* keep the timeout time */
 
 /*ARGSUSED*/
 main(argc, argv)
 
 /*ARGSUSED*/
 main(argc, argv)
-       int     argc;
-       char    **argv;
+       int argc;
+       char **argv;
 {
 {
-       struct passwd   *root_pwd, *my_pwd;
-       struct timeval  timval;
-       struct itimerval        ntimer, otimer;
-       struct tm       *timp;
-       int     sectimeout = TIMEOUT,
-               use_mine;
-       char    *ttynam, *ap, *tzn,
-               hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ],
-               *crypt(), *index(), *ttyname();
-
-       use_mine = NO;
-       for (++argv; *argv; ++argv) {
-               if (argv[0][0] != '-')
-                       usage();
-               if (argv[0][1] == 'p')
-                       use_mine = YES;
-               else if (!isdigit(argv[0][1])) {
-                       fprintf(stderr, "lock: illegal option -- %c\n", argv[0][1]);
-                       usage();
-               }
-               else if ((sectimeout = atoi(*argv + 1)) <= 0)
-                       usage();
+       extern char *optarg;
+       extern int optind;
+       struct passwd *root_pwd, *my_pwd;
+       struct timeval timval;
+       struct itimerval ntimer, otimer;
+       struct tm *timp;
+       int ch, sectimeout, use_mine;
+       char *ttynam, *ap, *tzn;
+       char hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ];
+       char *crypt(), *index(), *ttyname();
+
+       use_mine = 0;
+       sectimeout = TIMEOUT;
+       while ((ch = getopt(argc, argv, "pt:")) != EOF)
+               switch((char)ch) {
+               case 't':
+                       if ((sectimeout = atoi(optarg)) <= 0)
+                               exit(0);
+                       break;
+               case 'p':
+                       use_mine = 1;
+                       break;
+               case '?':
+               default:
+                       fputs("usage: lock [-p] [-t timeout]\n", stderr);
+                       exit(1);
        }
        timeout.tv_sec = sectimeout * 60;
 
        }
        timeout.tv_sec = sectimeout * 60;
 
@@ -169,7 +171,7 @@ main(argc, argv)
 static
 hi()
 {
 static
 hi()
 {
-       struct timeval  timval;
+       struct timeval timval;
 
        if (!gettimeofday(&timval, (struct timezone *)NULL))
            printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
 
        if (!gettimeofday(&timval, (struct timezone *)NULL))
            printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
@@ -190,10 +192,3 @@ bye()
        puts("lock: timeout");
        exit(1);
 }
        puts("lock: timeout");
        exit(1);
 }
-
-static
-usage()
-{
-       fputs("usage: lock [-p] [-timeout]\n", stderr);
-       exit(1);
-}