diff options
Diffstat (limited to 'miscutils/adjtimex.c')
-rw-r--r-- | miscutils/adjtimex.c | 98 |
1 files changed, 60 insertions, 38 deletions
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 67dd0a93b..07f083428 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c | |||
@@ -14,34 +14,46 @@ | |||
14 | #include "libbb.h" | 14 | #include "libbb.h" |
15 | #include <sys/timex.h> | 15 | #include <sys/timex.h> |
16 | 16 | ||
17 | static const struct { | 17 | static const uint16_t statlist_bit[] = { |
18 | int bit; | 18 | STA_PLL, |
19 | const char *name; | 19 | STA_PPSFREQ, |
20 | } statlist[] = { | 20 | STA_PPSTIME, |
21 | { STA_PLL, "PLL" }, | 21 | STA_FLL, |
22 | { STA_PPSFREQ, "PPSFREQ" }, | 22 | STA_INS, |
23 | { STA_PPSTIME, "PPSTIME" }, | 23 | STA_DEL, |
24 | { STA_FLL, "FFL" }, | 24 | STA_UNSYNC, |
25 | { STA_INS, "INS" }, | 25 | STA_FREQHOLD, |
26 | { STA_DEL, "DEL" }, | 26 | STA_PPSSIGNAL, |
27 | { STA_UNSYNC, "UNSYNC" }, | 27 | STA_PPSJITTER, |
28 | { STA_FREQHOLD, "FREQHOLD" }, | 28 | STA_PPSWANDER, |
29 | { STA_PPSSIGNAL, "PPSSIGNAL" }, | 29 | STA_PPSERROR, |
30 | { STA_PPSJITTER, "PPSJITTER" }, | 30 | STA_CLOCKERR, |
31 | { STA_PPSWANDER, "PPSWANDER" }, | 31 | 0 |
32 | { STA_PPSERROR, "PPSERROR" }, | ||
33 | { STA_CLOCKERR, "CLOCKERR" }, | ||
34 | { 0, NULL } | ||
35 | }; | 32 | }; |
33 | static const char statlist_name[] = | ||
34 | "PLL" "\0" | ||
35 | "PPSFREQ" "\0" | ||
36 | "PPSTIME" "\0" | ||
37 | "FFL" "\0" | ||
38 | "INS" "\0" | ||
39 | "DEL" "\0" | ||
40 | "UNSYNC" "\0" | ||
41 | "FREQHOLD" "\0" | ||
42 | "PPSSIGNAL" "\0" | ||
43 | "PPSJITTER" "\0" | ||
44 | "PPSWANDER" "\0" | ||
45 | "PPSERROR" "\0" | ||
46 | "CLOCKERR" | ||
47 | ; | ||
36 | 48 | ||
37 | static const char *const ret_code_descript[] = { | 49 | static const char ret_code_descript[] = |
38 | "clock synchronized", | 50 | "clock synchronized" "\0" |
39 | "insert leap second", | 51 | "insert leap second" "\0" |
40 | "delete leap second", | 52 | "delete leap second" "\0" |
41 | "leap second in progress", | 53 | "leap second in progress" "\0" |
42 | "leap second has occurred", | 54 | "leap second has occurred" "\0" |
43 | "clock not synchronized" | 55 | "clock not synchronized" |
44 | }; | 56 | ; |
45 | 57 | ||
46 | int adjtimex_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 58 | int adjtimex_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
47 | int adjtimex_main(int argc, char **argv) | 59 | int adjtimex_main(int argc, char **argv) |
@@ -52,7 +64,7 @@ int adjtimex_main(int argc, char **argv) | |||
52 | unsigned opt; | 64 | unsigned opt; |
53 | char *opt_o, *opt_f, *opt_p, *opt_t; | 65 | char *opt_o, *opt_f, *opt_p, *opt_t; |
54 | struct timex txc; | 66 | struct timex txc; |
55 | int i, ret, sep; | 67 | int i, ret; |
56 | const char *descript; | 68 | const char *descript; |
57 | txc.modes=0; | 69 | txc.modes=0; |
58 | 70 | ||
@@ -81,33 +93,42 @@ int adjtimex_main(int argc, char **argv) | |||
81 | 93 | ||
82 | ret = adjtimex(&txc); | 94 | ret = adjtimex(&txc); |
83 | 95 | ||
84 | if (ret < 0) perror("adjtimex"); | 96 | if (ret < 0) { |
97 | bb_perror_nomsg_and_die(); | ||
98 | } | ||
99 | |||
100 | if (!(opt & OPT_quiet)) { | ||
101 | int sep; | ||
102 | const char *name; | ||
85 | 103 | ||
86 | if (!(opt & OPT_quiet) && ret>=0) { | ||
87 | printf( | 104 | printf( |
88 | " mode: %d\n" | 105 | " mode: %d\n" |
89 | "-o offset: %ld\n" | 106 | "-o offset: %ld\n" |
90 | "-f frequency: %ld\n" | 107 | "-f frequency: %ld\n" |
91 | " maxerror: %ld\n" | 108 | " maxerror: %ld\n" |
92 | " esterror: %ld\n" | 109 | " esterror: %ld\n" |
93 | " status: %d ( ", | 110 | " status: %d (", |
94 | txc.modes, txc.offset, txc.freq, txc.maxerror, | 111 | txc.modes, txc.offset, txc.freq, txc.maxerror, |
95 | txc.esterror, txc.status); | 112 | txc.esterror, txc.status); |
96 | 113 | ||
97 | /* representative output of next code fragment: | 114 | /* representative output of next code fragment: |
98 | "PLL | PPSTIME" */ | 115 | "PLL | PPSTIME" */ |
99 | sep=0; | 116 | name = statlist_name; |
100 | for (i=0; statlist[i].name; i++) { | 117 | sep = 0; |
101 | if (txc.status & statlist[i].bit) { | 118 | for (i = 0; statlist_bit[i]; i++) { |
102 | if (sep) fputs(" | ",stdout); | 119 | if (txc.status & statlist_bit[i]) { |
103 | fputs(statlist[i].name,stdout); | 120 | if (sep) |
104 | sep=1; | 121 | fputs(" | ", stdout); |
122 | fputs(name, stdout); | ||
123 | sep = 1; | ||
105 | } | 124 | } |
125 | name += strlen(name) + 1; | ||
106 | } | 126 | } |
107 | 127 | ||
108 | descript = "error"; | 128 | descript = "error"; |
109 | if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret]; | 129 | if (ret <= 5) |
110 | printf(" )\n" | 130 | descript = nth_string(ret_code_descript, ret); |
131 | printf(")\n" | ||
111 | "-p timeconstant: %ld\n" | 132 | "-p timeconstant: %ld\n" |
112 | " precision: %ld\n" | 133 | " precision: %ld\n" |
113 | " tolerance: %ld\n" | 134 | " tolerance: %ld\n" |
@@ -119,5 +140,6 @@ int adjtimex_main(int argc, char **argv) | |||
119 | txc.precision, txc.tolerance, txc.tick, | 140 | txc.precision, txc.tolerance, txc.tick, |
120 | (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript); | 141 | (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript); |
121 | } | 142 | } |
122 | return (ret<0); | 143 | |
144 | return 0; | ||
123 | } | 145 | } |