Subject: bin/27362: accounting file should be aligned
To: None <gnats-bugs@gnats.NetBSD.org>
From: Denis Lagno <dlagno@smtp.ru>
List: netbsd-bugs
Date: 10/21/2004 00:52:05
>Number:         27362
>Category:       bin
>Synopsis:       accounting file should be aligned
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 22 21:34:55 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Denis Lagno
>Release:        NetBSD 2.99.10
>Organization:
Brigada
>Environment:
System: NetBSD flam.gado 2.99.10 NetBSD 2.99.10 (FLAM) #0: Wed Oct 20 06:40:24 MSD 2004 dina@flam.gado:/volatile/worksrc/netbsd-current/src/sys/arch/i386/compile/FLAM i386
Architecture: i386
Machine: i386
>Description:
Recently I discovered that starting 5 days back, surviving several reboots,
lastcomm reports some insane records:

.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -       root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
?          -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -SCD    root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0?        -       root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
?          -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -SCD    root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
.0         -FC     root     ??       390.02 secs Thu Jan  1 03:05 (0:00:00.00)
==600000+ lines snipped==
ck         -F      root     ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
ck+        -F      46137344 ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
ck?        -F      12582912 ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
ck?        -F      12582912 ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
ck         -F      25165824 ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -F      16777216 ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -SCD    root     ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -SFC    root     ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     ??       368.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -SFCD   root     ??         0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
?          -       root     console    0.00 secs Thu Jan  1 03:00 (0:00:00.00)
ksh        -F      dina     ttytb      0.00 secs Sat Oct 16 09:17 (0:00:00.00)
date       -       dina     ttytb      0.00 secs Sat Oct 16 09:17 (0:00:00.02)
sed        -       dina     ttytb      0.00 secs Sat Oct 16 09:17 (0:00:00.02)
tty        -       dina     ttytb      0.00 secs Sat Oct 16 09:17 (0:00:00.02)
hostname   -       dina     ttytb      0.00 secs Sat Oct 16 09:17 (0:00:00.00)

investigation discovered that size of acct file was 27281992 -- not multiple
of 40 == sizeof( struct acct ) on my machine.
Apparently during some crash and subsequent fsck accounting file was truncated 
to sector boundary.
So it is desirable to align accounting file on startup.

>How-To-Repeat:
>Fix:
fix probably should go to etc/rc.d/accounting but it is pain to
discover sizeof(struct acct) in shell script.
fixing acct(2) is arguably too low level.
So I fixed accton(8):

--- usr.sbin/accton/accton.c.1.9	2003-08-07 15:25:11.000000000 +0400
+++ usr.sbin/accton/accton.c	2004-10-21 00:37:55.000000000 +0400
@@ -44,6 +44,8 @@
 #endif /* not lint */
 
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/acct.h>
 #include <err.h>
 #include <errno.h>
 #include <unistd.h>
@@ -76,6 +78,20 @@
                         err(1, "acct");
                 break;
         case 1:
+                /* first trying to align accounting file */
+                if (!acct(NULL)) {
+                        struct stat sb;
+                        int n;
+                        FILE *fs;
+                        if (!stat(*argv, &sb))
+                                if ((n = sb.st_size % sizeof(struct acct)))
+                                        if ((fs = fopen(*argv, "ab"))) {
+                                                for (n = sizeof(struct acct) - n; n--; )
+                                                        fputc(0, fs);
+                                                fclose(fs);
+                                        }
+                }
+                /* then calling low-level func */
                 if (acct(*argv))
                         err(1, "acct `%s'", *argv);
                 break;
>Release-Note:
>Audit-Trail:
>Unformatted:
 X-send-pr-version: 3.95