Author: ed
Date: Thu Oct 27 17:05:18 2011
New Revision: 226846
URL: http://svn.freebsd.org/changeset/base/226846

Log:
  Make our utmpx more like System V.
  
  When booting the system, truncate the utx.active file, but do write the
  BOOT_TIME record into it afterwards. This allows one to obtain the boot
  time of the system as follows:
  
        struct utmpx u1 = { .ut_type = BOOT_TIME }, *u2;
  
        setutxent();
        u2 = getutxid(&u1);
  
  Now, the boot time is stored in u2->ut_tv, just like on Linux and other
  systems.
  
  We don't open the utx.active file with O_EXLOCK. It's rather unlikely
  that other applications use this database at the same time and I want to
  prevent the possibility of deadlocks in init(8).
  
  Discussed with:       pluknet

Modified:
  head/lib/libc/gen/getutxent.3
  head/lib/libc/gen/pututxline.c

Modified: head/lib/libc/gen/getutxent.3
==============================================================================
--- head/lib/libc/gen/getutxent.3       Thu Oct 27 16:48:19 2011        
(r226845)
+++ head/lib/libc/gen/getutxent.3       Thu Oct 27 17:05:18 2011        
(r226846)
@@ -301,7 +301,6 @@ The value of
 determines which databases are modified.
 .Pp
 Entries of type
-.Dv BOOT_TIME ,
 .Dv SHUTDOWN_TIME ,
 .Dv OLD_TIME
 and
@@ -335,7 +334,7 @@ In addition, entries of type
 .Dv BOOT_TIME
 and
 .Dv SHUTDOWN_TIME
-will cause all entries in
+will cause all existing entries in
 .Pa /var/run/utx.active
 to be discarded.
 .Pp

Modified: head/lib/libc/gen/pututxline.c
==============================================================================
--- head/lib/libc/gen/pututxline.c      Thu Oct 27 16:48:19 2011        
(r226845)
+++ head/lib/libc/gen/pututxline.c      Thu Oct 27 17:05:18 2011        
(r226846)
@@ -86,6 +86,9 @@ utx_active_add(const struct futx *fu)
                return (-1);
        while (fread(&fe, sizeof(fe), 1, fp) == 1) {
                switch (fe.fu_type) {
+               case BOOT_TIME:
+                       /* Leave these intact. */
+                       break;
                case USER_PROCESS:
                case INIT_PROCESS:
                case LOGIN_PROCESS:
@@ -171,6 +174,19 @@ utx_active_remove(struct futx *fu)
 }
 
 static void
+utx_active_init(const struct futx *fu)
+{
+       int fd;
+
+       /* Initialize utx.active with a single BOOT_TIME record. */
+       fd = _open(_PATH_UTX_ACTIVE, O_CREAT|O_RDWR|O_TRUNC, 0644);
+       if (fd < 0)
+               return;
+       _write(fd, fu, sizeof(*fu));
+       _close(fd);
+}
+
+static void
 utx_active_purge(void)
 {
 
@@ -277,9 +293,11 @@ pututxline(const struct utmpx *utmpx)
 
        switch (fu.fu_type) {
        case BOOT_TIME:
+               utx_active_init(&fu);
+               utx_lastlogin_upgrade();
+               break;
        case SHUTDOWN_TIME:
                utx_active_purge();
-               utx_lastlogin_upgrade();
                break;
        case OLD_TIME:
        case NEW_TIME:
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to