2 * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
4 * Originally written: October 1997
5 * Last hack: March 2001
6 * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License (Version 2,
10 * June 1991) as published by the Free Software Foundation. At the
11 * time of writing, that license was published by the FSF with the URL
12 * http://www.gnu.org/copyleft/gpl.html, and is incorporated herein by
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * This adjtimex(1) is very similar in intent to adjtimex(8) by Steven
21 * Dick <ssd@nevets.oau.org> and Jim Van Zandt <jrv@vanzandt.mv.com>
22 * (see http://metalab.unc.edu/pub/Linux/system/admin/time/adjtimex*).
23 * That version predates this one, and is _much_ bigger and more
24 * featureful. My independently written version was very similar to
25 * Steven's from the start, because they both follow the kernel timex
26 * structure. I further tweaked this version to be equivalent to Steven's
27 * where possible, but I don't like getopt_long, so the actual usage
28 * syntax is incompatible.
30 * Amazingly enough, my Red Hat 5.2 sys/timex (and sub-includes)
31 * don't actually give a prototype for adjtimex(2), so building
32 * this code (with -Wall) gives a warning. Later versions of
33 * glibc fix this issue.
35 * This program is too simple for a Makefile, just build with:
36 * gcc -Wall -O adjtimex.c -o adjtimex
38 * busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov>
39 * It will autosense if it is built in a busybox environment, based
40 * on the BB_VER preprocessor macro.
44 #include <sys/types.h>
47 #include <sys/timex.h>
50 static struct {int bit; char *name;} statlist[] = {
52 { STA_PPSFREQ, "PPSFREQ" },
53 { STA_PPSTIME, "PPSTIME" },
57 { STA_UNSYNC, "UNSYNC" },
58 { STA_FREQHOLD, "FREQHOLD" },
59 { STA_PPSSIGNAL, "PPSSIGNAL" },
60 { STA_PPSJITTER, "PPSJITTER" },
61 { STA_PPSWANDER, "PPSWANDER" },
62 { STA_PPSERROR, "PPSERROR" },
63 { STA_CLOCKERR, "CLOCKERR" },
66 static char *ret_code_descript[] = {
70 "leap second in progress",
71 "leap second has occurred",
72 "clock not synchronized" };
75 #define main adjtimex_main
77 void usage(char *prog)
80 "Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n",
83 #define bb_show_usage() usage(argv[0])
86 int main(int argc, char ** argv)
94 c = getopt( argc, argv, "qo:f:p:t:");
101 txc.offset = atoi(optarg);
102 txc.modes |= ADJ_OFFSET_SINGLESHOT;
105 txc.freq = atoi(optarg);
106 txc.modes |= ADJ_FREQUENCY;
109 txc.constant = atoi(optarg);
110 txc.modes |= ADJ_TIMECONST;
113 txc.tick = atoi(optarg);
114 txc.modes |= ADJ_TICK;
121 if (argc != optind) { /* no valid non-option parameters */
126 ret = adjtimex(&txc);
128 if (ret < 0) perror("adjtimex");
130 if (!quiet && ret>=0) {
134 "-f frequency: %ld\n"
138 txc.modes, txc.offset, txc.freq, txc.maxerror,
139 txc.esterror, txc.status);
141 /* representative output of next code fragment:
144 for (i=0; statlist[i].name; i++) {
145 if (txc.status & statlist[i].bit) {
146 if (sep) fputs(" | ",stdout);
147 fputs(statlist[i].name,stdout);
153 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
155 "-p timeconstant: %ld\n"
159 " time.tv_sec: %ld\n"
160 " time.tv_usec: %ld\n"
161 " return value: %d (%s)\n",
163 txc.precision, txc.tolerance, txc.tick,
164 (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);