Subject: Re: bin/27315: acct file should be aligned
To: Christos Zoulas <christos@zoulas.com>
From: Denis Lagno <dlagno@smtp.ru>
List: netbsd-bugs
Date: 10/26/2004 19:22:12
> 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;
--
Denis Lagno,
PGP key fingerprint: F94F F38F 1895 E673 4374 9D63 2B9E FAB3 8E83 584C