From: Theodore Tso Date: Wed, 27 Feb 1991 14:27:56 +0000 (+0000) Subject: Added a hack so that krb5_us_timeofday() will always return a monotonically X-Git-Tag: krb5-1.0-alpha4~161 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=37038d197a95a27f9dd7dd2cadcd272e129041cb;p=krb5.git Added a hack so that krb5_us_timeofday() will always return a monotonically increasing time, bumping the microsecond time if necessary. This is needed on OS's like ultrix which only have a 10 us granularity in their clock, and don't guarantee in the kernel that two calls to gettimeofday will return different values. This guarantees it in user space, which isn't quite good enough (two different processes communicating over the loopback interface could get confused), but it's better than nothing. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1811 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ustime.c b/src/lib/krb5/os/ustime.c index 974e942cc..65146492f 100644 --- a/src/lib/krb5/os/ustime.c +++ b/src/lib/krb5/os/ustime.c @@ -24,6 +24,8 @@ static char rcsid_mstime_c[] = extern int errno; +static struct timeval last_tv = {0, 0}; + krb5_error_code krb5_us_timeofday(seconds, microseconds) register krb5_int32 *seconds, *microseconds; @@ -34,6 +36,11 @@ register krb5_int32 *seconds, *microseconds; /* failed, return errno */ return (krb5_error_code) errno; } + if ((tv.tv_sec == last_tv.tv_sec) && (tv.tv_usec == last_tv.tv_usec)) + tv.tv_usec = ++last_tv.tv_usec; + else + last_tv = tv; + *seconds = tv.tv_sec; *microseconds = tv.tv_usec; return 0;