Added a hack so that krb5_us_timeofday() will always return a monotonically
authorTheodore Tso <tytso@mit.edu>
Wed, 27 Feb 1991 14:27:56 +0000 (14:27 +0000)
committerTheodore Tso <tytso@mit.edu>
Wed, 27 Feb 1991 14:27:56 +0000 (14:27 +0000)
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

src/lib/krb5/os/ustime.c

index 974e942cc0f603dbe96485181ae0c098ca6f0ce2..65146492f89bc7febcab63cb46278a6b74044f9f 100644 (file)
@@ -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;