aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2001-03-20 19:18:10 +0000
committerMark Whitley <markw@lineo.com>2001-03-20 19:18:10 +0000
commit6f93277f56f97852d6e4e937ef758df0cce7b8ef (patch)
treebe1bc8a7504d208fea701fa4686d93bb6bd62576
parentba372620c256b23340c5630098f1a81c10022386 (diff)
downloadbusybox-w32-6f93277f56f97852d6e4e937ef758df0cce7b8ef.tar.gz
busybox-w32-6f93277f56f97852d6e4e937ef758df0cce7b8ef.tar.bz2
busybox-w32-6f93277f56f97852d6e4e937ef758df0cce7b8ef.zip
Added adjtimex applet from Larry Doolittle.
-rw-r--r--Config.h1
-rw-r--r--adjtimex.c169
-rw-r--r--applets.h3
-rw-r--r--applets/usage.h13
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h13
-rw-r--r--miscutils/adjtimex.c169
-rw-r--r--usage.h13
8 files changed, 384 insertions, 0 deletions
diff --git a/Config.h b/Config.h
index 171385420..9022dd075 100644
--- a/Config.h
+++ b/Config.h
@@ -7,6 +7,7 @@
7// 7//
8// 8//
9// BusyBox Applications 9// BusyBox Applications
10//#define BB_ADJTIMEX
10//#define BB_AR 11//#define BB_AR
11#define BB_BASENAME 12#define BB_BASENAME
12#define BB_CAT 13#define BB_CAT
diff --git a/adjtimex.c b/adjtimex.c
new file mode 100644
index 000000000..02b6e89b0
--- /dev/null
+++ b/adjtimex.c
@@ -0,0 +1,169 @@
1/*
2 * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
3 *
4 * Originally written: October 1997
5 * Last hack: March 2001
6 * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
7 *
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
13 * reference.
14 *
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.
19 *
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.
29 *
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.
34 *
35 * This program is too simple for a Makefile, just build with:
36 * gcc -Wall -O adjtimex.c -o adjtimex
37 *
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.
41 */
42
43#include <stdio.h>
44#include <sys/types.h>
45#include <stdlib.h>
46#include <unistd.h>
47#include <sys/timex.h>
48#ifdef BB_VER
49#include "busybox.h"
50#endif
51
52static struct {int bit; char *name;} statlist[] = {
53 { STA_PLL, "PLL" },
54 { STA_PPSFREQ, "PPSFREQ" },
55 { STA_PPSTIME, "PPSTIME" },
56 { STA_FLL, "FFL" },
57 { STA_INS, "INS" },
58 { STA_DEL, "DEL" },
59 { STA_UNSYNC, "UNSYNC" },
60 { STA_FREQHOLD, "FREQHOLD" },
61 { STA_PPSSIGNAL, "PPSSIGNAL" },
62 { STA_PPSJITTER, "PPSJITTER" },
63 { STA_PPSWANDER, "PPSWANDER" },
64 { STA_PPSERROR, "PPSERROR" },
65 { STA_CLOCKERR, "CLOCKERR" },
66 { 0, NULL } };
67
68static char *ret_code_descript[] = {
69 "clock synchronized",
70 "insert leap second",
71 "delete leap second",
72 "leap second in progress",
73 "leap second has occurred",
74 "clock not synchronized" };
75
76#ifdef BB_VER
77#define main adjtimex_main
78#else
79void usage(char *prog)
80{
81 fprintf(stderr,
82 "Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n",
83 prog);
84}
85#define show_usage() usage(argv[0])
86#endif
87
88int main(int argc, char ** argv)
89{
90 struct timex txc;
91 int quiet=0;
92 int c, i, ret, sep;
93 char *descript;
94 txc.modes=0;
95 for (;;) {
96 c = getopt( argc, argv, "qo:f:p:t:");
97 if (c == EOF) break;
98 switch (c) {
99 case 'q':
100 quiet=1;
101 break;
102 case 'o':
103 txc.offset = atoi(optarg);
104 txc.modes |= ADJ_OFFSET_SINGLESHOT;
105 break;
106 case 'f':
107 txc.freq = atoi(optarg);
108 txc.modes |= ADJ_FREQUENCY;
109 break;
110 case 'p':
111 txc.constant = atoi(optarg);
112 txc.modes |= ADJ_TIMECONST;
113 break;
114 case 't':
115 txc.tick = atoi(optarg);
116 txc.modes |= ADJ_TICK;
117 break;
118 default:
119 show_usage();
120 exit(1);
121 }
122 }
123 if (argc != optind) { /* no valid non-option parameters */
124 show_usage();
125 exit(1);
126 }
127
128 ret = adjtimex(&txc);
129
130 if (ret < 0) perror("adjtimex");
131
132 if (!quiet && ret>=0) {
133 printf(
134 " mode: %d\n"
135 "-o offset: %ld\n"
136 "-f frequency: %ld\n"
137 " maxerror: %ld\n"
138 " esterror: %ld\n"
139 " status: %d ( ",
140 txc.modes, txc.offset, txc.freq, txc.maxerror,
141 txc.esterror, txc.status);
142
143 /* representative output of next code fragment:
144 "PLL | PPSTIME" */
145 sep=0;
146 for (i=0; statlist[i].name; i++) {
147 if (txc.status & statlist[i].bit) {
148 if (sep) fputs(" | ",stdout);
149 fputs(statlist[i].name,stdout);
150 sep=1;
151 }
152 }
153
154 descript = "error";
155 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
156 printf(" )\n"
157 "-p timeconstant: %ld\n"
158 " precision: %ld\n"
159 " tolerance: %ld\n"
160 "-t tick: %ld\n"
161 " time.tv_sec: %ld\n"
162 " time.tv_usec: %ld\n"
163 " return value: %d (%s)\n",
164 txc.constant,
165 txc.precision, txc.tolerance, txc.tick,
166 txc.time.tv_sec, txc.time.tv_usec, ret, descript);
167 }
168 return (ret<0);
169}
diff --git a/applets.h b/applets.h
index 8c59507ce..2af2b49e7 100644
--- a/applets.h
+++ b/applets.h
@@ -46,6 +46,9 @@
46#ifdef BB_TEST 46#ifdef BB_TEST
47 APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN) 47 APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
48#endif 48#endif
49#ifdef BB_ADJTIMEX
50 APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
51#endif
49#ifdef BB_AR 52#ifdef BB_AR
50 APPLET(ar, ar_main, _BB_DIR_USR_BIN) 53 APPLET(ar, ar_main, _BB_DIR_USR_BIN)
51#endif 54#endif
diff --git a/applets/usage.h b/applets/usage.h
index dc3b49816..8ec0170e2 100644
--- a/applets/usage.h
+++ b/applets/usage.h
@@ -1,3 +1,16 @@
1#define adjtimex_trivial_usage \
2 "[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]"
3#define adjtimex_full_usage \
4 "Reads and optionally sets system timebase parameters.\n" \
5 "See adjtimex(2).\n\n" \
6 "Options:\n" \
7 "\t-q\t\tquiet mode - do not print\n" \
8 "\t-o offset\ttime offset, microseconds\n" \
9 "\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \
10 "\t\t\t(positive values make the system clock run fast)\n" \
11 "\t-t tick\t\tmicroseconds per tick, usually 10000\n" \
12 "\t-p timeconstant\n"
13
1#define ar_trivial_usage \ 14#define ar_trivial_usage \
2 "-[ovR]{ptx} archive filenames" 15 "-[ovR]{ptx} archive filenames"
3#define ar_full_usage \ 16#define ar_full_usage \
diff --git a/include/applets.h b/include/applets.h
index 8c59507ce..2af2b49e7 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -46,6 +46,9 @@
46#ifdef BB_TEST 46#ifdef BB_TEST
47 APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN) 47 APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
48#endif 48#endif
49#ifdef BB_ADJTIMEX
50 APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
51#endif
49#ifdef BB_AR 52#ifdef BB_AR
50 APPLET(ar, ar_main, _BB_DIR_USR_BIN) 53 APPLET(ar, ar_main, _BB_DIR_USR_BIN)
51#endif 54#endif
diff --git a/include/usage.h b/include/usage.h
index dc3b49816..8ec0170e2 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1,3 +1,16 @@
1#define adjtimex_trivial_usage \
2 "[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]"
3#define adjtimex_full_usage \
4 "Reads and optionally sets system timebase parameters.\n" \
5 "See adjtimex(2).\n\n" \
6 "Options:\n" \
7 "\t-q\t\tquiet mode - do not print\n" \
8 "\t-o offset\ttime offset, microseconds\n" \
9 "\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \
10 "\t\t\t(positive values make the system clock run fast)\n" \
11 "\t-t tick\t\tmicroseconds per tick, usually 10000\n" \
12 "\t-p timeconstant\n"
13
1#define ar_trivial_usage \ 14#define ar_trivial_usage \
2 "-[ovR]{ptx} archive filenames" 15 "-[ovR]{ptx} archive filenames"
3#define ar_full_usage \ 16#define ar_full_usage \
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c
new file mode 100644
index 000000000..02b6e89b0
--- /dev/null
+++ b/miscutils/adjtimex.c
@@ -0,0 +1,169 @@
1/*
2 * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
3 *
4 * Originally written: October 1997
5 * Last hack: March 2001
6 * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
7 *
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
13 * reference.
14 *
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.
19 *
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.
29 *
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.
34 *
35 * This program is too simple for a Makefile, just build with:
36 * gcc -Wall -O adjtimex.c -o adjtimex
37 *
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.
41 */
42
43#include <stdio.h>
44#include <sys/types.h>
45#include <stdlib.h>
46#include <unistd.h>
47#include <sys/timex.h>
48#ifdef BB_VER
49#include "busybox.h"
50#endif
51
52static struct {int bit; char *name;} statlist[] = {
53 { STA_PLL, "PLL" },
54 { STA_PPSFREQ, "PPSFREQ" },
55 { STA_PPSTIME, "PPSTIME" },
56 { STA_FLL, "FFL" },
57 { STA_INS, "INS" },
58 { STA_DEL, "DEL" },
59 { STA_UNSYNC, "UNSYNC" },
60 { STA_FREQHOLD, "FREQHOLD" },
61 { STA_PPSSIGNAL, "PPSSIGNAL" },
62 { STA_PPSJITTER, "PPSJITTER" },
63 { STA_PPSWANDER, "PPSWANDER" },
64 { STA_PPSERROR, "PPSERROR" },
65 { STA_CLOCKERR, "CLOCKERR" },
66 { 0, NULL } };
67
68static char *ret_code_descript[] = {
69 "clock synchronized",
70 "insert leap second",
71 "delete leap second",
72 "leap second in progress",
73 "leap second has occurred",
74 "clock not synchronized" };
75
76#ifdef BB_VER
77#define main adjtimex_main
78#else
79void usage(char *prog)
80{
81 fprintf(stderr,
82 "Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n",
83 prog);
84}
85#define show_usage() usage(argv[0])
86#endif
87
88int main(int argc, char ** argv)
89{
90 struct timex txc;
91 int quiet=0;
92 int c, i, ret, sep;
93 char *descript;
94 txc.modes=0;
95 for (;;) {
96 c = getopt( argc, argv, "qo:f:p:t:");
97 if (c == EOF) break;
98 switch (c) {
99 case 'q':
100 quiet=1;
101 break;
102 case 'o':
103 txc.offset = atoi(optarg);
104 txc.modes |= ADJ_OFFSET_SINGLESHOT;
105 break;
106 case 'f':
107 txc.freq = atoi(optarg);
108 txc.modes |= ADJ_FREQUENCY;
109 break;
110 case 'p':
111 txc.constant = atoi(optarg);
112 txc.modes |= ADJ_TIMECONST;
113 break;
114 case 't':
115 txc.tick = atoi(optarg);
116 txc.modes |= ADJ_TICK;
117 break;
118 default:
119 show_usage();
120 exit(1);
121 }
122 }
123 if (argc != optind) { /* no valid non-option parameters */
124 show_usage();
125 exit(1);
126 }
127
128 ret = adjtimex(&txc);
129
130 if (ret < 0) perror("adjtimex");
131
132 if (!quiet && ret>=0) {
133 printf(
134 " mode: %d\n"
135 "-o offset: %ld\n"
136 "-f frequency: %ld\n"
137 " maxerror: %ld\n"
138 " esterror: %ld\n"
139 " status: %d ( ",
140 txc.modes, txc.offset, txc.freq, txc.maxerror,
141 txc.esterror, txc.status);
142
143 /* representative output of next code fragment:
144 "PLL | PPSTIME" */
145 sep=0;
146 for (i=0; statlist[i].name; i++) {
147 if (txc.status & statlist[i].bit) {
148 if (sep) fputs(" | ",stdout);
149 fputs(statlist[i].name,stdout);
150 sep=1;
151 }
152 }
153
154 descript = "error";
155 if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
156 printf(" )\n"
157 "-p timeconstant: %ld\n"
158 " precision: %ld\n"
159 " tolerance: %ld\n"
160 "-t tick: %ld\n"
161 " time.tv_sec: %ld\n"
162 " time.tv_usec: %ld\n"
163 " return value: %d (%s)\n",
164 txc.constant,
165 txc.precision, txc.tolerance, txc.tick,
166 txc.time.tv_sec, txc.time.tv_usec, ret, descript);
167 }
168 return (ret<0);
169}
diff --git a/usage.h b/usage.h
index dc3b49816..8ec0170e2 100644
--- a/usage.h
+++ b/usage.h
@@ -1,3 +1,16 @@
1#define adjtimex_trivial_usage \
2 "[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]"
3#define adjtimex_full_usage \
4 "Reads and optionally sets system timebase parameters.\n" \
5 "See adjtimex(2).\n\n" \
6 "Options:\n" \
7 "\t-q\t\tquiet mode - do not print\n" \
8 "\t-o offset\ttime offset, microseconds\n" \
9 "\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \
10 "\t\t\t(positive values make the system clock run fast)\n" \
11 "\t-t tick\t\tmicroseconds per tick, usually 10000\n" \
12 "\t-p timeconstant\n"
13
1#define ar_trivial_usage \ 14#define ar_trivial_usage \
2 "-[ovR]{ptx} archive filenames" 15 "-[ovR]{ptx} archive filenames"
3#define ar_full_usage \ 16#define ar_full_usage \