wakesync.patch   [plain text]


diff -up -r /SourceCache/ntp/ntp-44.3/ntp/include/ntpd.h ./include/ntpd.h
--- /SourceCache/ntp/ntp-44.3/ntp/include/ntpd.h	2008-08-27 14:58:46.000000000 -0700
+++ ./include/ntpd.h	2008-12-04 11:19:35.000000000 -0800
@@ -246,6 +246,7 @@ extern  int	sock_hash P((struct sockaddr
 extern	double	old_drift;
 
 extern int save_drift_file P((void));
+extern int awoke P((void));
 
 /*
  * Variable declarations for ntpd.
@@ -443,6 +444,7 @@ extern u_char	sys_revoke;		/* keys revok
 extern volatile u_long alarm_overflow;
 extern u_long	current_time;		/* current time (s) */
 extern u_long	dns_timer;
+extern u_long	awake_timer;
 extern u_long	timer_timereset;
 extern u_long	timer_overflows;
 extern u_long	timer_xmtcalls;
diff -up -r /SourceCache/ntp/ntp-44.3/ntp/ntpd/Makefile.in ./ntpd/Makefile.in
--- /SourceCache/ntp/ntp-44.3/ntp/ntpd/Makefile.in	2008-08-19 14:49:54.000000000 -0700
+++ ./ntpd/Makefile.in	2008-12-04 11:57:36.000000000 -0800
@@ -280,7 +280,7 @@ man_MANS = ntpd.1 ntpdsim.1
 # sqrt                                ntp_control.o
 # floor                               refclock_wwv.o
 # which are (usually) provided by -lm.
-ntpd_LDADD = $(LDADD) -lm @LCRYPTO@ $(LIBOPTS_LDADD) ../libntp/libntp.a -framework IOKit -lresolv
+ntpd_LDADD = $(LDADD) -lm @LCRYPTO@ $(LIBOPTS_LDADD) ../libntp/libntp.a -framework IOKit -framework CoreFoundation -lresolv
 ntpdsim_LDADD = $(LDADD) ../libntp/libntpsim.a -lm @LCRYPTO@ $(LIBOPTS_LDADD)
 ntpdsim_CFLAGS = $(CFLAGS) -DSIM
 check_y2k_LDADD = $(LDADD) ../libntp/libntp.a
diff -up -r /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_io.c ./ntpd/ntp_io.c
--- /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_io.c	2008-08-19 14:49:54.000000000 -0700
+++ ./ntpd/ntp_io.c	2008-12-04 11:46:04.000000000 -0800
@@ -816,6 +816,9 @@ remove_interface(struct interface *inter
 static void
 list_if_listening(struct interface *interface, u_short port)
 {
+	if (awoke()) {
+		awake_timer = current_time;
+	}
 	msyslog(LOG_INFO, "Listening on interface #%d %s, %s#%d %s",
 		interface->ifnum,
 		interface->name,
diff -up -r /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_timer.c ./ntpd/ntp_timer.c
--- /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_timer.c	2008-10-21 15:06:04.000000000 -0700
+++ ./ntpd/ntp_timer.c	2008-12-04 11:45:09.000000000 -0800
@@ -50,6 +50,7 @@ static	u_long stats_timer;		/* stats tim
 static	u_long huffpuff_timer;		/* huff-n'-puff timer */
 static  u_long interface_timer;	        /* interface update timer */
 u_long dns_timer;		/* update DNS flags on peers */
+u_long awake_timer;		/* Force a time sync after wakeup */
 #ifdef OPENSSL
 static	u_long revoke_timer;		/* keys revoke timer */
 u_char	sys_revoke = KEY_REVOKE;	/* keys revoke timeout (log2 s) */
@@ -303,6 +304,17 @@ timer(void)
 #endif /* REFCLOCK */
 	}
 
+	if (awake_timer && awake_timer <= current_time) {
+		for (n = 0; n < NTP_HASH_SIZE; n++) {
+			for (peer = peer_hash[n]; peer != 0; peer = peer->next) {
+				peer->burst = NTP_BURST;
+				peer->nextdate = current_time;
+			}
+		}
+		allow_panic = TRUE; /* Allow for large time offsets */
+		init_loopfilter();
+		awake_timer = 0;
+	}
 	/*
 	 * Now dispatch any peers whose event timer has expired. Be careful
 	 * here, since the peer structure might go away as the result of
diff -up -r /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_util.c ./ntpd/ntp_util.c
--- /SourceCache/ntp/ntp-44.3/ntp/ntpd/ntp_util.c	2008-09-25 15:50:51.000000000 -0700
+++ ./ntpd/ntp_util.c	2008-12-04 11:18:03.000000000 -0800
@@ -885,3 +885,31 @@ ntp_exit(int retval)
   exit(retval);
 }
 #endif
+
+#define kMaxUUIDLen 37
+
+/* Did we wake up since last check? Use SL API */
+/* for Leopard could trigger off changes to kern.waketime */
+int awoke(void)
+{
+    static char sleepwakeuuid[kMaxUUIDLen];
+    int rc = 0;
+    io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, 
+						   kIOPowerPlane ":/IOPowerConnection/IOPMrootDomain");
+    CFStringRef uuidString = IORegistryEntryCreateCFProperty(
+	    service,
+	    CFSTR(kIOPMSleepWakeUUIDKey),
+	    kCFAllocatorDefault, 0);
+    if (uuidString) {
+	    char newuuid[kMaxUUIDLen];
+	    CFStringGetCString(uuidString, newuuid, sizeof(newuuid), 
+			       kCFStringEncodingUTF8);
+	    rc = strncasecmp(newuuid, sleepwakeuuid, sizeof(newuuid));
+	    if (rc) {
+		    strlcpy(sleepwakeuuid, newuuid, sizeof(sleepwakeuuid));
+	    }
+	    CFRelease(uuidString);
+    }
+    IOObjectRelease(service);
+    return rc;
+}