NetBSD Problem Report #27315
From dina@flam.gado Thu Oct 21 21:21:47 2004
Return-Path: <dina@flam.gado>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.netbsd.org (Postfix) with SMTP id 16DF4251ECF
for <gnats@www.netbsd.org>; Thu, 21 Oct 2004 21:21:47 +0000 (UTC)
Message-Id: <20041021210158.868515BD4@flam.gado>
Date: Fri, 22 Oct 2004 01:01:58 +0400 (MSD)
From: dlagno@smtp.ru
Reply-To: dlagno@smtp.ru
To: gnats-bugs@gnats.NetBSD.org
Cc: dlagno@smtp.ru
Subject: acct file should be aligned
X-Send-Pr-Version: 3.95
>Number: 27315
>Category: bin
>Synopsis: acct file should be explicitly aligned
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: analyzed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Oct 22 08:47:02 +0000 2004
>Closed-Date:
>Last-Modified: Mon Dec 11 02:00:34 +0000 2023
>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:
From: christos@zoulas.com (Christos Zoulas)
To: dlagno@smtp.ru, gnats-bugs@gnats.NetBSD.org
Cc:
Subject: Re: bin/27315: acct file should be aligned
Date: Fri, 22 Oct 2004 08:31:34 -0400
On Oct 22, 1:01am, dlagno@smtp.ru (dlagno@smtp.ru) wrote:
-- Subject: bin/27315: acct file should be aligned
| Recently I discovered that starting 5 days back, surviving several reboots,
| lastcomm reports some insane records:
Good catch! Can you please submit a patch that uses:
fd = open();
lseek(fd, right loc - 1, SEEK_SET);
write(fd, "", 1);
close(fd);
Thanks,
christos
From: "Denis Lagno" <dlagno@smtp.ru>
To: gnats-bugs@gnats.NetBSD.org
Cc: christos@zoulas.com (Christos Zoulas)
Subject: Re: bin/27315: acct file should be aligned
Date: Sat, 23 Oct 2004 02:36:32 +0400
> Can you please submit a patch that uses:
>
> fd = open();
> lseek(fd, right loc - 1, SEEK_SET);
> write(fd, "", 1);
> close(fd);
Here is new version of the patch:
--- usr.sbin/accton/accton.c.1.9 2004-10-23 02:03:37.000000000 +0400
+++ usr.sbin/accton/accton.c 2004-10-23 02:27:02.000000000 +0400
@@ -44,9 +44,11 @@
#endif /* not lint */
#include <sys/types.h>
+#include <sys/acct.h>
#include <err.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -59,7 +61,8 @@
int argc;
char *argv[];
{
- int ch;
+ int ch, fd;
+ off_t n;
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
@@ -76,6 +79,16 @@
err(1, "acct");
break;
case 1:
+ /* first trying to align accounting file */
+ fd = -1;
+ if (!acct(NULL)
+ && (fd = open(*argv, O_WRONLY, 0)) >= 0
+ && (n = lseek(fd, 0, SEEK_END)) >= 0
+ && (n % sizeof(struct acct))
+ && (lseek(fd, (n / sizeof(struct acct) + 1) * sizeof(struct acct) - 1, SEEK_SET) >= 0))
+ write(fd, "", 1);
+ close(fd);
+ /* then calling low-level machinery */
if (acct(*argv))
err(1, "acct `%s'", *argv);
break;
From: enami tsugutomo <enami@but-b.or.jp>
To: christos@zoulas.com (Christos Zoulas)
Cc: dlagno@smtp.ru, gnats-bugs@gnats.NetBSD.org
Subject: Re: bin/27315: acct file should be aligned
Date: Wed, 27 Oct 2004 07:43:36 +0900 (JST)
> Good catch! Can you please submit a patch that uses:
>
>
> fd = open();
> lseek(fd, right loc - 1, SEEK_SET);
> write(fd, "", 1);
> close(fd);
Why not just call truncate()?
enami.
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@gnats.netbsd.org, dlagno@smtp.ru, reed@www.netbsd.org,
gnats-admin@netbsd.org
Cc: enami@netbsd.org
Subject: Re: bin/27315
Date: Tue, 26 Oct 2004 19:59:27 -0400
Well, I think that calling truncate might lose useful data. Now that I think
about it more, acct(2) should not append to such a file, but return an error
such as EFTYPE, or fix it in the kernel like in the appended patch (so that
each userland application that calls acct(2) does not have to worry about it).
Comments?
christos
Index: kern_acct.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_acct.c,v
retrieving revision 1.58
diff -u -r1.58 kern_acct.c
--- kern_acct.c 17 Sep 2004 14:11:25 -0000 1.58
+++ kern_acct.c 26 Oct 2004 23:52:18 -0000
@@ -239,6 +239,9 @@
* writing and make sure it's a 'normal'.
*/
if (SCARG(uap, path) != NULL) {
+ struct vattr va;
+ size_t pad;
+
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path),
p);
if ((error = vn_open(&nd, FWRITE|O_APPEND, 0)) != 0)
@@ -248,6 +251,28 @@
vn_close(nd.ni_vp, FWRITE, p->p_ucred, p);
return (EACCES);
}
+ if ((error = VOP_GETATTR(nd.ni_vp, &va, p->p_ucred, p)) != 0) {
+ vn_close(nd.ni_vp, FWRITE, p->p_ucred, p);
+ return (error);
+ }
+ if ((pad = (va.va_size % sizeof(struct acct))) != 0) {
+ struct acct acct;
+#ifdef DIAGNOSTIC
+ printf("size of accounting file not a multiple of "
+ "%lu - padded\n",
+ (unsigned long)sizeof(struct acct));
+#endif
+ pad = sizeof(struct acct) - pad;
+ (void)memset(&acct, 0, pad);
+ VOP_LEASE(nd.ni_vp, p, p->p_ucred, LEASE_WRITE);
+ error = vn_rdwr(UIO_WRITE, nd.ni_vp, &acct, pad,
+ (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT,
+ p->p_ucred, NULL, NULL);
+ if (error != 0) {
+ vn_close(nd.ni_vp, FWRITE, p->p_ucred, p);
+ return (error);
+ }
+ }
}
ACCT_LOCK();
From: enami tsugutomo <enami@sm.sony.co.jp>
To: christos@zoulas.com (Christos Zoulas)
Cc: gnats-bugs@gnats.netbsd.org, dlagno@smtp.ru, reed@www.netbsd.org,
gnats-admin@netbsd.org
Subject: Re: bin/27315
Date: 27 Oct 2004 09:36:33 +0900
christos@zoulas.com (Christos Zoulas) writes:
> Well, I think that calling truncate might lose useful data.
How do you lose useful data by calling truncate()? Race condition?
enami.
State-Changed-From-To: open->analyzed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 11 Dec 2023 02:00:34 +0000
State-Changed-Why:
problem analyzed, candidate patches supplied
>Unformatted:
>Quarter:
>Keywords:
>Date-Required:
(Contact us)
$NetBSD: gnats-precook-prs,v 1.4 2018/12/21 14:20:20 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.