note other reasons for pclose to return -1; wait(2) -> wait4(2)
[unix-history] / usr / src / usr.bin / lock / lock.c
index a3ded9f..01fe469 100644 (file)
@@ -1,18 +1,29 @@
 /*
 /*
- * 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) 1980, 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+"@(#) Copyright (c) 1980, 1987 Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)lock.c     5.3 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)lock.c     5.7 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Lock a terminal up until the given key is entered, until the root
 
 /*
  * Lock a terminal up until the given key is entered, until the root
@@ -29,10 +40,9 @@ static char sccsid[] = "@(#)lock.c   5.3 (Berkeley) %G%";
 #include <pwd.h>
 #include <sgtty.h>
 #include <stdio.h>
 #include <pwd.h>
 #include <sgtty.h>
 #include <stdio.h>
+#include <ctype.h>
 
 #define        TIMEOUT 15
 
 #define        TIMEOUT 15
-#define        YES     1
-#define        NO      0
 
 int    quit(), bye(), hi();
 
 
 int    quit(), bye(), hi();
 
@@ -43,27 +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 ((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;
 
@@ -153,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",
@@ -174,10 +192,3 @@ bye()
        puts("lock: timeout");
        exit(1);
 }
        puts("lock: timeout");
        exit(1);
 }
-
-static
-usage()
-{
-       puts("Usage: lock [-p] [-timeout]");
-       exit(1);
-}