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>
17 static const struct {int bit; const char *name;} statlist[] = {
19 { STA_PPSFREQ, "PPSFREQ" },
20 { STA_PPSTIME, "PPSTIME" },
24 { STA_UNSYNC, "UNSYNC" },
25 { STA_FREQHOLD, "FREQHOLD" },
26 { STA_PPSSIGNAL, "PPSSIGNAL" },
27 { STA_PPSJITTER, "PPSJITTER" },
28 { STA_PPSWANDER, "PPSWANDER" },
29 { STA_PPSERROR, "PPSERROR" },
30 { STA_CLOCKERR, "CLOCKERR" },
33 static const char * const ret_code_descript[] = {
37 "leap second in progress",
38 "leap second has occurred",
39 "clock not synchronized" };
41 int adjtimex_main(int argc, char **argv)
47 char *opt_o, *opt_f, *opt_p, *opt_t;
53 opt = getopt32(argc, argv, "qo:f:p:t:",
54 &opt_o, &opt_f, &opt_p, &opt_t);
55 //if (opt & 0x1) // -q
56 if (opt & 0x2) { // -o
57 txc.offset = xatoi(opt_o);
58 txc.modes |= ADJ_OFFSET_SINGLESHOT;
60 if (opt & 0x4) { // -f
61 txc.freq = xatou(opt_f);
62 txc.modes |= ADJ_FREQUENCY;
64 if (opt & 0x8) { // -p
65 txc.constant = xatoi(opt_p);
66 txc.modes |= ADJ_TIMECONST;
68 if (opt & 0x10) { // -t
69 txc.tick = xatoi(opt_t);
70 txc.modes |= ADJ_TICK;
72 if (argc != optind) { /* no valid non-option parameters */
78 if (ret < 0) perror("adjtimex");
80 if (!(opt & OPT_quiet) && ret>=0) {
88 txc.modes, txc.offset, txc.freq, txc.maxerror,
89 txc.esterror, txc.status);
91 /* representative output of next code fragment:
94 for (i=0; statlist[i].name; i++) {
95 if (txc.status & statlist[i].bit) {
96 if (sep) fputs(" | ",stdout);
97 fputs(statlist[i].name,stdout);
103 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
105 "-p timeconstant: %ld\n"
109 " time.tv_sec: %ld\n"
110 " time.tv_usec: %ld\n"
111 " return value: %d (%s)\n",
113 txc.precision, txc.tolerance, txc.tick,
114 (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);