title: How does ntpdate update the time?
body: <p>I used <code>strace</code> on <code>ntpdate</code> command which calls adjtimex to adjust time.
  I got this:</p>
  
  <pre><code>adjtimex({modes=ADJ_OFFSET|0x8000, offset=-479139, freq=0, maxerror=16000000, esterror=16000000, status=STA_UNSYNC, constant=2, precision=1, tolerance=32768000, time={1352220968, 428418}, tick=10000, ppsfreq=0, jitter=0, shift=0, stabil=0, jitcnt=0, calcnt=0, errcnt=0, stbcnt=0}) = 5 (TIME_ERROR)
  </code></pre>
  
  <p>Then I looked into implementation of adjtimex API in do_adjtimex main funcition.
  But from the code I can not see how <code>ntpdate</code> adjusts the time.</p>
  
  <pre><code>modes=ADJ_OFFSET|0x8000=ADJ_OFFSET|ADJ_ADJTIME
  
  int do_adjtimex(struct timex *txc)
  {
      struct timespec ts;
      int result;
  /* Validate the data before disabling interrupts */
  if (txc-&gt;modes &amp; ADJ_ADJTIME) { **&lt;----this is true. modes as ADJ_OFFSET|ADJ_ADJTIME**
      /* singleshot must not be used with any other mode bits */
      if (!(txc-&gt;modes &amp; ADJ_OFFSET_SINGLESHOT))
          return -EINVAL;
      if (!(txc-&gt;modes &amp; ADJ_OFFSET_READONLY) &amp;&amp;
          !capable(CAP_SYS_TIME))
          return -EPERM;
  } else {
      .....
  }
  
  if (txc-&gt;modes &amp; ADJ_SETOFFSET) { **《===this is false**
      .....
  }
  
  getnstimeofday(&amp;ts);**《------------just get the walk time**
  
  spin_lock_irq(&amp;ntp_lock);
  
  if (txc-&gt;modes &amp; ADJ_ADJTIME) {&lt;----this is true.
      long save_adjust = time_adjust; **&lt;----this is global valu eoffset=-479139**
  
      if (!(txc-&gt;modes &amp; ADJ_OFFSET_READONLY)) {
          /* adjtime() is independent from ntp_adjtime() */
          time_adjust = txc-&gt;offset;
          ntp_update_frequency();
      }
      txc-&gt;offset = save_adjust;
  } else {
  
      .......
  }
  
  result = time_state;    /* mostly `TIME_OK' */ this is 
  /* check for errors */
  if (is_error_status(time_status)) **&lt;----this is STA_UNSYNC**
      result = TIME_ERROR;
  
  txc-&gt;freq      = shift_right((time_freq &gt;&gt; PPM_SCALE_INV_SHIFT) *
                   PPM_SCALE_INV, NTP_SCALE_SHIFT);
  txc-&gt;maxerror      = time_maxerror;
  txc-&gt;esterror      = time_esterror;
  txc-&gt;status    = time_status;
  txc-&gt;constant      = time_constant;
  txc-&gt;precision     = 1;
  txc-&gt;tolerance     = MAXFREQ_SCALED / PPM_SCALE;
  txc-&gt;tick      = tick_usec;
  txc-&gt;tai       = time_tai;
  
  /* fill PPS status fields */
  pps_fill_timex(txc);
  
  spin_unlock_irq(&amp;ntp_lock);
  
  txc-&gt;time.tv_sec = ts.tv_sec;
  txc-&gt;time.tv_usec = ts.tv_nsec;
  if (!(time_status &amp; STA_NANO))
      txc-&gt;time.tv_usec /= NSEC_PER_USEC;
  
  notify_cmos_timer(); &lt;---- call sync_cmos_clock.
  
  return result;
  }
  </code></pre>
  
  <p>sync_cmos_clock checks whether ntp is synced. time_status is STA_UNSYNC.
  Just do nothing and return.</p>
  
  <pre><code>if (!ntp_synced()) { /*
                        * Not synced, exit, do not restart a timer (if one is
                        * running, let it run out). */
  return; }
  </code></pre>
  
  <p>Am I missing something?</p>