procmail
[Top] [All Lists]

Re: how to deliver to a file with a unique time-stamped file name, reliably?

2005-01-19 04:15:51
On Wed, 19 Jan 2005, 00:44 GMT-08 Gary Funck wrote:

[Robert Allerstorfer:]
in my SoftlabsAV package, I am creating an unique ID number for each
mail, including the mail's processing date and time with an accurancy
of at least to the second. That ID will be in the format
"YYYYMMDD-hhmmss.xxxxxx" where the x's are either 6-digits
microseconds (if supported by the OS), or 5-digits Process-ID

The use of microseconds will not guarantee uniqueness, if the script
is run on a multi-cpu system, and the script does not otherwise
serialize the part that creates the file name.

This would mean that using microseconds is bullet-proof on single-CPU
systems. This is sufficient for me. However, not all "date"
implementations support the %N format - that's why I check the result
and use the PID instead in such a case.

The use of a pid
is more bullet proof becuase it is unlikely (based upon the way
most Un*x implementations assign pids that the process creating
file N, exits and a new process creates file N+1, and both processes
would happen to be assigned the same pid, all within the same second.
Still, it is theoretically possible, so neither approach is
iron clad. Probably using both microseconds and the pid is nearly
certain not cause a name clash (again, as long as the operator doesn't
set the time back, which has been known to happen).

I am assuming the procmail recipe will run on a properly configured
system. Setting the system time back, deleting the date program or
other strange scenarios resulting in unpredictable results are simply
"not supported". Relying on 'date', one could save the created ID into
a certain file and always read its content before creating a new ID,
checking if both IDs does not match. This should give nearly 100%
uniqueness. But no method will give real 100%, I think. Also not
really necessary, IMO.

rob.


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>