It doesn't make sense to allow the user to simultaneously set -n
(never time out) and also set -t timeout (release the terminal after
timeout minutes).

ok?

Index: lock.c
===================================================================
RCS file: /cvs/src/usr.bin/lock/lock.c,v
retrieving revision 1.41
diff -u -p -r1.41 lock.c
--- lock.c      6 Sep 2017 21:02:31 -0000       1.41
+++ lock.c      4 Jul 2019 17:41:35 -0000
@@ -63,7 +63,9 @@
 
 void bye(int);
 void hi(int);
+void usage(void);
 
+int    custom_timeout;
 int    no_timeout;                     /* lock terminal forever */
 
 int
@@ -84,7 +86,7 @@ main(int argc, char *argv[])
        sectimeout = TIMEOUT;
        style = NULL;
        usemine = 0;
-       no_timeout = 0;
+       custom_timeout = no_timeout = 0;
        memset(&timeout, 0, sizeof(timeout));
 
        if (pledge("stdio rpath wpath getpw tty proc exec", NULL) == -1)
@@ -116,21 +118,23 @@ main(int argc, char *argv[])
                        usemine = 1;
                        break;
                case 't':
+                       if (no_timeout)
+                               usage();
                        sectimeout = strtonum(optarg, 1, INT_MAX, &errstr);
                        if (errstr)
                                errx(1, "timeout %s: %s", errstr, optarg);
+                       custom_timeout = 1;
                        break;
                case 'p':
                        usemine = 1;
                        break;
                case 'n':
+                       if (custom_timeout)
+                               usage();
                        no_timeout = 1;
                        break;
                default:
-                       fprintf(stderr,
-                           "usage: %s [-np] [-a style] [-t timeout]\n",
-                           getprogname());
-                       exit(1);
+                       usage();
                }
        }
        timeout.tv_sec = sectimeout * 60;
@@ -251,4 +255,12 @@ bye(int signo)
        if (!no_timeout)
                warnx("timeout");
        _exit(1);
+}
+
+void
+usage(void)
+{
+       fprintf(stderr, "usage: %s [-p] [-a style] [-n | -t timeout]\n",
+           getprogname());
+       exit(1);
 }
Index: lock.1
===================================================================
RCS file: /cvs/src/usr.bin/lock/lock.1,v
retrieving revision 1.17
diff -u -p -r1.17 lock.1
--- lock.1      14 Aug 2013 08:39:26 -0000      1.17
+++ lock.1      4 Jul 2019 17:41:35 -0000
@@ -37,9 +37,9 @@
 .Nd reserve a terminal
 .Sh SYNOPSIS
 .Nm lock
-.Op Fl np
+.Op Fl p
 .Op Fl a Ar style
-.Op Fl t Ar timeout
+.Op Fl n | Fl t Ar timeout
 .Sh DESCRIPTION
 .Nm
 requests a password from the user, reads it again for verification

Reply via email to