Mercurial > dovecot > core-2.2
changeset 20115:939cd2e189f3
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.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 28 Apr 2016 22:33:14 +0300 |
parents | 3c623555bcaa |
children | bc2237152abd |
files | src/lib/guid.c |
diffstat | 1 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/guid.c Fri Apr 29 21:57:36 2016 +0300 +++ b/src/lib/guid.c Thu Apr 28 22:33:14 2016 +0300 @@ -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 @@ 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++;