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.
16 #include <sys/types.h>
19 #include <sys/timex.h>
21 static const struct {int bit; const char *name;} statlist[] = {
23 { STA_PPSFREQ, "PPSFREQ" },
24 { STA_PPSTIME, "PPSTIME" },
28 { STA_UNSYNC, "UNSYNC" },
29 { STA_FREQHOLD, "FREQHOLD" },
30 { STA_PPSSIGNAL, "PPSSIGNAL" },
31 { STA_PPSJITTER, "PPSJITTER" },
32 { STA_PPSWANDER, "PPSWANDER" },
33 { STA_PPSERROR, "PPSERROR" },
34 { 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" };
45 int adjtimex_main(int argc, char **argv)
51 char *opt_o, *opt_f, *opt_p, *opt_t;
57 opt = getopt32(argc, argv, "qo:f:p:t:",
58 &opt_o, &opt_f, &opt_p, &opt_t);
59 //if (opt & 0x1) // -q
60 if (opt & 0x2) { // -o
61 txc.offset = atoi(opt_o);
62 txc.modes |= ADJ_OFFSET_SINGLESHOT;
64 if (opt & 0x4) { // -f
65 txc.freq = atoi(opt_f);
66 txc.modes |= ADJ_FREQUENCY;
68 if (opt & 0x8) { // -p
69 txc.constant = atoi(opt_p);
70 txc.modes |= ADJ_TIMECONST;
72 if (opt & 0x10) { // -t
73 txc.tick = atoi(opt_t);
74 txc.modes |= ADJ_TICK;
76 if (argc != optind) { /* no valid non-option parameters */
82 if (ret < 0) perror("adjtimex");
84 if (!(opt & OPT_quiet) && ret>=0) {
92 txc.modes, txc.offset, txc.freq, txc.maxerror,
93 txc.esterror, txc.status);
95 /* representative output of next code fragment:
98 for (i=0; statlist[i].name; i++) {
99 if (txc.status & statlist[i].bit) {
100 if (sep) fputs(" | ",stdout);
101 fputs(statlist[i].name,stdout);
107 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
109 "-p timeconstant: %ld\n"
113 " time.tv_sec: %ld\n"
114 " time.tv_usec: %ld\n"
115 " return value: %d (%s)\n",
117 txc.precision, txc.tolerance, txc.tick,
118 (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);