Last active
January 20, 2018 16:04
-
-
Save kerolasa/88ee7a56fc58749b3c64ac8605c92da1 to your computer and use it in GitHub Desktop.
adjtimex(2) human readable print out utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is adjtimex(2) human readable print out utility. | |
* | |
* The program has BSD 2-clause license which also known as "Simplified | |
* BSD License" or "FreeBSD License". | |
* | |
* Copyright 2018- Sami Kerola. All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are | |
* met: | |
* | |
* 1. Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* | |
* 2. Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the | |
* distribution. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS OR | |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
* | |
* The views and conclusions contained in the software and documentation are | |
* those of the authors and should not be interpreted as representing | |
* official policies, either expressed or implied, of Sami Kerola. | |
* | |
* https://gist.github.com/kerolasa/88ee7a56fc58749b3c64ac8605c92da1 | |
*/ | |
#include <stdio.h> | |
#include <sys/timex.h> | |
int main(int argc, char **argv) | |
{ | |
struct timex tx = { 0 }; | |
int ret; | |
int nano; | |
ret = ntp_adjtime(&tx); | |
nano = (tx.status & STA_NANO); | |
printf("ntp_adjtime() return value: "); | |
switch(ret) { | |
case TIME_OK: | |
printf("TIME_OK\n"); | |
break; | |
case TIME_INS: | |
printf("TIME_INS a leap second will be added at the end of the UTC day\n"); | |
break; | |
case TIME_DEL: | |
printf("TIME_DEL a leap second will be deleted at the end of the UTC day\n"); | |
break; | |
case TIME_OOP: | |
printf("TIME_OOP leap-second insertion or deletion has been completed\n"); | |
break; | |
case TIME_ERROR: | |
printf("TIME_ERROR system clock is not synchronized to a reliable server\n"); | |
break; | |
default: | |
printf("unexpected return value: %d\n", ret); | |
break; | |
} | |
printf("%20ld Time offset in %sseconds\n", tx.offset, nano ? "nano" : "micro"); | |
printf("%20ld Frequency offset\n", tx.freq); | |
printf("%20ld Maximum error microseconds\n", tx.maxerror); | |
printf("%20ld Estimated error microseconds\n", tx.esterror); | |
printf("%20d Clock status\n", tx.status); | |
if (tx.status & STA_PLL) {printf("%*s ^ phase-locked loop updates\n", 21, "");} | |
if (tx.status & STA_PPSFREQ) {printf("%*s ^ pulse-per-second frequency discipline\n", 21, "");} | |
if (tx.status & STA_PPSTIME) {printf("%*s ^ pulse-per-second time discipline\n", 21, "");} | |
if (tx.status & STA_FLL) {printf("%*s ^ frequency-lock mode\n", 21, "");} | |
if (tx.status & STA_INS) {printf("%*s ^ insert leap\n", 21, "");} | |
if (tx.status & STA_DEL) {printf("%*s ^ delete leap\n", 21, "");} | |
if (tx.status & STA_UNSYNC) {printf("%*s ^ clock unsynchronized\n", 21, "");} | |
if (tx.status & STA_FREQHOLD) {printf("%*s ^ hold frequency\n", 21, "");} | |
if (tx.status & STA_PPSSIGNAL) {printf("%*s ^ PPS signal present\n", 21, "");} | |
if (tx.status & STA_PPSJITTER) {printf("%*s ^ PPS signal jitter exceeded\n", 21, "");} | |
if (tx.status & STA_PPSWANDER) {printf("%*s ^ PPS signal wander exceeded\n", 21, "");} | |
if (tx.status & STA_PPSERROR) {printf("%*s ^ PPS signal calibration error\n", 21, "");} | |
if (tx.status & STA_CLOCKERR) {printf("%*s ^ clock hardware fault\n", 21, "");} | |
if (tx.status & STA_NANO) {printf("%*s ^ nanosecond resolution\n", 21, "");} | |
if (tx.status & STA_MODE) {printf("%*s ^ frequency-locked loop mode\n", 21, "");} | |
if (tx.status & STA_CLK) {printf("%*s ^ ADJ_TICK in use\n", 21, "");} | |
printf("%20ld PLL (phase-locked loop) time constant\n", tx.constant); | |
printf("%20ld Clock precision microseconds\n", tx.precision); | |
printf("%20ld Clock frequency tolerance\n", tx.tolerance); | |
printf("%ld.%09ld Current time\n", tx.time.tv_sec, tx.time.tv_usec); | |
printf("%20ld Microseconds between clock ticks\n", tx.tick); | |
if (tx.status & STA_PPSFREQ || tx.status & STA_PPSTIME) { | |
printf("%20ld PPS (pulse per second) frequency\n", tx.ppsfreq); | |
printf("%20ld PPS jitter (read-only); %sseconds\n", tx.jitter, nano ? "nano" : "micro"); | |
printf("%20d PPS interval duration\n", tx.shift); | |
printf("%20ld PPS stability\n", tx.stabil); | |
printf("%20ld PPS count of jitter limit exceeded events\n", tx.jitcnt); | |
printf("%20ld PPS count of calibration intervals\n", tx.calcnt); | |
printf("%20ld PPS count of calibration errors\n", tx.errcnt); | |
printf("%20ld PPS count of stability limit exceeded events\n", tx.stbcnt); | |
} | |
printf("%20d TAI offset\n", tx.tai); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment