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 uint16_t statlist_bit[] = {
33 static const char statlist_name[] =
49 static const char ret_code_descript[] =
50 "clock synchronized" "\0"
51 "insert leap second" "\0"
52 "delete leap second" "\0"
53 "leap second in progress" "\0"
54 "leap second has occurred" "\0"
55 "clock not synchronized"
58 int adjtimex_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
59 int adjtimex_main(int argc UNUSED_PARAM, char **argv)
65 char *opt_o, *opt_f, *opt_p, *opt_t;
70 opt_complementary = "=0"; /* no valid non-option parameters */
71 opt = getopt32(argv, "qo:f:p:t:",
72 &opt_o, &opt_f, &opt_p, &opt_t);
74 //if (opt & 0x1) // -q
75 if (opt & 0x2) { // -o
76 txc.offset = xatol(opt_o);
77 txc.modes |= ADJ_OFFSET_SINGLESHOT;
79 if (opt & 0x4) { // -f
80 txc.freq = xatol(opt_f);
81 txc.modes |= ADJ_FREQUENCY;
83 if (opt & 0x8) { // -p
84 txc.constant = xatol(opt_p);
85 txc.modes |= ADJ_TIMECONST;
87 if (opt & 0x10) { // -t
88 txc.tick = xatol(opt_t);
89 txc.modes |= ADJ_TICK;
95 bb_perror_nomsg_and_die();
98 if (!(opt & OPT_quiet)) {
105 "-f frequency: %ld\n"
109 txc.modes, txc.offset, txc.freq, txc.maxerror,
110 txc.esterror, txc.status);
112 /* representative output of next code fragment:
114 name = statlist_name;
116 for (i = 0; statlist_bit[i]; i++) {
117 if (txc.status & statlist_bit[i]) {
119 fputs(" | ", stdout);
123 name += strlen(name) + 1;
128 descript = nth_string(ret_code_descript, ret);
130 "-p timeconstant: %ld\n"
134 " time.tv_sec: %ld\n"
135 " time.tv_usec: %ld\n"
136 " return value: %d (%s)\n",
138 txc.precision, txc.tolerance, txc.tick,
139 (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);