Re: Time off by -5 hours

email builder <[email protected]> Fri, 4 Nov 2005 11:09:46 -0800 (PST)
Newsgroups gmane.comp.lib.libtai
Message-ID <[email protected]>
> >> that when I updated our "clockctl" config file with an active NTP server
> >> (anyone have an enhanced version of this approach that allows for using
> a
> >> list of NTP servers so we can have some fallback?), 
> 
> I just came across the OpenBSD setup of ntp - they use pool.ntp.org as
> source. This gives a random set of 8 IP addresses of Stratum2 servers.

Oh, nice.  Thank you.
 
> I will look at the test function later - I'm too tired now.

I fixed it so that it is not specific to NTP; should also work for taiclock
users as well now.  I think it's more based on thedjbway.org's
implementation, but I don't think that's too far removed from yours, Frank. 
I have pasted the whole script in below for the sake of completeness.


#!/bin/sh
# interface to djb clockspeed
# ===

# read configuration:
if [ -r /etc/clockspeed/clockspeed.conf ] ; then
  . /etc/clockspeed/clockspeed.conf
else
  echo "$0: configuration error: unable to read clockspeed.conf"
  exit 1
fi


# choose which CLOCK_IP to use
#
choose_clock_ip()
{
  echo "Looking for an active master server..."

  # start in random place in array
  MAX=${#CLOCK_IPS[@]}
  START=$RANDOM
  let "START %= $MAX"  # gives random number less than $MAX

  # set $START to an index that you KNOW will fail here
  # to test that this function actually works
  #START=15

  J="$START"
  CLOCK_IP=0
  while test 1; do

      echo "Trying ${CLOCK_IPS[$J]}..."
      clock_pick ${CLOCK_IPS[$J]} 1
      if [ $? = 0 ]; then
          CLOCK_IP="${CLOCK_IPS[$J]}"
          echo "Will use ${CLOCK_IPS[$J]}"
          break
      fi

      # loop control...
      J=`expr $J + 1`

      if [ $J = $START ]; then
          break

      elif [ $J = $MAX -a $START = 0 ]; then
          break

      elif [ $J = $MAX ]; then
          J=0
      fi

  done

  if [ $CLOCK_IP = 0 ] ; then
      echo "$0: server error: no master servers were reachable"
      exit 1;
  fi
}


# clock_pick function:
#
# Expected args:
#    $1 - The IP of the master server to use
#    $2 - Hide output? 1 = Yes, any other (or no) value = No
#
clock_pick()
{
  case ${CLOCK_TYPE} in
  ntp|NTP)
      if [ "$2" = 1 ] ; then
          ${CLOCKSPEED_BIN}/sntpclock "$1" > /dev/null
      else
          ${CLOCKSPEED_BIN}/sntpclock "$1"
      fi
      ;;
  tai|TAI)
      if [ "$2" = 1 ] ; then
          ${CLOCKSPEED_BIN}/taiclock "$1" > /dev/null
      else
          ${CLOCKSPEED_BIN}/taiclock "$1"
      fi
      ;;
  *)
      echo "$0: configuration error: CLOCK_TYPE not recognized"
      exit 1;
      ;;
   esac
}


# make sure we have a good master server to connect to
choose_clock_ip


# process command:
case $1 in
a|atto)
    echo "Viewing current attoseconds in hardware tick:"
    ${CLOCKSPEED_BIN}/clockview < ${CLOCKSPEED_HOME}/etc/atto
    ;;
m|mark)
    echo "Obtaining new calibration mark from master server at ${CLOCK_IP}:"
    clock_pick ${CLOCK_IP} | tee ${CLOCKSPEED_HOME}/adjust |
${CLOCKSPEED_BIN}/clockview
    ;;
s|sync)
    echo "Setting system clock with master server at ${CLOCK_IP}:"
    clock_pick ${CLOCK_IP} | ${CLOCKSPEED_BIN}/clockadd && \
    clock_pick ${CLOCK_IP} | ${CLOCKSPEED_BIN}/clockview
    ;;
v|view)
    echo "Checking system clock against master server at ${CLOCK_IP}
(clockview):"
    clock_pick ${CLOCK_IP} | ${CLOCKSPEED_BIN}/clockview
    ;;
h|help)
    cat <<END_HELP
clockspeed control:
  atto -- inspect current "attoseconds"
  mark -- obtain new calibration mark for clockspeed
  sync -- set the system clock with master time server
  view -- check system clock against master time server
  help -- this screen
END_HELP
    ;;

*)
    echo "Usage: $0 [ a|atto | m|mark | s|sync | v|view | h|help ]"
    exit 1
    ;;
esac

exit 0




		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs