/contrib/ntp/util/testrs6000.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 55 lines · 42 code · 4 blank · 9 comment · 6 complexity · 4fbb1ee489cf1442ad1f79a2664607c7 MD5 · raw file

  1. /* Checks for the RS/6000 AIX adjtime() bug, in which if a negative
  2. * offset is given, the system gets messed up and never completes the
  3. * adjustment. If the problem is fixed, this program will print the
  4. * time, sit there for 10 seconds, and exit. If the problem isn't fixed,
  5. * the program will print an occasional "result=nnnnnn" (the residual
  6. * slew from adjtime()).
  7. *
  8. * Compile this with bsdcc and run it as root!
  9. */
  10. #include <signal.h>
  11. #include <sys/time.h>
  12. #include <time.h>
  13. #include <stdio.h>
  14. int timeout();
  15. struct timeval adjustment, result;
  16. int
  17. main (
  18. int argc,
  19. char *argv[]
  20. )
  21. {
  22. struct itimerval value, oldvalue;
  23. int i;
  24. time_t curtime;
  25. curtime = time(0);
  26. printf("Starting: %s", ctime(&curtime));
  27. value.it_interval.tv_sec = value.it_value.tv_sec = 1;
  28. value.it_interval.tv_usec = value.it_value.tv_usec = 0;
  29. adjustment.tv_sec = 0;
  30. adjustment.tv_usec = -2000;
  31. signal(SIGALRM, timeout);
  32. setitimer(ITIMER_REAL, &value, &oldvalue);
  33. for (i=0; i<10; i++) {
  34. pause();
  35. }
  36. }
  37. int
  38. timeout(
  39. int sig,
  40. int code,
  41. struct sigcontext *scp
  42. )
  43. {
  44. signal (SIGALRM, timeout);
  45. if (adjtime(&adjustment, &result))
  46. printf("adjtime call failed\n");
  47. if (result.tv_sec != 0 || result.tv_usec != 0) {
  48. printf("result.u = %d.%06.6d ", (int) result.tv_sec,
  49. (int) result.tv_usec);
  50. }
  51. }