diff options
Diffstat (limited to 'miscutils/adjtimex.c')
-rw-r--r-- | miscutils/adjtimex.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 04ba5636f..c1718e909 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables. | 3 | * adjtimex.c - read, and possibly modify, the Linux kernel 'timex' variables. |
4 | * | 4 | * |
5 | * Originally written: October 1997 | 5 | * Originally written: October 1997 |
6 | * Last hack: March 2001 | 6 | * Last hack: March 2001 |
@@ -18,7 +18,7 @@ | |||
18 | //config: Adjtimex reads and optionally sets adjustment parameters for | 18 | //config: Adjtimex reads and optionally sets adjustment parameters for |
19 | //config: the Linux clock adjustment algorithm. | 19 | //config: the Linux clock adjustment algorithm. |
20 | 20 | ||
21 | //applet:IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) | 21 | //applet:IF_ADJTIMEX(APPLET_NOFORK(adjtimex, adjtimex, BB_DIR_SBIN, BB_SUID_DROP, adjtimex)) |
22 | 22 | ||
23 | //kbuild:lib-$(CONFIG_ADJTIMEX) += adjtimex.o | 23 | //kbuild:lib-$(CONFIG_ADJTIMEX) += adjtimex.o |
24 | 24 | ||
@@ -90,13 +90,15 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv) | |||
90 | unsigned opt; | 90 | unsigned opt; |
91 | char *opt_o, *opt_f, *opt_p, *opt_t; | 91 | char *opt_o, *opt_f, *opt_p, *opt_t; |
92 | struct timex txc; | 92 | struct timex txc; |
93 | int i, ret; | 93 | int ret; |
94 | const char *descript; | 94 | const char *descript; |
95 | 95 | ||
96 | opt_complementary = "=0"; /* no valid non-option parameters */ | 96 | memset(&txc, 0, sizeof(txc)); |
97 | opt = getopt32(argv, "qo:f:p:t:", | 97 | |
98 | &opt_o, &opt_f, &opt_p, &opt_t); | 98 | opt = getopt32(argv, "^" "qo:f:p:t:" |
99 | txc.modes = 0; | 99 | "\0" "=0"/*no valid non-option args*/, |
100 | &opt_o, &opt_f, &opt_p, &opt_t | ||
101 | ); | ||
100 | //if (opt & 0x1) // -q | 102 | //if (opt & 0x1) // -q |
101 | if (opt & 0x2) { // -o | 103 | if (opt & 0x2) { // -o |
102 | txc.offset = xatol(opt_o); | 104 | txc.offset = xatol(opt_o); |
@@ -115,15 +117,19 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv) | |||
115 | txc.modes |= ADJ_TICK; | 117 | txc.modes |= ADJ_TICK; |
116 | } | 118 | } |
117 | 119 | ||
118 | ret = adjtimex(&txc); | 120 | /* It's NOFORK applet because the code is very simple: |
121 | * just some printf. No opens, no allocs. | ||
122 | * If you need to make it more complex, feel free to downgrade to NOEXEC | ||
123 | */ | ||
119 | 124 | ||
120 | if (ret < 0) { | 125 | ret = adjtimex(&txc); |
126 | if (ret < 0) | ||
121 | bb_perror_nomsg_and_die(); | 127 | bb_perror_nomsg_and_die(); |
122 | } | ||
123 | 128 | ||
124 | if (!(opt & OPT_quiet)) { | 129 | if (!(opt & OPT_quiet)) { |
125 | const char *sep; | 130 | const char *sep; |
126 | const char *name; | 131 | const char *name; |
132 | int i; | ||
127 | 133 | ||
128 | printf( | 134 | printf( |
129 | " mode: %d\n" | 135 | " mode: %d\n" |
@@ -132,8 +138,9 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv) | |||
132 | " maxerror: %ld\n" | 138 | " maxerror: %ld\n" |
133 | " esterror: %ld\n" | 139 | " esterror: %ld\n" |
134 | " status: %d (", | 140 | " status: %d (", |
135 | txc.modes, txc.offset, txc.freq, txc.maxerror, | 141 | txc.modes, txc.offset, txc.freq, txc.maxerror, |
136 | txc.esterror, txc.status); | 142 | txc.esterror, txc.status |
143 | ); | ||
137 | 144 | ||
138 | /* representative output of next code fragment: | 145 | /* representative output of next code fragment: |
139 | * "PLL | PPSTIME" | 146 | * "PLL | PPSTIME" |
@@ -159,9 +166,11 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv) | |||
159 | " time.tv_sec: %ld\n" | 166 | " time.tv_sec: %ld\n" |
160 | " time.tv_usec: %ld\n" | 167 | " time.tv_usec: %ld\n" |
161 | " return value: %d (%s)\n", | 168 | " return value: %d (%s)\n", |
162 | txc.constant, | 169 | txc.constant, |
163 | txc.precision, txc.tolerance, txc.tick, | 170 | txc.precision, txc.tolerance, txc.tick, |
164 | (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript); | 171 | (long)txc.time.tv_sec, (long)txc.time.tv_usec, |
172 | ret, descript | ||
173 | ); | ||
165 | } | 174 | } |
166 | 175 | ||
167 | return 0; | 176 | return 0; |