From: Timo Sirainen Date: Thu, 28 Apr 2016 19:33:14 +0000 (+0300) Subject: lib: Set timestamp part more accurately in guid_128_generate() X-Git-Tag: 2.3.0.rc1~3896 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1684fd2affe6159e99bc6de0fd387ce802f0ca6;p=thirdparty%2Fdovecot%2Fcore.git lib: Set timestamp part more accurately in guid_128_generate() Previously a long-running process would keep the timestamp close to its original start time. This doesn't really matter as long as GUIDs are treated opaque, but some pieces of code prefer to try to use the timestamp fields since they're already there. This makes such code work more nicely. --- diff --git a/src/lib/guid.c b/src/lib/guid.c index 902c79658c..b0524dbb51 100644 --- a/src/lib/guid.c +++ b/src/lib/guid.c @@ -1,6 +1,7 @@ /* Copyright (c) 2011-2016 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "ioloop.h" #include "buffer.h" #include "sha1.h" #include "hash.h" @@ -65,7 +66,15 @@ void guid_128_generate(guid_128_t guid_r) guid_static[2] = (pid & 0x00ff0000) >> 16; guid_static[3] = (pid & 0xff000000) >> 24; guid_128_host_hash_get(my_hostdomain(), guid_static+4); - } else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) { + } else if (ioloop_timeval.tv_sec > ts.tv_sec || + (ioloop_timeval.tv_sec == ts.tv_sec && + ioloop_timeval.tv_usec > ts.tv_nsec*1000)) { + /* use ioloop's time since we have it. it doesn't provide any + more uniqueness, but it allows finding out more reliably + when a GUID was created. */ + ts.tv_sec = ioloop_timeval.tv_sec; + ts.tv_nsec = ioloop_timeval.tv_usec*1000; + } else if ((uint32_t)ts.tv_nsec < 1000000000) { ts.tv_nsec++; } else { ts.tv_sec++;