svn commit: r201771 - user/ed/utmpx/lib/libc/gen

Ed Schouten ed at FreeBSD.org
Fri Jan 8 07:29:52 UTC 2010


Author: ed
Date: Fri Jan  8 07:29:51 2010
New Revision: 201771
URL: http://svn.freebsd.org/changeset/base/201771

Log:
  Also add an upgrade path for lastlogin.
  
  Right now we only have one version of the file format, so there's
  nothing to do here, except truncating it. Future versions of the
  implementation should have some conversion routines.

Modified:
  user/ed/utmpx/lib/libc/gen/pututxline.c

Modified: user/ed/utmpx/lib/libc/gen/pututxline.c
==============================================================================
--- user/ed/utmpx/lib/libc/gen/pututxline.c	Fri Jan  8 05:53:11 2010	(r201770)
+++ user/ed/utmpx/lib/libc/gen/pututxline.c	Fri Jan  8 07:29:51 2010	(r201771)
@@ -181,6 +181,26 @@ done:
 }
 
 static void
+utx_lastlogin_upgrade(void)
+{
+	int fd;
+	struct stat sb;
+
+	fd = _open(_PATH_UTX_LASTLOGIN, O_RDWR, 0644);
+	if (fd < 0)
+		return;
+
+	/*
+	 * Truncate broken lastlogin files.  In the future we should
+	 * check for older versions of the file format here and try to
+	 * upgrade it.
+	 */
+	if (_fstat(fd, &sb) != -1 && sb.st_size % sizeof(struct futx) != 0)
+		ftruncate(fd, 0);
+	_close(fd);
+}
+
+static void
 utx_log_add(const struct futx *fu)
 {
 	struct {
@@ -219,6 +239,7 @@ pututxline(const struct utmpx *utmpx)
 	case BOOT_TIME:
 	case SHUTDOWN_TIME:
 		utx_active_purge();
+		utx_lastlogin_upgrade();
 		break;
 	case OLD_TIME:
 	case NEW_TIME:


More information about the svn-src-user mailing list