file access time updateing and utime[s]()..

Matti E Aarnio (mea@mea.cc.utu.fi)
Wed, 20 Mar 1996 15:57:27 +0200


Hello,

I am a mailer hacker, and to my attention became drawn to
odd phenomena at Linux systems not being able to preserve
file access dates of the mailboxes.

When the file (mailbox) is appeneded a new message, it is
done with at first reading the last two chars of file to
see if they are both newlines (if they are, my mailbox
writer need not add a newline or two..)

The question is, if the only read access is one before utime(s)
call, what makes it to reset the read (atime) access time
variable into its current value at the subsequent writes ?

(Linux 1.3.75, ... libc 5.3.2)

I could (perhaps) move the ``restore_accesstimes'' routine
into after the last fclose() at the file, but why this same
code works as intended at Sun Solaris ?

/Matti Aarnio <mea@nic.funet.fi> <mea@utu.fi>

The program works like this:

.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
fp = fopen("mailboxpath", O_RDWR, ..) /* we handle existing file
appending example, and
not care about creation.. */
/* ... acquire locking at the fd/file */
fstat(fileno(fp),&statbuf);
fseek(fp, -2, SEEK_END); /* Two bytes down from end of file)
read(fp,testbuf,2);

if (restore_accesstimes) {
tv.actime = statbuf.st_atime; /* taken from the fstat() result */
tv.modtime = statbuf.st_mtime; /* high above.. */
rc = utime(filename, &tv);
}

fseek(fp, 0, SEEK_END);
if (testbuf != "\n\n") .. /* do we need to open more newlines
after the previous msg ? */
putmail(fd, ...); /* Put the email in.. */
/* uses only write/put operations */

fflush(fp);
/* .. un-acquire locking at the fd/file ... */
fclose(fp);
.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.