blob: 29f51021e813ece6c81205d5a357fa6678c190a1 [file] [log] [blame]
Robert Griebl1cd04452002-07-21 16:50:49 +00001/* vi: set sw=4 ts=4: */
2/*
Robert Griebl6859d762002-08-05 02:57:12 +00003 * Mini hwclock implementation for busybox
4 *
Robert Griebl1cd04452002-07-21 16:50:49 +00005 * Copyright (C) 2002 Robert Griebl <griebl@gmx.de>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Denys Vlasenkodd898c92016-11-23 11:46:32 +01008 */
9//config:config HWCLOCK
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020010//config: bool "hwclock (5.8 kb)"
Denys Vlasenkodd898c92016-11-23 11:46:32 +010011//config: default y
12//config: select PLATFORM_LINUX
13//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020014//config: The hwclock utility is used to read and set the hardware clock
15//config: on a system. This is primarily used to set the current time on
16//config: shutdown in the hardware clock, so the hardware will keep the
17//config: correct time when Linux is _not_ running.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010018//config:
Denys Vlasenkodd898c92016-11-23 11:46:32 +010019//config:config FEATURE_HWCLOCK_ADJTIME_FHS
20//config: bool "Use FHS /var/lib/hwclock/adjtime"
21//config: default n # util-linux-ng in Fedora 13 still uses /etc/adjtime
22//config: depends on HWCLOCK
23//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020024//config: Starting with FHS 2.3, the adjtime state file is supposed to exist
25//config: at /var/lib/hwclock/adjtime instead of /etc/adjtime. If you wish
26//config: to use the FHS behavior, answer Y here, otherwise answer N for the
27//config: classic /etc/adjtime path.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010028//config:
Denys Vlasenko72089cf2017-07-21 09:50:55 +020029//config: pathname.com/fhs/pub/fhs-2.3.html#VARLIBHWCLOCKSTATEDIRECTORYFORHWCLO
Denys Vlasenkodd898c92016-11-23 11:46:32 +010030
31//applet:IF_HWCLOCK(APPLET(hwclock, BB_DIR_SBIN, BB_SUID_DROP))
32
33//kbuild:lib-$(CONFIG_HWCLOCK) += hwclock.o
Robert Griebl1cd04452002-07-21 16:50:49 +000034
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000035#include "libbb.h"
Denys Vlasenko043b1e52009-09-06 12:47:55 +020036/* After libbb.h, since it needs sys/types.h on some systems */
37#include <sys/utsname.h>
Mike Frysinger6b160e42008-02-15 02:27:19 +000038#include "rtc_.h"
Eric Andersen8882ea52002-12-11 03:41:28 +000039
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010040/* diff code is disabled: it's not sys/hw clock diff, it's some useless
41 * "time between hwclock was started and we saw CMOS tick" quantity.
42 * It's useless since hwclock is started at a random moment,
43 * thus the quantity is also random, useless. Showing 0.000000 does not
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010044 * deprive us from any useful info.
45 *
46 * SHOW_HWCLOCK_DIFF code in this file shows the difference between system
47 * and hw clock. It is useful, but not compatible with standard hwclock.
48 * Thus disabled.
49 */
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010050#define SHOW_HWCLOCK_DIFF 0
51
52
53#if !SHOW_HWCLOCK_DIFF
54# define read_rtc(pp_rtcname, sys_tv, utc) read_rtc(pp_rtcname, utc)
55#endif
56static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
Denis Vlasenko92258542006-11-01 10:25:35 +000057{
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010058 struct tm tm_time;
Mike Frysinger6b160e42008-02-15 02:27:19 +000059 int fd;
Robert Griebl1cd04452002-07-21 16:50:49 +000060
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010061 fd = rtc_xopen(pp_rtcname, O_RDONLY);
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010062
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010063 rtc_read_tm(&tm_time, fd);
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010064
65#if SHOW_HWCLOCK_DIFF
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010066 {
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010067 int before = tm_time.tm_sec;
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010068 while (1) {
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010069 rtc_read_tm(&tm_time, fd);
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010070 gettimeofday(sys_tv, NULL);
Denys Vlasenkod778e6c2012-04-17 19:25:13 +020071 if (before != (int)tm_time.tm_sec)
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010072 break;
73 }
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010074 }
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010075#endif
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010076
Denys Vlasenko695fa512010-01-06 18:16:39 +010077 if (ENABLE_FEATURE_CLEAN_UP)
78 close(fd);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000079
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010080 return rtc_tm2time(&tm_time, utc);
Robert Griebl1cd04452002-07-21 16:50:49 +000081}
82
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010083static void show_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +000084{
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010085#if SHOW_HWCLOCK_DIFF
86 struct timeval sys_tv;
87#endif
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020088 time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
Robert Griebl1cd04452002-07-21 16:50:49 +000089
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020090#if ENABLE_LOCALE_SUPPORT
91 /* Standard hwclock uses locale-specific output format */
92 char cp[64];
93 struct tm *ptm = localtime(&t);
94 strftime(cp, sizeof(cp), "%c", ptm);
95#else
96 char *cp = ctime(&t);
Ron Yorston8ec1ff32015-03-12 20:18:51 +010097 chomp(cp);
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020098#endif
99
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100100#if !SHOW_HWCLOCK_DIFF
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100101 printf("%s 0.000000 seconds\n", cp);
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100102#else
103 {
104 long diff = sys_tv.tv_sec - t;
105 if (diff < 0 /*&& tv.tv_usec != 0*/) {
Denys Vlasenko319b8bb2011-07-08 06:40:25 +0200106 /* Why we need diff++? */
107 /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
108 /* 45.520820 | 43.520820 */
109 /* - 44.000000 | - 45.000000 */
110 /* = 1.520820 | = -1.479180, not -2.520820! */
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100111 diff++;
Denys Vlasenko319b8bb2011-07-08 06:40:25 +0200112 /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100113 sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
114 }
115 printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100116 }
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100117#endif
Robert Griebl1cd04452002-07-21 16:50:49 +0000118}
119
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100120static void to_sys_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +0000121{
Denis Vlasenko459be352007-06-17 19:09:05 +0000122 struct timeval tv;
Denys Vlasenko043b1e52009-09-06 12:47:55 +0200123 struct timezone tz;
124
Denys Vlasenko589051b2014-02-25 17:52:10 +0100125 tz.tz_minuteswest = timezone/60;
126 /* ^^^ used to also subtract 60*daylight, but it's wrong:
127 * daylight!=0 means "this timezone has some DST
128 * during the year", not "DST is in effect now".
129 */
Denys Vlasenko043b1e52009-09-06 12:47:55 +0200130 tz.tz_dsttime = 0;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000131
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100132 tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
Denis Vlasenko459be352007-06-17 19:09:05 +0000133 tv.tv_usec = 0;
Denis Vlasenko92258542006-11-01 10:25:35 +0000134 if (settimeofday(&tv, &tz))
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100135 bb_perror_msg_and_die("settimeofday");
Robert Griebl1cd04452002-07-21 16:50:49 +0000136}
137
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100138static void from_sys_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +0000139{
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700140#if 1
141 struct timeval tv;
142 struct tm tm_time;
143 int rtc;
144
145 rtc = rtc_xopen(pp_rtcname, O_WRONLY);
146 gettimeofday(&tv, NULL);
147 /* Prepare tm_time */
148 if (sizeof(time_t) == sizeof(tv.tv_sec)) {
149 if (utc)
150 gmtime_r((time_t*)&tv.tv_sec, &tm_time);
151 else
152 localtime_r((time_t*)&tv.tv_sec, &tm_time);
153 } else {
154 time_t t = tv.tv_sec;
155 if (utc)
156 gmtime_r(&t, &tm_time);
157 else
158 localtime_r(&t, &tm_time);
159 }
160#else
161/* Bloated code which tries to set hw clock with better precision.
162 * On x86, even though code does set hw clock within <1ms of exact
163 * whole seconds, apparently hw clock (at least on some machines)
164 * doesn't reset internal fractional seconds to 0,
Denys Vlasenko10ad6222017-04-17 16:13:32 +0200165 * making all this a pointless exercise.
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700166 */
167 /* If we see that we are N usec away from whole second,
168 * we'll sleep for N-ADJ usecs. ADJ corrects for the fact
169 * that CPU is not infinitely fast.
170 * On infinitely fast CPU, next wakeup would be
171 * on (exactly_next_whole_second - ADJ). On real CPUs,
172 * this difference between current time and whole second
173 * is less than ADJ (assuming system isn't heavily loaded).
174 */
175 /* Small value of 256us gives very precise sync for 2+ GHz CPUs.
176 * Slower CPUs will fail to sync and will go to bigger
177 * ADJ values. qemu-emulated armv4tl with ~100 MHz
178 * performance ends up using ADJ ~= 4*1024 and it takes
179 * 2+ secs (2 tries with successively larger ADJ)
180 * to sync. Even straced one on the same qemu (very slow)
181 * takes only 4 tries.
182 */
183#define TWEAK_USEC 256
184 unsigned adj = TWEAK_USEC;
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100185 struct tm tm_time;
Denis Vlasenko459be352007-06-17 19:09:05 +0000186 struct timeval tv;
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100187 int rtc = rtc_xopen(pp_rtcname, O_WRONLY);
Robert Griebl1cd04452002-07-21 16:50:49 +0000188
Denys Vlasenko695fa512010-01-06 18:16:39 +0100189 /* Try to catch the moment when whole second is close */
190 while (1) {
191 unsigned rem_usec;
192 time_t t;
193
194 gettimeofday(&tv, NULL);
195
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100196 t = tv.tv_sec;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100197 rem_usec = 1000000 - tv.tv_usec;
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700198 if (rem_usec < adj) {
199 /* Close enough */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100200 small_rem:
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100201 t++;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100202 }
203
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700204 /* Prepare tm_time from t */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100205 if (utc)
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100206 gmtime_r(&t, &tm_time); /* may read /etc/xxx (it takes time) */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100207 else
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100208 localtime_r(&t, &tm_time); /* same */
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700209
210 if (adj >= 32*1024) {
211 break; /* 32 ms diff and still no luck?? give up trying to sync */
212 }
Denys Vlasenko695fa512010-01-06 18:16:39 +0100213
214 /* gmtime/localtime took some time, re-get cur time */
215 gettimeofday(&tv, NULL);
216
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700217 if (tv.tv_sec < t /* we are still in old second */
218 || (tv.tv_sec == t && tv.tv_usec < adj) /* not too far into next second */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100219 ) {
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700220 break; /* good, we are in sync! */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100221 }
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700222
223 rem_usec = 1000000 - tv.tv_usec;
224 if (rem_usec < adj) {
225 t = tv.tv_sec;
226 goto small_rem; /* already close to next sec, don't sleep */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100227 }
228
229 /* Try to sync up by sleeping */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100230 usleep(rem_usec - adj);
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700231
232 /* Jump to 1ms diff, then increase fast (x2): EVERY loop
233 * takes ~1 sec, people won't like slowly converging code here!
234 */
235 //bb_error_msg("adj:%d tv.tv_usec:%d", adj, (int)tv.tv_usec);
236 if (adj < 512)
237 adj = 512;
238 /* ... and if last "overshoot" does not look insanely big,
239 * just use it as adj increment. This makes convergence faster.
240 */
241 if (tv.tv_usec < adj * 8) {
242 adj += tv.tv_usec;
243 continue;
244 }
245 adj *= 2;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100246 }
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700247 /* Debug aid to find "optimal" TWEAK_USEC with nearly exact sync.
Denys Vlasenko695fa512010-01-06 18:16:39 +0100248 * Look for a value which makes tv_usec close to 999999 or 0.
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700249 * For 2.20GHz Intel Core 2: optimal TWEAK_USEC ~= 200
Denys Vlasenko695fa512010-01-06 18:16:39 +0100250 */
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700251 //bb_error_msg("tv.tv_usec:%d", (int)tv.tv_usec);
252#endif
253
254 tm_time.tm_isdst = 0;
255 xioctl(rtc, RTC_SET_TIME, &tm_time);
Denys Vlasenko695fa512010-01-06 18:16:39 +0100256
257 if (ENABLE_FEATURE_CLEAN_UP)
258 close(rtc);
Robert Griebl1cd04452002-07-21 16:50:49 +0000259}
260
Davide Cavalca658a4372011-01-22 18:55:32 +0100261/*
262 * At system boot, kernel may set system time from RTC,
263 * but it knows nothing about timezones. If RTC is in local time,
264 * then system time is wrong - it is offset by timezone.
265 * This option corrects system time if RTC is in local time,
266 * and (always) sets in-kernel timezone.
267 *
268 * This is an alternate option to --hctosys that does not read the
269 * hardware clock.
270 */
271static void set_system_clock_timezone(int utc)
272{
273 struct timeval tv;
274 struct tm *broken;
275 struct timezone tz;
276
277 gettimeofday(&tv, NULL);
278 broken = localtime(&tv.tv_sec);
279 tz.tz_minuteswest = timezone / 60;
Denys Vlasenko589051b2014-02-25 17:52:10 +0100280 if (broken->tm_isdst > 0)
Davide Cavalca658a4372011-01-22 18:55:32 +0100281 tz.tz_minuteswest -= 60;
282 tz.tz_dsttime = 0;
283 gettimeofday(&tv, NULL);
284 if (!utc)
285 tv.tv_sec += tz.tz_minuteswest * 60;
286 if (settimeofday(&tv, &tz))
287 bb_perror_msg_and_die("settimeofday");
288}
289
290//usage:#define hwclock_trivial_usage
Denys Vlasenko036585a2017-08-08 16:38:18 +0200291//usage: IF_LONG_OPTS(
292//usage: "[-r|--show] [-s|--hctosys] [-w|--systohc] [--systz]"
293//usage: " [--localtime] [-u|--utc]"
Davide Cavalca658a4372011-01-22 18:55:32 +0100294//usage: " [-f|--rtc FILE]"
295//usage: )
Denys Vlasenko036585a2017-08-08 16:38:18 +0200296//usage: IF_NOT_LONG_OPTS(
Davide Cavalca658a4372011-01-22 18:55:32 +0100297//usage: "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]"
298//usage: )
299//usage:#define hwclock_full_usage "\n\n"
300//usage: "Query and set hardware clock (RTC)\n"
Davide Cavalca658a4372011-01-22 18:55:32 +0100301//usage: "\n -r Show hardware clock time"
302//usage: "\n -s Set system time from hardware clock"
303//usage: "\n -w Set hardware clock from system time"
Denys Vlasenko036585a2017-08-08 16:38:18 +0200304//usage: IF_LONG_OPTS(
305//usage: "\n --systz Set in-kernel timezone, correct system time"
306//usage: )
Davide Cavalca658a4372011-01-22 18:55:32 +0100307//usage: "\n if hardware clock is in local time"
Denys Vlasenko46465ec2011-07-04 04:34:57 +0200308//usage: "\n -u Assume hardware clock is kept in UTC"
Denys Vlasenko036585a2017-08-08 16:38:18 +0200309//usage: IF_LONG_OPTS(
310//usage: "\n --localtime Assume hardware clock is kept in local time"
311//usage: )
Davide Cavalca658a4372011-01-22 18:55:32 +0100312//usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)"
313
Denys Vlasenko036585a2017-08-08 16:38:18 +0200314//TODO: get rid of incompatible -t and -l aliases to --systz and --localtime
315
Denis Vlasenko92258542006-11-01 10:25:35 +0000316#define HWCLOCK_OPT_LOCALTIME 0x01
317#define HWCLOCK_OPT_UTC 0x02
318#define HWCLOCK_OPT_SHOW 0x04
319#define HWCLOCK_OPT_HCTOSYS 0x08
320#define HWCLOCK_OPT_SYSTOHC 0x10
Davide Cavalca658a4372011-01-22 18:55:32 +0100321#define HWCLOCK_OPT_SYSTZ 0x20
322#define HWCLOCK_OPT_RTCFILE 0x40
Glenn L McGrath689e4b92004-02-22 09:11:33 +0000323
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000324int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000325int hwclock_main(int argc UNUSED_PARAM, char **argv)
Robert Griebl1cd04452002-07-21 16:50:49 +0000326{
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100327 const char *rtcname = NULL;
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000328 unsigned opt;
Robert Griebl6bb80872004-03-22 21:27:39 +0000329 int utc;
Robert Griebl1cd04452002-07-21 16:50:49 +0000330
Denys Vlasenko036585a2017-08-08 16:38:18 +0200331#if ENABLE_LONG_OPTS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000332 static const char hwclock_longopts[] ALIGN1 =
Davide Cavalca658a4372011-01-22 18:55:32 +0100333 "localtime\0" No_argument "l" /* short opt is non-standard */
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000334 "utc\0" No_argument "u"
335 "show\0" No_argument "r"
336 "hctosys\0" No_argument "s"
337 "systohc\0" No_argument "w"
Davide Cavalca658a4372011-01-22 18:55:32 +0100338 "systz\0" No_argument "t" /* short opt is non-standard */
339 "rtc\0" Required_argument "f"
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000340 ;
Robert Griebl1cd04452002-07-21 16:50:49 +0000341#endif
Denys Vlasenko589051b2014-02-25 17:52:10 +0100342
343 /* Initialize "timezone" (libc global variable) */
344 tzset();
345
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200346 opt = getopt32long(argv,
347 "^lurswtf:" "\0" "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l",
348 hwclock_longopts,
349 &rtcname
350 );
Robert Griebl1cd04452002-07-21 16:50:49 +0000351
Robert Griebl6bb80872004-03-22 21:27:39 +0000352 /* If -u or -l wasn't given check if we are using utc */
Mike Frysingerb31566e2005-04-16 04:48:48 +0000353 if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME))
Mike Frysinger6b160e42008-02-15 02:27:19 +0000354 utc = (opt & HWCLOCK_OPT_UTC);
Robert Griebl6bb80872004-03-22 21:27:39 +0000355 else
Mike Frysinger6b160e42008-02-15 02:27:19 +0000356 utc = rtc_adjtime_is_utc();
Mike Frysingerb31566e2005-04-16 04:48:48 +0000357
Mike Frysinger6b160e42008-02-15 02:27:19 +0000358 if (opt & HWCLOCK_OPT_HCTOSYS)
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100359 to_sys_clock(&rtcname, utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000360 else if (opt & HWCLOCK_OPT_SYSTOHC)
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100361 from_sys_clock(&rtcname, utc);
Davide Cavalca658a4372011-01-22 18:55:32 +0100362 else if (opt & HWCLOCK_OPT_SYSTZ)
363 set_system_clock_timezone(utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000364 else
365 /* default HWCLOCK_OPT_SHOW */
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100366 show_clock(&rtcname, utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000367
Denis Vlasenko459be352007-06-17 19:09:05 +0000368 return 0;
Robert Griebl1cd04452002-07-21 16:50:49 +0000369}