svn commit: r224296 - stable/8/usr.bin/lock

Ed Schouten ed at FreeBSD.org
Sun Jul 24 19:19:50 UTC 2011


Author: ed
Date: Sun Jul 24 19:19:50 2011
New Revision: 224296
URL: http://svn.freebsd.org/changeset/base/224296

Log:
  MFC r216696 and r216737:
  
    Slightly improve output of lock(1).
  
    - Remove the /dev/ portion of the TTY name.
    - In case we use lock -p, print the username that was used to obtain the
      password hash.

Modified:
  stable/8/usr.bin/lock/lock.c
Directory Properties:
  stable/8/usr.bin/lock/   (props changed)

Modified: stable/8/usr.bin/lock/lock.c
==============================================================================
--- stable/8/usr.bin/lock/lock.c	Sun Jul 24 19:13:54 2011	(r224295)
+++ stable/8/usr.bin/lock/lock.c	Sun Jul 24 19:19:50 2011	(r224296)
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <ctype.h>
 #include <errno.h>
+#include <paths.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -102,6 +103,7 @@ main(int argc, char **argv)
 	openlog("lock", LOG_ODELAY, LOG_AUTH);
 
 	sectimeout = TIMEOUT;
+	pw = NULL;
 	mypw = NULL;
 	usemine = 0;
 	no_timeout = 0;
@@ -137,6 +139,8 @@ main(int argc, char **argv)
 	gethostname(hostname, sizeof(hostname));
 	if (!(ttynam = ttyname(0)))
 		errx(1, "not a terminal?");
+	if (strncmp(ttynam, _PATH_DEV, strlen(_PATH_DEV)) == 0)
+		ttynam += strlen(_PATH_DEV);
 	if (gettimeofday(&timval, (struct timezone *)NULL))
 		err(1, "gettimeofday");
 	nexttime = timval.tv_sec + (sectimeout * 60);
@@ -196,7 +200,11 @@ main(int argc, char **argv)
 	}
 
 	/* header info */
-	(void)printf("lock: %s on %s.", ttynam, hostname);
+	if (pw != NULL)
+		(void)printf("lock: %s using %s on %s.", pw->pw_name,
+		    ttynam, hostname);
+	else
+		(void)printf("lock: %s on %s.", ttynam, hostname);
 	if (no_timeout)
 		(void)printf(" no timeout.");
 	else


More information about the svn-src-stable mailing list