Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Feb 2012 20:28:42 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r231530 - in head: lib/libc/gen tools/build/mk tools/build/options usr.sbin usr.sbin/utx usr.sbin/utxrm
Message-ID:  <201202112028.q1BKSgY3046649@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sat Feb 11 20:28:42 2012
New Revision: 231530
URL: http://svn.freebsd.org/changeset/base/231530

Log:
  Replace utxrm(8) by utx(8).
  
  At first, I added a utility called utxrm(8) to remove stale entries from
  the user accounting database. It seems there are cases in which we need
  to perform different operations on the database as well. Simply rename
  utxrm(8) to utx(8) and place the old code under the "rm" command.
  
  In addition to "rm", this tool supports "boot" and "shutdown", which are
  going to be used by an rc-script which I am going to commit separately.

Added:
  head/usr.sbin/utx/
     - copied from r231514, head/usr.sbin/utxrm/
  head/usr.sbin/utx/utx.8
     - copied, changed from r231514, head/usr.sbin/utxrm/utxrm.8
  head/usr.sbin/utx/utx.c
     - copied, changed from r231514, head/usr.sbin/utxrm/utxrm.c
Deleted:
  head/usr.sbin/utx/utxrm.8
  head/usr.sbin/utx/utxrm.c
  head/usr.sbin/utxrm/
Modified:
  head/lib/libc/gen/getutxent.3
  head/tools/build/mk/OptionalObsoleteFiles.inc
  head/tools/build/options/WITHOUT_UTMPX
  head/usr.sbin/Makefile
  head/usr.sbin/utx/Makefile

Modified: head/lib/libc/gen/getutxent.3
==============================================================================
--- head/lib/libc/gen/getutxent.3	Sat Feb 11 20:08:46 2012	(r231529)
+++ head/lib/libc/gen/getutxent.3	Sat Feb 11 20:28:42 2012	(r231530)
@@ -423,7 +423,7 @@ The file format is invalid.
 .Xr tty 4 ,
 .Xr ac 8 ,
 .Xr newsyslog 8 ,
-.Xr utxrm 8
+.Xr utx 8
 .Sh STANDARDS
 The
 .Fn endutxent ,

Modified: head/tools/build/mk/OptionalObsoleteFiles.inc
==============================================================================
--- head/tools/build/mk/OptionalObsoleteFiles.inc	Sat Feb 11 20:08:46 2012	(r231529)
+++ head/tools/build/mk/OptionalObsoleteFiles.inc	Sat Feb 11 20:28:42 2012	(r231530)
@@ -3407,6 +3407,7 @@ OLD_FILES+=usr/bin/who
 OLD_FILES+=usr/bin/wtmpcvt
 OLD_FILES+=usr/sbin/ac
 OLD_FILES+=usr/sbin/lastlogin
+OLD_FILES+=usr/sbin/utx
 OLD_FILES+=usr/sbin/utxrm
 OLD_FILES+=usr/share/man/man1/last.1.gz
 OLD_FILES+=usr/share/man/man1/users.1.gz
@@ -3414,6 +3415,7 @@ OLD_FILES+=usr/share/man/man1/who.1.gz
 OLD_FILES+=usr/share/man/man1/wtmpcvt.1.gz
 OLD_FILES+=usr/share/man/man8/ac.8.gz
 OLD_FILES+=usr/share/man/man8/lastlogin.8.gz
+OLD_FILES+=usr/share/man/man8/utx.8.gz
 OLD_FILES+=usr/share/man/man8/utxrm.8.gz
 .endif
 

Modified: head/tools/build/options/WITHOUT_UTMPX
==============================================================================
--- head/tools/build/options/WITHOUT_UTMPX	Sat Feb 11 20:08:46 2012	(r231529)
+++ head/tools/build/options/WITHOUT_UTMPX	Sat Feb 11 20:28:42 2012	(r231530)
@@ -6,4 +6,4 @@ Set to not build user accounting tools s
 .Xr ac 8 ,
 .Xr lastlogin 8
 and
-.Xr utxrm 8 .
+.Xr utx 8 .

Modified: head/usr.sbin/Makefile
==============================================================================
--- head/usr.sbin/Makefile	Sat Feb 11 20:08:46 2012	(r231529)
+++ head/usr.sbin/Makefile	Sat Feb 11 20:28:42 2012	(r231530)
@@ -306,7 +306,7 @@ SUBDIR+=	usbdump
 .if ${MK_UTMPX} != "no"
 SUBDIR+=	ac
 SUBDIR+=	lastlogin
-SUBDIR+=	utxrm
+SUBDIR+=	utx
 .endif
 
 .if ${MK_WIRELESS} != "no"

Modified: head/usr.sbin/utx/Makefile
==============================================================================
--- head/usr.sbin/utxrm/Makefile	Sat Feb 11 11:11:13 2012	(r231514)
+++ head/usr.sbin/utx/Makefile	Sat Feb 11 20:28:42 2012	(r231530)
@@ -1,6 +1,9 @@
 # $FreeBSD$
 
-PROG=	utxrm
-MAN=	utxrm.8
+PROG=	utx
+MAN=	utx.8
+
+LINKS=	${BINDIR}/utx ${BINDIR}/utxrm
+MLINKS=	utx.8 utxrm.8
 
 .include <bsd.prog.mk>

Copied and modified: head/usr.sbin/utx/utx.8 (from r231514, head/usr.sbin/utxrm/utxrm.8)
==============================================================================
--- head/usr.sbin/utxrm/utxrm.8	Sat Feb 11 11:11:13 2012	(r231514, copy source)
+++ head/usr.sbin/utx/utx.8	Sat Feb 11 20:28:42 2012	(r231530)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
+.\" Copyright (c) 2011-2012 Ed Schouten <ed@FreeBSD.org>
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -24,20 +24,46 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 19, 2011
-.Dt UTXRM 8
+.Dd February 11, 2012
+.Dt UTX 8
 .Os
 .Sh NAME
+.Nm utx ,
 .Nm utxrm
-.Nd remove sessions from the user accounting database
+.Nd manage the user accounting database
 .Sh SYNOPSIS
 .Nm
+.Cm boot
+.Nm
+.Cm shutdown
+.Nm
+.Cm rm
+.Ar identifier
+.Ar ...
+.Nm utxrm
 .Ar identifier
 .Ar ...
 .Sh DESCRIPTION
 The
 .Nm
-utility can be used to remove stale sessions from the user accounting
+utility can be used to perform operations on the user accounting
+database, as done by
+.Xr pututxline 3 .
+.Pp
+The first argument to
+.Nm
+indicates an action to be performed:
+.Bl -tag -width ".Cm shutdown"
+.It Cm boot
+Write a boot time record to the user accounting database.
+This option should typically only be used by
+.Xr rc 8 .
+.It Cm shutdown
+Write a shutdown time record to the user accounting database.
+This option should typically only be used by
+.Xr rc 8 .
+.It Cm rm
+Remove stale sessions from the user accounting
 database, by referring to their
 .Ar identifier .
 Stale sessions can occur if a login service exits prematurely or fails
@@ -57,6 +83,13 @@ Identifiers can either be supplied in he
 .Xr getent 1 ,
 or as a string if the identifier allows such a representation.
 .Pp
+To remain backward compatible, this action can also be invoked directly
+by using the
+.Nm utxrm
+command.
+.El
+.Pp
+.Pp
 Because this utility requires write-access to the user accounting
 database, its use is limited to the super-user.
 .Sh SEE ALSO
@@ -66,7 +99,9 @@ database, its use is limited to the supe
 .Sh HISTORY
 The
 .Nm
-utility appeared in
-.Fx 9.0 .
+utility replaced
+.Nm utxrm
+in
+.Fx 10.0 .
 .Sh AUTHORS
 .An Ed Schouten Aq ed@FreeBSD.org

Copied and modified: head/usr.sbin/utx/utx.c (from r231514, head/usr.sbin/utxrm/utxrm.c)
==============================================================================
--- head/usr.sbin/utxrm/utxrm.c	Sat Feb 11 11:11:13 2012	(r231514, copy source)
+++ head/usr.sbin/utx/utx.c	Sat Feb 11 20:28:42 2012	(r231530)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
+ * Copyright (c) 2011-2012 Ed Schouten <ed@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <utmpx.h>
 
@@ -47,38 +48,67 @@ b16_pton(const char *in, char *out, size
 	return (0);
 }
 
-int
-main(int argc, char *argv[])
+static int
+rm(char *id[])
 {
 	struct utmpx utx = { .ut_type = DEAD_PROCESS };
 	size_t len;
-	int i, ret = 0;
-
-	if (argc < 2) {
-		fprintf(stderr, "usage: utxrm identifier ...\n");
-		return (1);
-	}
+	int ret = 0;
 
-	gettimeofday(&utx.ut_tv, NULL);
-	for (i = 1; i < argc; i++) {
-		len = strlen(argv[i]);
+	(void)gettimeofday(&utx.ut_tv, NULL);
+	for (; *id != NULL; id++) {
+		len = strlen(*id);
 		if (len <= sizeof(utx.ut_id)) {
 			/* Identifier as string. */
-			strncpy(utx.ut_id, argv[i], sizeof(utx.ut_id));
+			strncpy(utx.ut_id, *id, sizeof(utx.ut_id));
 		} else if (len != sizeof(utx.ut_id) * 2 ||
-		    b16_pton(argv[i], utx.ut_id, sizeof(utx.ut_id)) != 0) {
+		    b16_pton(*id, utx.ut_id, sizeof(utx.ut_id)) != 0) {
 			/* Also not hexadecimal. */
-			fprintf(stderr, "%s: Invalid identifier format\n",
-			    argv[i]);
+			fprintf(stderr, "%s: Invalid identifier format\n", *id);
 			ret = 1;
 			continue;
 		}
 
 		/* Zap the entry. */
 		if (pututxline(&utx) == NULL) {
-			perror(argv[i]);
+			perror(*id);
 			ret = 1;
 		}
 	}
 	return (ret);
 }
+
+static int
+boot(short type)
+{
+	struct utmpx utx = { .ut_type = type };
+
+	(void)gettimeofday(&utx.ut_tv, NULL);
+	if (pututxline(&utx) == NULL) {
+		perror("pututxline");
+		return (1);
+	}
+	return (0);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+	if (argc >= 2 && strcmp(getprogname(), "utxrm") == 0)
+		/* For compatibility. */
+		return (rm(&argv[1]));
+	else if (argc == 2 && strcmp(argv[1], "boot") == 0)
+		return (boot(BOOT_TIME));
+	else if (argc == 2 && strcmp(argv[1], "shutdown") == 0)
+		return (boot(SHUTDOWN_TIME));
+	else if (argc >= 3 && strcmp(argv[1], "rm") == 0)
+		return (rm(&argv[2]));
+
+	fprintf(stderr,
+	    "usage: utx boot\n"
+	    "       utx shutdown\n"
+	    "       utx rm identifier ...\n"
+	    "       utxrm identifier ...\n");
+	exit(1);
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202112028.q1BKSgY3046649>