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 source tree.
13 //config:config ADJTIMEX
14 //config: bool "adjtimex (4.5 kb)"
16 //config: select PLATFORM_LINUX
18 //config: Adjtimex reads and optionally sets adjustment parameters for
19 //config: the Linux clock adjustment algorithm.
21 //applet:IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP))
23 //kbuild:lib-$(CONFIG_ADJTIMEX) += adjtimex.o
25 //usage:#define adjtimex_trivial_usage
26 //usage: "[-q] [-o OFF] [-f FREQ] [-p TCONST] [-t TICK]"
27 //usage:#define adjtimex_full_usage "\n\n"
28 //usage: "Read or set kernel time variables. See adjtimex(2)\n"
29 //usage: "\n -q Quiet"
30 //usage: "\n -o OFF Time offset, microseconds"
31 //usage: "\n -f FREQ Frequency adjust, integer kernel units (65536 is 1ppm)"
32 //usage: "\n -t TICK Microseconds per tick, usually 10000"
33 //usage: "\n (positive -t or -f values make clock run faster)"
34 //usage: "\n -p TCONST"
38 # include <linux/timex.h>
40 # include <sys/timex.h>
43 static const uint16_t statlist_bit[] ALIGN2 = {
59 static const char statlist_name[] ALIGN1 =
75 static const char ret_code_descript[] ALIGN1 =
76 "clock synchronized" "\0"
77 "insert leap second" "\0"
78 "delete leap second" "\0"
79 "leap second in progress" "\0"
80 "leap second has occurred" "\0"
81 "clock not synchronized"
84 int adjtimex_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
85 int adjtimex_main(int argc UNUSED_PARAM, char **argv)
91 char *opt_o, *opt_f, *opt_p, *opt_t;
96 opt_complementary = "=0"; /* no valid non-option parameters */
97 opt = getopt32(argv, "qo:f:p:t:",
98 &opt_o, &opt_f, &opt_p, &opt_t);
100 //if (opt & 0x1) // -q
101 if (opt & 0x2) { // -o
102 txc.offset = xatol(opt_o);
103 txc.modes |= ADJ_OFFSET_SINGLESHOT;
105 if (opt & 0x4) { // -f
106 txc.freq = xatol(opt_f);
107 txc.modes |= ADJ_FREQUENCY;
109 if (opt & 0x8) { // -p
110 txc.constant = xatol(opt_p);
111 txc.modes |= ADJ_TIMECONST;
113 if (opt & 0x10) { // -t
114 txc.tick = xatol(opt_t);
115 txc.modes |= ADJ_TICK;
118 ret = adjtimex(&txc);
121 bb_perror_nomsg_and_die();
124 if (!(opt & OPT_quiet)) {
130 "-o offset: %ld us\n"
131 "-f freq.adjust: %ld (65536 = 1ppm)\n"
135 txc.modes, txc.offset, txc.freq, txc.maxerror,
136 txc.esterror, txc.status);
138 /* representative output of next code fragment:
141 name = statlist_name;
143 for (i = 0; statlist_bit[i]; i++) {
144 if (txc.status & statlist_bit[i]) {
145 printf("%s%s", sep, name);
148 name += strlen(name) + 1;
153 descript = nth_string(ret_code_descript, ret);
155 "-p timeconstant: %ld\n"
156 " precision: %ld us\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);