Merged changed from Mac_V2_0_derivatives branch
authorMiro Jurisic <meeroh@mit.edu>
Wed, 9 Jun 1999 14:52:29 +0000 (14:52 +0000)
committerMiro Jurisic <meeroh@mit.edu>
Wed, 9 Jun 1999 14:52:29 +0000 (14:52 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11499 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/ChangeLog
src/lib/krb5/os/c_ustime.c
src/lib/krb5/os/init_os_ctx.c
src/lib/krb5/os/net_write.c
src/util/profile/ChangeLog
src/util/profile/prof_file.c

index d230bc6351603cbe3d4e3e432e083b1943764d4c..1771da98ff1d4bfaef473a32078d73c4961e172d 100644 (file)
@@ -1,3 +1,31 @@
+1999-06-09  Miro Jurisic  <meeroh@mit.edu>
+
+       * c_ustime.c (AbsoluteToSecsNanosecs): Fixed the UInt64 division
+       * c_ustime.c (krb5_crypto_us_timeofday): now returning the correct value
+
+1999-06-09  Miro Jurisic  <meeroh@mit.edu>
+
+       * c_ustime.c (AbsoluteToSecsNanosecs): Fixed the UInt64 comparison
+
+1999-06-09  Miro Jurisic  <meeroh@mit.edu>
+
+       * net_read.c, net_write.c: now setting errno on Mac too
+       
+1999-06-09  Miro Jurisic  <meeroh@mit.edu>
+
+       * c_ustime.c (krb5_crypto_us_timeofday, HaveAccurateTime,
+               AbsoluteToSecsNanosecs): Added support for microseconds or
+               better timers on the Mac when available
+
+       * c_ustime.c (krb5_crypto_us_timeofday): fixed usecs counting bug
+               (From Chas Williams)
+
+       * init_os_ctx.c (GetMacProfilePathname): removed hardcoded config file name
+               (From Chas Williams)
+       
+       * init_os_ctx.c (os_init_paths): added NRL config file name
+               (From Chas Williams)
+
 Tue Jun  8 15:26:21 1999  Alexandra Ellwood  <lxs@mit.edu>
 
        * changepw.c: Changed errno to SOCKET_ERRNO/SOCKET_SET_ERRNO
index e790acc956af139a6f5b4b998161f86e8828b17f..85197f1d26707715717d4106e49240eef6559ea4 100644 (file)
@@ -23,7 +23,7 @@
  *
  * krb5_mstimeofday for BSD 4.3
  */
-
 #define        NEED_SOCKETS
 #include "k5-int.h"
 
  * Macintosh ooperating system interface for Kerberos.
  */
 
-#include "AddressXlation.h"    /* for ip_addr, for #if 0'd net-time stuff  */
-
 #include <script.h>            /* Defines MachineLocation, used by getTimeZoneOffset */
 #include <ToolUtils.h>         /* Defines BitTst(), called by getTimeZoneOffset() */
 #include <OSUtils.h>           /* Defines GetDateTime */
+#include <DriverServices.h> /* Nanosecond timing */
+#include <CodeFragments.h>     /* Check for presence of UpTime */
+#include <Math64.h>                    /* 64-bit integer math */
 
 /* Mac Cincludes */
 #include <string.h>
 
 static krb5_int32 last_sec = 0, last_usec = 0;
 
+/* Check for availability of microseconds or better timer */
+Boolean HaveAccurateTime ();
+
+/* Convert nanoseconds to date and time */
+void AbsoluteToSecsNanosecs (
+      AbsoluteTime             eventTime,              /* Value to convert   */
+      UInt32                   *eventSeconds,         /* Result goes here   */
+      UInt32                   *residualNanoseconds    /* Fractional second  */
+   );
+
 /*
  * The Unix epoch is 1/1/70, the Mac epoch is 1/1/04.
  *
@@ -98,29 +109,119 @@ krb5_crypto_us_timeofday(seconds, microseconds)
     sec = the_time - 
        ((66 * 365 * 24 * 60 * 60) + (17 *  24 * 60 * 60) + 
        (getTimeZoneOffset() * 60 * 60));
-
-    usec = 0;  /* Mac is too slow to count faster than once a second */
-
-    if ((sec == last_sec) && (usec == last_usec)) {
-           if (++last_usec >= 1000000) {
-                   last_usec = 0;
-                   last_sec++;
+       
+    if (HaveAccurateTime ()) {                                 /* Does hardware support accurate time? */
+    
+       AbsoluteTime    absoluteTime;
+       UInt32                  nanoseconds;
+       
+       absoluteTime = UpTime ();
+       AbsoluteToSecsNanosecs (absoluteTime, seconds, &nanoseconds);
+       
+       usec = nanoseconds / 1000;
+
+    } else {
+           usec = 0;
+
+           if (sec == last_sec) {                              /* Same as last time? */
+               usec = ++last_usec;                             /* Yep, so do microseconds */
+                   if (++last_usec >= 1000000) {
+                       ++sec;
+                           usec = 0;
+                   }
            }
-           sec = last_sec;
-           usec = last_usec;
-    }
-    else {
-           last_sec = sec;
+           last_sec = sec;                                             /* Remember for next time */
            last_usec = usec;
        }
 
     *seconds = sec;
-    *microseconds = usec;
+    *microseconds = usec;                                      /* Return the values */
 
     return 0;
 }
 
+/* Check if we have microsecond or better timer */
 
+Boolean HaveAccurateTime ()
+{
+       static  Boolean alreadyChecked = false;
+       static  haveAccurateTime = false;
+       
+       if (!alreadyChecked) {
+               alreadyChecked = true;
+               haveAccurateTime = false;
+               if ((Ptr) UpTime != (Ptr) kUnresolvedCFragSymbolAddress) {
+                       UInt32  minAbsoluteTimeDelta;
+                       UInt32  theAbsoluteTimeToNanosecondNumerator;
+                       UInt32  theAbsoluteTimeToNanosecondDenominator;
+                       UInt32  theProcessorToAbsoluteTimeNumerator;
+                       UInt32  theProcessorToAbsoluteTimeDenominator;
+
+                       GetTimeBaseInfo (
+                               &minAbsoluteTimeDelta,
+                               &theAbsoluteTimeToNanosecondNumerator,
+                               &theAbsoluteTimeToNanosecondDenominator,
+                               &theProcessorToAbsoluteTimeNumerator,
+                               &theProcessorToAbsoluteTimeDenominator);
+                               
+                       /* minAbsoluteTimeDelta is the period in which Uptime is updated, in absolute time */
+                       /* We convert it to nanoseconds and compare it with .5 microsecond */
+                       
+                       if (minAbsoluteTimeDelta * theAbsoluteTimeToNanosecondNumerator <
+                               500 * theAbsoluteTimeToNanosecondDenominator) {
+                               haveAccurateTime = true;
+                       }
+               }
+       }
+       
+       return haveAccurateTime;
+}
+
+/* Convert nanoseconds to date and time */
+
+void AbsoluteToSecsNanosecs (
+      AbsoluteTime             eventTime,              /* Value to convert   */
+      UInt32                   *eventSeconds,         /* Result goes here   */
+      UInt32                   *residualNanoseconds    /* Fractional second  */
+   )
+{
+   UInt64                                      eventNanoseconds;
+   UInt64                                      eventSeconds64;
+   static const UInt64         kTenE9 = U64SetU (1000000000);
+   static UInt64                       gNanosecondsAtStart = U64SetU (0);
+
+   /*
+    * If this is the first call, compute the offset between
+    * GetDateTime and UpTime.
+    */
+   if (U64Compare (gNanosecondsAtStart, U64SetU (0)) == 0) {
+      UInt32                           secondsAtStart;
+      AbsoluteTime                     absoluteTimeAtStart;
+      UInt64                           upTimeAtStart;
+         UInt64                                nanosecondsAtStart;
+
+      GetDateTime (&secondsAtStart);
+      upTimeAtStart = UnsignedWideToUInt64 (AbsoluteToNanoseconds (UpTime()));
+         nanosecondsAtStart = U64SetU (secondsAtStart);
+      nanosecondsAtStart = U64Multiply (nanosecondsAtStart, kTenE9);
+      gNanosecondsAtStart = U64Subtract (nanosecondsAtStart, upTimeAtStart);
+   }
+   /*
+    * Convert the event time (UpTime value) to nanoseconds and add
+    * the local time epoch.
+    */
+   eventNanoseconds = UnsignedWideToUInt64 (AbsoluteToNanoseconds (eventTime));
+   eventNanoseconds = U64Add (gNanosecondsAtStart, eventNanoseconds);
+   /*
+    * eventSeconds = eventNanoseconds /= 10e9;
+    * residualNanoseconds = eventNanoseconds % 10e9;
+    * Finally, compute the local time (seconds) and fraction.
+    */
+   eventSeconds64 = U64Div (eventNanoseconds, kTenE9);
+   eventNanoseconds = U64Subtract (eventNanoseconds, U64Multiply (eventSeconds64, kTenE9));
+   *eventSeconds = (UInt64ToUnsignedWide (eventSeconds64)).lo;
+   *residualNanoseconds = (UInt64ToUnsignedWide (eventNanoseconds)).lo;
+}
 #elif defined(_WIN32)
 
    /* Microsoft Windows NT and 95   (32bit)  */
index ab325cb266c4ae6285f98ac971889304602f78ff..7c031543e0d4b553e31bf251156ce7be45505e53 100644 (file)
@@ -80,7 +80,7 @@ OSErr         err;
 }
 
 char*
-GetMacProfilePathName(void)
+GetMacProfilePathName(Str255 filename)
 {
 short  vRefnum;
 long   parID;
@@ -89,7 +89,7 @@ FSSpec        krbSpec;
 char   pathbuf[255];
 
        theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefnum, &parID);
-       FSMakeFSSpec(vRefnum, parID, "\pkrb5.ini", &krbSpec);
+       FSMakeFSSpec(vRefnum, parID, filename, &krbSpec);
        GetPathname(&krbSpec, &pathbuf);
        return strdup(pathbuf);
 }
@@ -106,7 +106,9 @@ os_init_paths(ctx, secure)
        krb5_error_code retval = 0;
        char *name = 0;
 
-#if defined(macintosh) || defined(_MSDOS) || defined(_WIN32)
+#if defined(macintosh)
+       const char *filenames[3];
+#elif defined(_MSDOS) || defined(_WIN32)
        const char *filenames[2];
 #endif
 
@@ -132,7 +134,8 @@ os_init_paths(ctx, secure)
 
 #else /* _MSDOS || _WIN32 */
 #ifdef macintosh
-       filenames[0] = GetMacProfilePathName();
+       filenames[0] = GetMacProfilePathName("\pkrb Configuration");
+       filenames[0] = GetMacProfilePathName("\pkrb5.ini");
        filenames[1] = 0;
        retval = profile_init(filenames, &ctx->profile);
 #else
index e959d68c9ec7adda02af4c6507096d8df407b7b0..1da730e1e32ba048e8624ef9d451bfe4456ce3b6 100644 (file)
@@ -49,8 +49,10 @@ krb5_net_write(context, fd, buf, len)
        if (cc < 0) {
            if (SOCKET_ERRNO == SOCKET_EINTR)
                continue;
+
                /* XXX this interface sucks! */
         errno = SOCKET_ERRNO;           
+
            return(cc);
        }
        else {
index e9917c6338504c14ab54dd4fac06c1f858d2347c..02dd1c8cef56de9ee6b32233200cb3a412e2ce48 100644 (file)
@@ -1,3 +1,9 @@
+1999-06-09 Miro Jurisic   <meeroh@mit.edu>
+
+       * prof_file.c (profile_update_file): if fopen fails and errno is 0, set
+       errno to ENOENT so that we can try multiple names for settings file
+       (From Chas Williams)
+
 Wed May 19 11:46:02 1999  Danilo Almeida  <dalmeida@mit.edu>
 
        * Makefile.in: Add windows build rules for putting header files in
index 0f1ac658fd20cb0fad7887343c200d24ad2a5dbc..8606bf79e4901f0e54220cefc7bb2f7eb5618986 100644 (file)
@@ -130,7 +130,7 @@ errcode_t profile_update_file(prf)
        if (f == NULL) {
                retval = errno;
                if (retval == 0)
-                       retval = PROF_FAIL_OPEN;
+                       retval = ENOENT;
                return retval;
        }
        prf->upd_serial++;