[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ntpd crashes.



Mauro <mrsanna1@gmail.com> writes:

> PROBLEM!!!!!!
> System clock is gone one hour ahead, ntp stops to run with no messages
> logs and I now I'm in trouble because I don't know what to do.

Try the program below and see what it says.  If it actually tells you
that the time is out of sync, you can write a script around it that
checks the exit code, restores system time from hardware time (if the
hardware time isn't off, too) or with ntpdate, restarts your NTP daemon
if needed and the program.  It won't keep your time from jumping and
only would make it jump back right away.  It's ugly, yet better than
nothing.

If it doesn't tell you that the time is out of sync when it is, I would
wonder why the kernel doesn't know about it ...

My system time doesn't jump and I don't want it to, so I can only say
that the program runs and that the return value of adjtimex() indicates
that the time is ok.


You could also try to use ntpdate with the -q or -d option to get time
from an external reference, verify that with the system time and do
something when the system time is suddenly off.

What's in the configuration of your NTP daemon?  Perhaps there's
something wrong with that.


// this software is licensend under the GPL
// written by lee@yun.yagibdah.de, 2012-09-26
// compile with something like:
//   gcc -Wall -O2 timetellbad.c -o timetellbad
//
// supposed to print a message to stdout, then exit with code 2 when the
//   kernel figures the time is out of sync --- checks every TICK seconds
//


#include <stdio.h>
#include <sys/timex.h>
#include <unistd.h>


// sleep 5 seconds between checks
#define TICK 5


int main(int argc, char *argv[] ) {

  struct timex tx;
  int cstate;

  tx.modes = 0;

  while(1) {

    cstate = adjtimex( &tx);

    if( cstate == -1) {
      perror("error");
      return 1;
    }
    else {
      if( cstate == TIME_BAD) {
	puts("time is out of sync, exiting");
	return 2;
      }
    }

    sleep(TICK);
  }

  return 0;
}


-- 
Debian testing amd64


Reply to: