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

From: Parkin Frank - fparki (fparki@acxiom.co.uk)
Date: Thu Aug 07 2003 - 08:21:21 EDT


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@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.



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:49:30 EDT