summaryrefslogtreecommitdiffstats
path: root/usr.bin/lock
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2002-07-28 07:13:53 +0000
committerdd <dd@FreeBSD.org>2002-07-28 07:13:53 +0000
commit82b3ef03869b7a2ffde4e167655034422dfe28a8 (patch)
treed9bd62e931400cb14faff2db4f3d80180506b3e2 /usr.bin/lock
parenta78f016a2098b07bcd213887af09f2539a1eb3af (diff)
downloadFreeBSD-src-82b3ef03869b7a2ffde4e167655034422dfe28a8.zip
FreeBSD-src-82b3ef03869b7a2ffde4e167655034422dfe28a8.tar.gz
Add a -v option that prevents switching virtual terminals while this
terminal is locked. This permits the user to easily lock the entire console from a single terminal.
Diffstat (limited to 'usr.bin/lock')
-rw-r--r--usr.bin/lock/lock.114
-rw-r--r--usr.bin/lock/lock.c46
2 files changed, 47 insertions, 13 deletions
diff --git a/usr.bin/lock/lock.1 b/usr.bin/lock/lock.1
index 785fc4a..c162c29 100644
--- a/usr.bin/lock/lock.1
+++ b/usr.bin/lock/lock.1
@@ -32,7 +32,7 @@
.\" @(#)lock.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd June 6, 1993
+.Dd July 10, 2002
.Dt LOCK 1
.Os
.Sh NAME
@@ -40,8 +40,7 @@
.Nd reserve a terminal
.Sh SYNOPSIS
.Nm
-.Op Fl n
-.Op Fl p
+.Op Fl npv
.Op Fl t Ar timeout
.Sh DESCRIPTION
The
@@ -65,6 +64,15 @@ is used.
The time limit (default 15 minutes) is changed to
.Ar timeout
minutes.
+.It Fl v
+Disable switching virtual terminals while this terminal is locked.
+This option is implemented in a way similar to the
+.Fl S
+option of
+.Xr vidcontrol 1 ,
+and is only available if the terminal in question is a
+.Xr syscons 4
+virtual terminal.
.El
.Sh HISTORY
The
diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c
index 61d12e0..17f7312 100644
--- a/usr.bin/lock/lock.c
+++ b/usr.bin/lock/lock.c
@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/signal.h>
+#include <sys/consio.h>
#include <err.h>
#include <ctype.h>
#include <pwd.h>
@@ -83,6 +84,7 @@ struct timeval zerotime;
struct sgttyb tty, ntty;
long nexttime; /* keep the timeout time */
int no_timeout; /* lock terminal forever */
+int vtyunlock; /* Unlock flag and code. */
/*ARGSUSED*/
int
@@ -95,7 +97,7 @@ main(argc, argv)
time_t timval_sec;
struct itimerval ntimer, otimer;
struct tm *timp;
- int ch, failures, sectimeout, usemine;
+ int ch, failures, sectimeout, usemine, vtylock;
char *ap, *mypw, *ttynam, *tzn;
char hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ];
@@ -105,7 +107,8 @@ main(argc, argv)
mypw = NULL;
usemine = 0;
no_timeout = 0;
- while ((ch = getopt(argc, argv, "npt:")) != -1)
+ vtylock = 0;
+ while ((ch = getopt(argc, argv, "npt:v")) != -1)
switch((char)ch) {
case 't':
if ((sectimeout = atoi(optarg)) <= 0)
@@ -120,6 +123,9 @@ main(argc, argv)
case 'n':
no_timeout = 1;
break;
+ case 'v':
+ vtylock = 1;
+ break;
case '?':
default:
usage();
@@ -177,15 +183,31 @@ main(argc, argv)
ntimer.it_value = timeout;
if (!no_timeout)
setitimer(ITIMER_REAL, &ntimer, &otimer);
+ if (vtylock) {
+ /*
+ * If this failed, we want to err out; warn isn't good
+ * enough, since we don't want the user to think that
+ * everything is nice and locked because they got a
+ * "Key:" prompt.
+ */
+ if (ioctl(0, VT_LOCKSWITCH, &vtylock) == -1) {
+ (void)ioctl(0, TIOCSETP, &tty);
+ err(1, "locking vty");
+ }
+ vtyunlock = 0x2;
+ }
/* header info */
- if (no_timeout) {
-(void)printf("lock: %s on %s. no timeout\ntime now is %.20s%s%s",
- ttynam, hostname, ap, tzn, ap + 19);
- } else {
-(void)printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
- ttynam, hostname, sectimeout, ap, tzn, ap + 19);
- }
+ (void)printf("lock: %s on %s.", ttynam, hostname);
+ if (no_timeout)
+ (void)printf(" no timeout.");
+ else
+ (void)printf(" timeout in %d minute%s.", sectimeout,
+ sectimeout != 1 ? "s" : "");
+ if (vtylock)
+ (void)printf(" vty locked.");
+ (void)printf("\ntime now is %.20s%s%s", ap, tzn, ap + 19);
+
failures = 0;
for (;;) {
@@ -222,7 +244,7 @@ main(argc, argv)
static void
usage()
{
- (void)fprintf(stderr, "usage: lock [-n] [-p] [-t timeout]\n");
+ (void)fprintf(stderr, "usage: lock [-npv] [-t timeout]\n");
exit(1);
}
@@ -248,6 +270,8 @@ quit(int signo __unused)
{
(void)putchar('\n');
(void)ioctl(0, TIOCSETP, &tty);
+ if (vtyunlock)
+ (void)ioctl(0, VT_LOCKSWITCH, &vtyunlock);
exit(0);
}
@@ -256,6 +280,8 @@ bye(int signo __unused)
{
if (!no_timeout) {
(void)ioctl(0, TIOCSETP, &tty);
+ if (vtyunlock)
+ (void)ioctl(0, VT_LOCKSWITCH, &vtyunlock);
(void)printf("lock: timeout\n");
exit(1);
}
OpenPOWER on IntegriCloud