More changes to the id generator

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@778 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2007-08-29 21:50:53 +00:00
parent bf5d011d85
commit e6113d586d

View File

@ -5,10 +5,14 @@ use strict;
use Qpsmtpd::Utils;
use Qpsmtpd::Constants;
use Socket qw(inet_aton);
use Sys::Hostname;
use Time::HiRes qw(gettimeofday);
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;
sub new { start(@_) }
sub start {
@ -16,12 +20,18 @@ sub start {
my $class = ref($proto) || $proto;
my %args = @_;
# generate id
# Generate unique id
# use gettimeofday for microsec precision
my ($start, $mstart) = gettimeofday();
# add in rand() in case gettimeofday clock is slow (e.g. bsd?)
# add in $$ in case srand is set per process
my $id = sprintf("%d.%06d.%d.%d", $start, $mstart, rand(10000), $$);
my ($start, $mstart) = gettimeofday();
my $id = sprintf("%d.%06d.%s.%d.%d",
$start,
$mstart,
$SALT_HOST,
rand(10000),
$$,
);
my $self = { _rcpt => [], started => $start, _id => $id };
bless ($self, $class);