On Thu, Jul 04, 2019 at 11:35:59PM -0600, Theo de Raadt wrote: > Klemens Nanni <k...@openbsd.org> wrote: > > > On Thu, Jul 04, 2019 at 12:43:21PM -0500, Scott Cheloha wrote: > > > 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). > > > Makes sense but the synopsis should probably stay the same. You could > > simply print usage like chmod(8) or explicitly state their mutual > > exclusiveness in an error message like pfctl(8) does. I prefer the > > former here.
So I should change the usage but not the manpage synopsis? Or neither should change but I should document that the options are incompatible? > I agree on that. Being excessively precise with nested [] can be > annoying and hide the simple case. That sorta makes sense. Still unsure what you guys would prefer. Is this any better? 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 5 Jul 2019 13:55:42 -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 [-np] [-a style] [-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 5 Jul 2019 13:55:42 -0000 @@ -69,6 +69,9 @@ to get the standard prompt for that .It Fl n Don't use a timeout value. Terminal will be locked forever. +This option is incompatible with the +.Fl t +option. .It Fl p A password is not requested, instead the user's current login password is used. @@ -85,6 +88,9 @@ password. The time limit (default 15 minutes) is changed to .Ar timeout minutes. +This option is incompatible with the +.Fl n +option. .El .Sh SEE ALSO .Xr skey 1 ,