1 /* vi: set sw=4 ts=4: */
3 * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
5 * Originally written: October 1997
6 * Last hack: March 2001
7 * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
9 * busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov>
11 * Licensed under GPLv2 or later, see file License in this tarball for details.
15 #include <sys/timex.h>
22 { STA_PPSFREQ, "PPSFREQ" },
23 { STA_PPSTIME, "PPSTIME" },
27 { STA_UNSYNC, "UNSYNC" },
28 { STA_FREQHOLD, "FREQHOLD" },
29 { STA_PPSSIGNAL, "PPSSIGNAL" },
30 { STA_PPSJITTER, "PPSJITTER" },
31 { STA_PPSWANDER, "PPSWANDER" },
32 { STA_PPSERROR, "PPSERROR" },
33 { STA_CLOCKERR, "CLOCKERR" },
37 static const char *const ret_code_descript[] = {
41 "leap second in progress",
42 "leap second has occurred",
43 "clock not synchronized"
46 int adjtimex_main(int argc, char **argv);
47 int adjtimex_main(int argc, char **argv)
53 char *opt_o, *opt_f, *opt_p, *opt_t;
59 opt = getopt32(argv, "qo:f:p:t:",
60 &opt_o, &opt_f, &opt_p, &opt_t);
61 //if (opt & 0x1) // -q
62 if (opt & 0x2) { // -o
63 txc.offset = xatol(opt_o);
64 txc.modes |= ADJ_OFFSET_SINGLESHOT;
66 if (opt & 0x4) { // -f
67 txc.freq = xatol(opt_f);
68 txc.modes |= ADJ_FREQUENCY;
70 if (opt & 0x8) { // -p
71 txc.constant = xatol(opt_p);
72 txc.modes |= ADJ_TIMECONST;
74 if (opt & 0x10) { // -t
75 txc.tick = xatol(opt_t);
76 txc.modes |= ADJ_TICK;
78 if (argc != optind) { /* no valid non-option parameters */
84 if (ret < 0) perror("adjtimex");
86 if (!(opt & OPT_quiet) && ret>=0) {
94 txc.modes, txc.offset, txc.freq, txc.maxerror,
95 txc.esterror, txc.status);
97 /* representative output of next code fragment:
100 for (i=0; statlist[i].name; i++) {
101 if (txc.status & statlist[i].bit) {
102 if (sep) fputs(" | ",stdout);
103 fputs(statlist[i].name,stdout);
109 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
111 "-p timeconstant: %ld\n"
115 " time.tv_sec: %ld\n"
116 " time.tv_usec: %ld\n"
117 " return value: %d (%s)\n",
119 txc.precision, txc.tolerance, txc.tick,
120 (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);