diff options
author | Davide Cavalca <davide@geexbox.org> | 2011-01-22 18:55:32 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-22 18:55:32 +0100 |
commit | 658a437d4bd97d4897a9d0183570634a90ae6773 (patch) | |
tree | fcee9bf4c7dcdcfe32f563d7c1f5137ca372a354 /util-linux/hwclock.c | |
parent | 1336f89d59fc571ef19f3cb74ced0580b3331a96 (diff) | |
download | busybox-w32-658a437d4bd97d4897a9d0183570634a90ae6773.tar.gz busybox-w32-658a437d4bd97d4897a9d0183570634a90ae6773.tar.bz2 busybox-w32-658a437d4bd97d4897a9d0183570634a90ae6773.zip |
hwclock: implement --systz
function old new delta
hwclock_main 324 434 +110
packed_usage 28220 28259 +39
static.hwclock_longopts 53 60 +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 156/0) Total: 156 bytes
Signed-off-by: Davide Cavalca <davide@geexbox.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/hwclock.c')
-rw-r--r-- | util-linux/hwclock.c | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 922dd0578..54e97e5bb 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -223,12 +223,63 @@ static void from_sys_clock(const char **pp_rtcname, int utc) | |||
223 | close(rtc); | 223 | close(rtc); |
224 | } | 224 | } |
225 | 225 | ||
226 | /* | ||
227 | * At system boot, kernel may set system time from RTC, | ||
228 | * but it knows nothing about timezones. If RTC is in local time, | ||
229 | * then system time is wrong - it is offset by timezone. | ||
230 | * This option corrects system time if RTC is in local time, | ||
231 | * and (always) sets in-kernel timezone. | ||
232 | * | ||
233 | * This is an alternate option to --hctosys that does not read the | ||
234 | * hardware clock. | ||
235 | */ | ||
236 | static void set_system_clock_timezone(int utc) | ||
237 | { | ||
238 | struct timeval tv; | ||
239 | struct tm *broken; | ||
240 | struct timezone tz; | ||
241 | |||
242 | gettimeofday(&tv, NULL); | ||
243 | broken = localtime(&tv.tv_sec); | ||
244 | tz.tz_minuteswest = timezone / 60; | ||
245 | if (broken->tm_isdst) | ||
246 | tz.tz_minuteswest -= 60; | ||
247 | tz.tz_dsttime = 0; | ||
248 | gettimeofday(&tv, NULL); | ||
249 | if (!utc) | ||
250 | tv.tv_sec += tz.tz_minuteswest * 60; | ||
251 | if (settimeofday(&tv, &tz)) | ||
252 | bb_perror_msg_and_die("settimeofday"); | ||
253 | } | ||
254 | |||
255 | //usage:#define hwclock_trivial_usage | ||
256 | //usage: IF_FEATURE_HWCLOCK_LONG_OPTIONS( | ||
257 | //usage: "[-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz]" | ||
258 | //usage: " [-l|--localtime] [-u|--utc]" | ||
259 | //usage: " [-f|--rtc FILE]" | ||
260 | //usage: ) | ||
261 | //usage: IF_NOT_FEATURE_HWCLOCK_LONG_OPTIONS( | ||
262 | //usage: "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]" | ||
263 | //usage: ) | ||
264 | //usage:#define hwclock_full_usage "\n\n" | ||
265 | //usage: "Query and set hardware clock (RTC)\n" | ||
266 | //usage: "\nOptions:" | ||
267 | //usage: "\n -r Show hardware clock time" | ||
268 | //usage: "\n -s Set system time from hardware clock" | ||
269 | //usage: "\n -w Set hardware clock from system time" | ||
270 | //usage: "\n -t Set in-kernel timezone, correct system time" | ||
271 | //usage: "\n if hardware clock is in local time" | ||
272 | //usage: "\n -u Hardware clock is in UTC" | ||
273 | //usage: "\n -l Hardware clock is in local time" | ||
274 | //usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)" | ||
275 | |||
226 | #define HWCLOCK_OPT_LOCALTIME 0x01 | 276 | #define HWCLOCK_OPT_LOCALTIME 0x01 |
227 | #define HWCLOCK_OPT_UTC 0x02 | 277 | #define HWCLOCK_OPT_UTC 0x02 |
228 | #define HWCLOCK_OPT_SHOW 0x04 | 278 | #define HWCLOCK_OPT_SHOW 0x04 |
229 | #define HWCLOCK_OPT_HCTOSYS 0x08 | 279 | #define HWCLOCK_OPT_HCTOSYS 0x08 |
230 | #define HWCLOCK_OPT_SYSTOHC 0x10 | 280 | #define HWCLOCK_OPT_SYSTOHC 0x10 |
231 | #define HWCLOCK_OPT_RTCFILE 0x20 | 281 | #define HWCLOCK_OPT_SYSTZ 0x20 |
282 | #define HWCLOCK_OPT_RTCFILE 0x40 | ||
232 | 283 | ||
233 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 284 | int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
234 | int hwclock_main(int argc UNUSED_PARAM, char **argv) | 285 | int hwclock_main(int argc UNUSED_PARAM, char **argv) |
@@ -239,17 +290,18 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv) | |||
239 | 290 | ||
240 | #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS | 291 | #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS |
241 | static const char hwclock_longopts[] ALIGN1 = | 292 | static const char hwclock_longopts[] ALIGN1 = |
242 | "localtime\0" No_argument "l" | 293 | "localtime\0" No_argument "l" /* short opt is non-standard */ |
243 | "utc\0" No_argument "u" | 294 | "utc\0" No_argument "u" |
244 | "show\0" No_argument "r" | 295 | "show\0" No_argument "r" |
245 | "hctosys\0" No_argument "s" | 296 | "hctosys\0" No_argument "s" |
246 | "systohc\0" No_argument "w" | 297 | "systohc\0" No_argument "w" |
247 | "file\0" Required_argument "f" | 298 | "systz\0" No_argument "t" /* short opt is non-standard */ |
299 | "rtc\0" Required_argument "f" | ||
248 | ; | 300 | ; |
249 | applet_long_options = hwclock_longopts; | 301 | applet_long_options = hwclock_longopts; |
250 | #endif | 302 | #endif |
251 | opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l"; | 303 | opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l"; |
252 | opt = getopt32(argv, "lurswf:", &rtcname); | 304 | opt = getopt32(argv, "lurswtf:", &rtcname); |
253 | 305 | ||
254 | /* If -u or -l wasn't given check if we are using utc */ | 306 | /* If -u or -l wasn't given check if we are using utc */ |
255 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) | 307 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) |
@@ -261,6 +313,8 @@ int hwclock_main(int argc UNUSED_PARAM, char **argv) | |||
261 | to_sys_clock(&rtcname, utc); | 313 | to_sys_clock(&rtcname, utc); |
262 | else if (opt & HWCLOCK_OPT_SYSTOHC) | 314 | else if (opt & HWCLOCK_OPT_SYSTOHC) |
263 | from_sys_clock(&rtcname, utc); | 315 | from_sys_clock(&rtcname, utc); |
316 | else if (opt & HWCLOCK_OPT_SYSTZ) | ||
317 | set_system_clock_timezone(utc); | ||
264 | else | 318 | else |
265 | /* default HWCLOCK_OPT_SHOW */ | 319 | /* default HWCLOCK_OPT_SHOW */ |
266 | show_clock(&rtcname, utc); | 320 | show_clock(&rtcname, utc); |