SUMMARY: Bug in find command - tru64 v5.1a???

From: Parkin Frank - fparki <fparki_at_acxiom.co.uk>
Date: Thu, 07 Aug 2003 13:21:21 +0100

Thanks go to Nikola Milutinovic and Joerg Bruehe.

Special thanks to Tim Cutts with this excellent response...

If you've created the file before, and it already exists, then creat()
truncates it rather than creating a new file. This means that the
atime() does not change. Consider the following program:

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>

int main(void) {
  int fd;

  struct stat s;

  fd = open("testfile", O_CREAT | O_WRONLY | O_TRUNC, 0644);
  if (fd == -1) {
    perror("Could not create file");
    return 1;
  }

  if (fstat(fd, &s) != 0) {
    perror("Could not fstat descriptor");
    return 1;
  }

  if (write(fd, "some data\n", sizeof("some data\n")) == -1) {
    perror("Could not write to file");
    return 1;
  }
  
  printf("atime: %d\nctime: %d\nmtime: %d\n\n",
     s.st_atime,
     s.st_ctime,
     s.st_mtime);

  close(fd);

  return 0;
}


This program creates a file, writes some data to it, and then reports
the atime ctime and mtime values.

The first time it's run, it produced the following output:

ecs2f:/nfs/acari/tjrc$ ./t
atime: 1060257520
ctime: 1060257520
mtime: 1060257520

all three the same. Fine.

Now, if I run the program again a few seconds later:

ecs2f:/nfs/acari/tjrc$ ./t
atime: 1060257520
ctime: 1060257573
mtime: 1060257573

Aha! The ctime and mtime have changed, but atime has not!

So, if this file you have is being created with creat() or with an
open() O_TRUNC flag as above, the file is not actually created anew, and
the atime on the inode does not change.

You need to actually unlink() the file between invocations of the
program for the atime to be updated.



                 -----Original Message-----
                From: Parkin Frank - fparki
                Sent: 07 August 2003 12:28
                To: 'tru64-unix-managers_at_ornl.gov'
                Subject: Bug in find command - tru64 v5.1a???

                We use a find command in an automated process to delete
files.

                find . -atime +7 -exec rm -ef {} ;\

                The command has worked perfectly for several months.
However, last night it deleted 6 files that were in the process of being
written.

                Is this correct behaviour?


                Thanks
                Frank

                





**********************************************************************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.
Received on Thu Aug 07 2003 - 12:18:34 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:44 NZDT