Novell is now a part of Micro Focus

Programmatically Checking Time Synchronization

Novell Cool Solutions: Feature
By Siddharth Jagtiani

Digg This - Slashdot This

Posted: 23 Sep 2003

Update: Siddarth has added new information to this article.

If you've ever wanted to check for time synchronization events easily and automatically, you may have wondered if you should look at the CLOCK_SYNCHRONIZATION_IS_ACTIVE and CLOCK_IS_NEARLY_IN_SYNC flags. The simple answer to the question is "Yes, you should wait for CLOCK_IS_NEARLY_IN_SYNC to SET." For most cases, this will do. Here the scoop:


CLOCK_SYNCHRONIZATION_IS_ACTIVE - When XNTPD/Timesync load, we SET this flag. This means, "the time synchronization service is active, you only need to wait a while until time can actually synchronize".

CLOCK_IS_NETWORK_SYNCHRONIZED - Check the value for this flag to know if time is syncrhonized to its time source.

CLOCK_IS_NEARLY_IN_SYNC - Only XNTPD (NTPv3 Daemon on NetWare 6.5) uses this flag. This flag is SET when time is as close as 500 ms to its time source. Hence most applications which are ok with this accuracy can use this flag instead of waiting for CLOCK_IS_NETWORK_SYNCHRONIZED. Or applications can initialize and do initial work until they get CLOCK_IS_SYNCHRONIZED OR CLOCK_IS_NETWORK_SYNCHRONIZED as SET.

Improving Synchronization Performance

Here's the advanced portion of the explanation. How do we get time to synchronize faster and get CLOCK_IS_NEARLY_IN_SYNC to SET within 10 seconds of XNTPD load. Answer is simple: either

  • Call "XNTPD" with "-S" option.
  • Or
  • Edit the ntp.conf file and put "stepclock" keyword in a new line of the configuration file.

The second method (conf file), helps you to avoid the "-S" in the command line. So it's more like a persistent configuration.

If you want time to synchronize fast, you should first use the "stepclock" keyword in your conf file and then load xntpd. After that, wait for only CLOCK_IS_NEARLY_IN_SYNC flag to SET. This will tell you that time has syncrhonized and is as close as 500 ms of the time source. Then when your application reaches a high precision state where 500ms is not enough but you instead need 10 ms, then you should should wait for CLOCK_SYNCHRONIZATION_IS_ACTIVE.

Additional Information

I want to update this cool tip with some more information.


#include <synclock.h>
Synchronized_Clock_T clock ;
int syncStatus ;
GetSyncClockFields(SYNCCLOCK_ALL_DEFINED_BITS, &clock);
syncStatus = clock.statusFlags &
     if ( (syncStatus & CLOCK_IS_SYNCHRONIZED) || 
            printf("Time synchronization is loaded and synchronized") ;
    else if (syncStatus & CLOCK_IS_NEARLY_IN_SYNC)
             printf("Time synchronization is loaded and nearly synchronized" ) ;
             printf("Time synchronization is loaded and NOT synchronized" ) ;
      printf("Time synchronization is NOT loaded" ) ; 

NEW Info

// NetWare 5.x and 6.0, 6.5
// NetWare 6.5 Only
#define CLOCK_IS_NEARLY_IN_SYNC0x00000010L

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates