From 610672cb5f404673611bc42e090fb7f6e6109f28 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Thu, 30 Aug 2007 20:50:39 +0000 Subject: [PATCH] Switch rand() part of id to a sequence git-svn-id: https://svn.perl.org/qpsmtpd/trunk@782 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/Transaction.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Qpsmtpd/Transaction.pm b/lib/Qpsmtpd/Transaction.pm index 27b2318..c91e0d3 100644 --- a/lib/Qpsmtpd/Transaction.pm +++ b/lib/Qpsmtpd/Transaction.pm @@ -13,6 +13,8 @@ use IO::File qw(O_RDWR O_CREAT); my $SALT_HOST = crypt(hostname, chr(65+rand(57)).chr(65+rand(57))); $SALT_HOST =~ tr/A-Za-z0-9//cd; +my $SEQUENCE_ID = 1; + sub new { start(@_) } sub start { @@ -22,14 +24,15 @@ sub start { # Generate unique id # use gettimeofday for microsec precision - # add in rand() in case gettimeofday clock is slow (e.g. bsd?) - # add in $$ in case srand is set per process + # add in a sequence in case gettimeofday clock is slow (e.g. alpha) + # add in $$ to provide uniqueness per process/child my ($start, $mstart) = gettimeofday(); + my $seq = $SEQUENCE_ID++ % 10000; my $id = sprintf("%d.%06d.%s.%d.%d", $start, $mstart, $SALT_HOST, - rand(10000), + $seq, $$, );