Switch rand() part of id to a sequence
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@782 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
e4cc9f7562
commit
610672cb5f
@ -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)));
|
my $SALT_HOST = crypt(hostname, chr(65+rand(57)).chr(65+rand(57)));
|
||||||
$SALT_HOST =~ tr/A-Za-z0-9//cd;
|
$SALT_HOST =~ tr/A-Za-z0-9//cd;
|
||||||
|
|
||||||
|
my $SEQUENCE_ID = 1;
|
||||||
|
|
||||||
sub new { start(@_) }
|
sub new { start(@_) }
|
||||||
|
|
||||||
sub start {
|
sub start {
|
||||||
@ -22,14 +24,15 @@ sub start {
|
|||||||
|
|
||||||
# Generate unique id
|
# Generate unique id
|
||||||
# use gettimeofday for microsec precision
|
# use gettimeofday for microsec precision
|
||||||
# add in rand() in case gettimeofday clock is slow (e.g. bsd?)
|
# add in a sequence in case gettimeofday clock is slow (e.g. alpha)
|
||||||
# add in $$ in case srand is set per process
|
# add in $$ to provide uniqueness per process/child
|
||||||
my ($start, $mstart) = gettimeofday();
|
my ($start, $mstart) = gettimeofday();
|
||||||
|
my $seq = $SEQUENCE_ID++ % 10000;
|
||||||
my $id = sprintf("%d.%06d.%s.%d.%d",
|
my $id = sprintf("%d.%06d.%s.%d.%d",
|
||||||
$start,
|
$start,
|
||||||
$mstart,
|
$mstart,
|
||||||
$SALT_HOST,
|
$SALT_HOST,
|
||||||
rand(10000),
|
$seq,
|
||||||
$$,
|
$$,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user