From owner-svn-src-head@FreeBSD.ORG Sat Dec 5 20:26:56 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA63110656AE; Sat, 5 Dec 2009 20:26:55 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C930F8FC18; Sat, 5 Dec 2009 20:26:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nB5KQtUX099121; Sat, 5 Dec 2009 20:26:55 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB5KQtH6099116; Sat, 5 Dec 2009 20:26:55 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912052026.nB5KQtH6099116@svn.freebsd.org> From: Ed Schouten Date: Sat, 5 Dec 2009 20:26:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200161 - in head/sbin: init reboot X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Dec 2009 20:26:56 -0000 Author: ed Date: Sat Dec 5 20:26:55 2009 New Revision: 200161 URL: http://svn.freebsd.org/changeset/base/200161 Log: Let init(8) and reboot(8) use utmpx to log wtmp entries. logwtmp() gets called with the raw strings that are written to disk. For regular user entries, this isn't too bad, but when booting/shutting down, the contents get rather cryptic. Just call the standardized pututxline(). Modified: head/sbin/init/Makefile head/sbin/init/init.c head/sbin/reboot/Makefile head/sbin/reboot/reboot.c Modified: head/sbin/init/Makefile ============================================================================== --- head/sbin/init/Makefile Sat Dec 5 20:22:26 2009 (r200160) +++ head/sbin/init/Makefile Sat Dec 5 20:26:55 2009 (r200161) @@ -6,8 +6,8 @@ MAN= init.8 PRECIOUSPROG= INSTALLFLAGS=-b -B.bak CFLAGS+=-DDEBUGSHELL -DSECURE -DLOGIN_CAP -DCOMPAT_SYSV_INIT -DPADD= ${LIBUTIL} ${LIBCRYPT} -LDADD= -lutil -lcrypt +DPADD= ${LIBUTIL} ${LIBULOG} ${LIBCRYPT} +LDADD= -lutil -lulog -lcrypt NO_SHARED?= YES Modified: head/sbin/init/init.c ============================================================================== --- head/sbin/init/init.c Sat Dec 5 20:22:26 2009 (r200160) +++ head/sbin/init/init.c Sat Dec 5 20:26:55 2009 (r200161) @@ -65,6 +65,8 @@ static const char rcsid[] = #include #include #include +#define _ULOG_POSIX_NAMES +#include #include #include #include @@ -569,10 +571,8 @@ transition(state_t s) static void clear_session_logs(session_t *sp) { - char *line = sp->se_device + sizeof(_PATH_DEV) - 1; - if (logout(line)) - logwtmp(line, "", ""); + ulog_logout(sp->se_device); } /* @@ -775,6 +775,7 @@ single_user(void) static state_func_t runcom(void) { + struct utmpx utx; state_func_t next_transition; if ((next_transition = run_script(_PATH_RUNCOM)) != 0) @@ -782,7 +783,9 @@ runcom(void) runcom_mode = AUTOBOOT; /* the default */ /* NB: should send a message to the session logger to avoid blocking. */ - logwtmp("~", "reboot", ""); + utx.ut_type = BOOT_TIME; + gettimeofday(&utx.ut_tv, NULL); + pututxline(&utx); return (state_func_t) read_ttys; } @@ -1487,13 +1490,16 @@ alrm_handler(int sig) static state_func_t death(void) { + struct utmpx utx; session_t *sp; int i; pid_t pid; static const int death_sigs[2] = { SIGTERM, SIGKILL }; /* NB: should send a message to the session logger to avoid blocking. */ - logwtmp("~", "shutdown", ""); + utx.ut_type = SHUTDOWN_TIME; + gettimeofday(&utx.ut_tv, NULL); + pututxline(&utx); /* * Also revoke the TTY here. Because runshutdown() may reopen Modified: head/sbin/reboot/Makefile ============================================================================== --- head/sbin/reboot/Makefile Sat Dec 5 20:22:26 2009 (r200160) +++ head/sbin/reboot/Makefile Sat Dec 5 20:26:55 2009 (r200161) @@ -2,8 +2,8 @@ # $FreeBSD$ PROG= reboot -DPADD= ${LIBUTIL} -LDADD= -lutil +DPADD= ${LIBULOG} +LDADD= -lulog MAN= reboot.8 nextboot.8 MLINKS= reboot.8 halt.8 reboot.8 fastboot.8 reboot.8 fasthalt.8 Modified: head/sbin/reboot/reboot.c ============================================================================== --- head/sbin/reboot/reboot.c Sat Dec 5 20:22:26 2009 (r200160) +++ head/sbin/reboot/reboot.c Sat Dec 5 20:26:55 2009 (r200161) @@ -42,18 +42,20 @@ static char sccsid[] = "@(#)reboot.c 8.1 __FBSDID("$FreeBSD$"); #include +#include #include #include #include #include #include #include -#include #include #include #include #include #include +#define _ULOG_POSIX_NAMES +#include #include static void usage(void); @@ -64,6 +66,7 @@ int dohalt; int main(int argc, char *argv[]) { + struct utmpx utx; const struct passwd *pw; int ch, howto, i, fd, lflag, nflag, qflag, sverrno; u_int pageins; @@ -140,7 +143,9 @@ main(int argc, char *argv[]) syslog(LOG_CRIT, "rebooted by %s", user); } } - logwtmp("~", "shutdown", ""); + utx.ut_type = SHUTDOWN_TIME; + gettimeofday(&utx.ut_tv, NULL); + pututxline(&utx); /* * Do a sync early on, so disks start transfers while we're off