blob: 791525fc2607782af357d3cb2c1313673527df70 [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
Denys Vlasenkodd898c92016-11-23 11:46:32 +010012//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: The hwclock utility is used to read and set the hardware clock
14//config: on a system. This is primarily used to set the current time on
15//config: shutdown in the hardware clock, so the hardware will keep the
16//config: correct time when Linux is _not_ running.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010017//config:
Denys Vlasenkodd898c92016-11-23 11:46:32 +010018//config:config FEATURE_HWCLOCK_ADJTIME_FHS
19//config: bool "Use FHS /var/lib/hwclock/adjtime"
20//config: default n # util-linux-ng in Fedora 13 still uses /etc/adjtime
21//config: depends on HWCLOCK
22//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020023//config: Starting with FHS 2.3, the adjtime state file is supposed to exist
24//config: at /var/lib/hwclock/adjtime instead of /etc/adjtime. If you wish
25//config: to use the FHS behavior, answer Y here, otherwise answer N for the
26//config: classic /etc/adjtime path.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010027//config:
Denys Vlasenko72089cf2017-07-21 09:50:55 +020028//config: pathname.com/fhs/pub/fhs-2.3.html#VARLIBHWCLOCKSTATEDIRECTORYFORHWCLO
Denys Vlasenkodd898c92016-11-23 11:46:32 +010029
30//applet:IF_HWCLOCK(APPLET(hwclock, BB_DIR_SBIN, BB_SUID_DROP))
31
32//kbuild:lib-$(CONFIG_HWCLOCK) += hwclock.o
Robert Griebl1cd04452002-07-21 16:50:49 +000033
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000034#include "libbb.h"
Denys Vlasenko043b1e52009-09-06 12:47:55 +020035/* After libbb.h, since it needs sys/types.h on some systems */
36#include <sys/utsname.h>
Mike Frysinger6b160e42008-02-15 02:27:19 +000037#include "rtc_.h"
Eric Andersen8882ea52002-12-11 03:41:28 +000038
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010039/* diff code is disabled: it's not sys/hw clock diff, it's some useless
40 * "time between hwclock was started and we saw CMOS tick" quantity.
41 * It's useless since hwclock is started at a random moment,
42 * thus the quantity is also random, useless. Showing 0.000000 does not
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010043 * deprive us from any useful info.
44 *
45 * SHOW_HWCLOCK_DIFF code in this file shows the difference between system
46 * and hw clock. It is useful, but not compatible with standard hwclock.
47 * Thus disabled.
48 */
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010049#define SHOW_HWCLOCK_DIFF 0
50
51
52#if !SHOW_HWCLOCK_DIFF
53# define read_rtc(pp_rtcname, sys_tv, utc) read_rtc(pp_rtcname, utc)
54#endif
55static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
Denis Vlasenko92258542006-11-01 10:25:35 +000056{
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010057 struct tm tm_time;
Mike Frysinger6b160e42008-02-15 02:27:19 +000058 int fd;
Robert Griebl1cd04452002-07-21 16:50:49 +000059
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010060 fd = rtc_xopen(pp_rtcname, O_RDONLY);
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010061
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010062 rtc_read_tm(&tm_time, fd);
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010063
64#if SHOW_HWCLOCK_DIFF
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010065 {
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010066 int before = tm_time.tm_sec;
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010067 while (1) {
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010068 rtc_read_tm(&tm_time, fd);
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010069 gettimeofday(sys_tv, NULL);
Denys Vlasenkod778e6c2012-04-17 19:25:13 +020070 if (before != (int)tm_time.tm_sec)
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010071 break;
72 }
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010073 }
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010074#endif
Denys Vlasenko5e3b1402010-01-06 22:43:39 +010075
Denys Vlasenko695fa512010-01-06 18:16:39 +010076 if (ENABLE_FEATURE_CLEAN_UP)
77 close(fd);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000078
Denys Vlasenkodc698bb2010-01-09 19:10:49 +010079 return rtc_tm2time(&tm_time, utc);
Robert Griebl1cd04452002-07-21 16:50:49 +000080}
81
Denys Vlasenko6959f6b2010-01-07 08:31:46 +010082static void show_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +000083{
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010084#if SHOW_HWCLOCK_DIFF
85 struct timeval sys_tv;
86#endif
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020087 time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
Robert Griebl1cd04452002-07-21 16:50:49 +000088
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020089#if ENABLE_LOCALE_SUPPORT
90 /* Standard hwclock uses locale-specific output format */
91 char cp[64];
92 struct tm *ptm = localtime(&t);
93 strftime(cp, sizeof(cp), "%c", ptm);
94#else
95 char *cp = ctime(&t);
Ron Yorston8ec1ff32015-03-12 20:18:51 +010096 chomp(cp);
Denys Vlasenko319b8bb2011-07-08 06:40:25 +020097#endif
98
Denys Vlasenko0c58cc72010-01-07 10:36:41 +010099#if !SHOW_HWCLOCK_DIFF
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100100 printf("%s 0.000000 seconds\n", cp);
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100101#else
102 {
103 long diff = sys_tv.tv_sec - t;
104 if (diff < 0 /*&& tv.tv_usec != 0*/) {
Denys Vlasenko319b8bb2011-07-08 06:40:25 +0200105 /* Why we need diff++? */
106 /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
107 /* 45.520820 | 43.520820 */
108 /* - 44.000000 | - 45.000000 */
109 /* = 1.520820 | = -1.479180, not -2.520820! */
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100110 diff++;
Denys Vlasenko319b8bb2011-07-08 06:40:25 +0200111 /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
Denys Vlasenko0c58cc72010-01-07 10:36:41 +0100112 sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
113 }
114 printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100115 }
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100116#endif
Robert Griebl1cd04452002-07-21 16:50:49 +0000117}
118
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100119static void to_sys_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +0000120{
Denis Vlasenko459be352007-06-17 19:09:05 +0000121 struct timeval tv;
Denys Vlasenko043b1e52009-09-06 12:47:55 +0200122 struct timezone tz;
123
Eddie James1a5d6fc2020-08-10 09:59:02 -0500124 tz.tz_minuteswest = timezone / 60;
Denys Vlasenko589051b2014-02-25 17:52:10 +0100125 /* ^^^ used to also subtract 60*daylight, but it's wrong:
126 * daylight!=0 means "this timezone has some DST
127 * during the year", not "DST is in effect now".
128 */
Denys Vlasenko043b1e52009-09-06 12:47:55 +0200129 tz.tz_dsttime = 0;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000130
Eddie James1a5d6fc2020-08-10 09:59:02 -0500131 /* glibc v2.31+ returns an error if both args are non-NULL */
132 if (settimeofday(NULL, &tz))
133 bb_simple_perror_msg_and_die("settimeofday");
134
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100135 tv.tv_sec = read_rtc(pp_rtcname, NULL, utc);
Denis Vlasenko459be352007-06-17 19:09:05 +0000136 tv.tv_usec = 0;
Eddie James1a5d6fc2020-08-10 09:59:02 -0500137 if (settimeofday(&tv, NULL))
James Byrne69374872019-07-02 11:35:03 +0200138 bb_simple_perror_msg_and_die("settimeofday");
Robert Griebl1cd04452002-07-21 16:50:49 +0000139}
140
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100141static void from_sys_clock(const char **pp_rtcname, int utc)
Robert Griebl1cd04452002-07-21 16:50:49 +0000142{
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700143#if 1
144 struct timeval tv;
145 struct tm tm_time;
146 int rtc;
147
148 rtc = rtc_xopen(pp_rtcname, O_WRONLY);
149 gettimeofday(&tv, NULL);
150 /* Prepare tm_time */
151 if (sizeof(time_t) == sizeof(tv.tv_sec)) {
152 if (utc)
153 gmtime_r((time_t*)&tv.tv_sec, &tm_time);
154 else
155 localtime_r((time_t*)&tv.tv_sec, &tm_time);
156 } else {
157 time_t t = tv.tv_sec;
158 if (utc)
159 gmtime_r(&t, &tm_time);
160 else
161 localtime_r(&t, &tm_time);
162 }
163#else
164/* Bloated code which tries to set hw clock with better precision.
165 * On x86, even though code does set hw clock within <1ms of exact
166 * whole seconds, apparently hw clock (at least on some machines)
167 * doesn't reset internal fractional seconds to 0,
Denys Vlasenko10ad6222017-04-17 16:13:32 +0200168 * making all this a pointless exercise.
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700169 */
170 /* If we see that we are N usec away from whole second,
171 * we'll sleep for N-ADJ usecs. ADJ corrects for the fact
172 * that CPU is not infinitely fast.
173 * On infinitely fast CPU, next wakeup would be
174 * on (exactly_next_whole_second - ADJ). On real CPUs,
175 * this difference between current time and whole second
176 * is less than ADJ (assuming system isn't heavily loaded).
177 */
178 /* Small value of 256us gives very precise sync for 2+ GHz CPUs.
179 * Slower CPUs will fail to sync and will go to bigger
180 * ADJ values. qemu-emulated armv4tl with ~100 MHz
181 * performance ends up using ADJ ~= 4*1024 and it takes
182 * 2+ secs (2 tries with successively larger ADJ)
183 * to sync. Even straced one on the same qemu (very slow)
184 * takes only 4 tries.
185 */
186#define TWEAK_USEC 256
187 unsigned adj = TWEAK_USEC;
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100188 struct tm tm_time;
Denis Vlasenko459be352007-06-17 19:09:05 +0000189 struct timeval tv;
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100190 int rtc = rtc_xopen(pp_rtcname, O_WRONLY);
Robert Griebl1cd04452002-07-21 16:50:49 +0000191
Denys Vlasenko695fa512010-01-06 18:16:39 +0100192 /* Try to catch the moment when whole second is close */
193 while (1) {
194 unsigned rem_usec;
195 time_t t;
196
197 gettimeofday(&tv, NULL);
198
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100199 t = tv.tv_sec;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100200 rem_usec = 1000000 - tv.tv_usec;
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700201 if (rem_usec < adj) {
202 /* Close enough */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100203 small_rem:
Denys Vlasenko5e3b1402010-01-06 22:43:39 +0100204 t++;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100205 }
206
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700207 /* Prepare tm_time from t */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100208 if (utc)
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100209 gmtime_r(&t, &tm_time); /* may read /etc/xxx (it takes time) */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100210 else
Denys Vlasenkodc698bb2010-01-09 19:10:49 +0100211 localtime_r(&t, &tm_time); /* same */
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700212
213 if (adj >= 32*1024) {
214 break; /* 32 ms diff and still no luck?? give up trying to sync */
215 }
Denys Vlasenko695fa512010-01-06 18:16:39 +0100216
217 /* gmtime/localtime took some time, re-get cur time */
218 gettimeofday(&tv, NULL);
219
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700220 if (tv.tv_sec < t /* we are still in old second */
221 || (tv.tv_sec == t && tv.tv_usec < adj) /* not too far into next second */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100222 ) {
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700223 break; /* good, we are in sync! */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100224 }
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700225
226 rem_usec = 1000000 - tv.tv_usec;
227 if (rem_usec < adj) {
228 t = tv.tv_sec;
229 goto small_rem; /* already close to next sec, don't sleep */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100230 }
231
232 /* Try to sync up by sleeping */
Denys Vlasenko695fa512010-01-06 18:16:39 +0100233 usleep(rem_usec - adj);
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700234
235 /* Jump to 1ms diff, then increase fast (x2): EVERY loop
236 * takes ~1 sec, people won't like slowly converging code here!
237 */
238 //bb_error_msg("adj:%d tv.tv_usec:%d", adj, (int)tv.tv_usec);
239 if (adj < 512)
240 adj = 512;
241 /* ... and if last "overshoot" does not look insanely big,
242 * just use it as adj increment. This makes convergence faster.
243 */
244 if (tv.tv_usec < adj * 8) {
245 adj += tv.tv_usec;
246 continue;
247 }
248 adj *= 2;
Denys Vlasenko695fa512010-01-06 18:16:39 +0100249 }
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700250 /* Debug aid to find "optimal" TWEAK_USEC with nearly exact sync.
Denys Vlasenko695fa512010-01-06 18:16:39 +0100251 * Look for a value which makes tv_usec close to 999999 or 0.
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700252 * For 2.20GHz Intel Core 2: optimal TWEAK_USEC ~= 200
Denys Vlasenko695fa512010-01-06 18:16:39 +0100253 */
Denys Vlasenko60f659f2010-04-14 09:19:20 -0700254 //bb_error_msg("tv.tv_usec:%d", (int)tv.tv_usec);
255#endif
256
257 tm_time.tm_isdst = 0;
258 xioctl(rtc, RTC_SET_TIME, &tm_time);
Denys Vlasenko695fa512010-01-06 18:16:39 +0100259
260 if (ENABLE_FEATURE_CLEAN_UP)
261 close(rtc);
Robert Griebl1cd04452002-07-21 16:50:49 +0000262}
263
Davide Cavalca658a4372011-01-22 18:55:32 +0100264/*
265 * At system boot, kernel may set system time from RTC,
266 * but it knows nothing about timezones. If RTC is in local time,
267 * then system time is wrong - it is offset by timezone.
268 * This option corrects system time if RTC is in local time,
269 * and (always) sets in-kernel timezone.
270 *
271 * This is an alternate option to --hctosys that does not read the
272 * hardware clock.
273 */
274static void set_system_clock_timezone(int utc)
275{
276 struct timeval tv;
277 struct tm *broken;
278 struct timezone tz;
279
280 gettimeofday(&tv, NULL);
281 broken = localtime(&tv.tv_sec);
282 tz.tz_minuteswest = timezone / 60;
Denys Vlasenko589051b2014-02-25 17:52:10 +0100283 if (broken->tm_isdst > 0)
Davide Cavalca658a4372011-01-22 18:55:32 +0100284 tz.tz_minuteswest -= 60;
285 tz.tz_dsttime = 0;
286 gettimeofday(&tv, NULL);
287 if (!utc)
288 tv.tv_sec += tz.tz_minuteswest * 60;
Eddie James1a5d6fc2020-08-10 09:59:02 -0500289
290 /* glibc v2.31+ returns an error if both args are non-NULL */
291 if (settimeofday(NULL, &tz))
292 bb_simple_perror_msg_and_die("settimeofday");
293 if (settimeofday(&tv, NULL))
James Byrne69374872019-07-02 11:35:03 +0200294 bb_simple_perror_msg_and_die("settimeofday");
Davide Cavalca658a4372011-01-22 18:55:32 +0100295}
296
297//usage:#define hwclock_trivial_usage
Denys Vlasenko036585a2017-08-08 16:38:18 +0200298//usage: IF_LONG_OPTS(
Denys Vlasenkocaba1a12020-12-16 01:19:08 +0100299//usage: "[-swu] [--systz] [--localtime] [-f FILE]"
Davide Cavalca658a4372011-01-22 18:55:32 +0100300//usage: )
Denys Vlasenko036585a2017-08-08 16:38:18 +0200301//usage: IF_NOT_LONG_OPTS(
Denys Vlasenkocaba1a12020-12-16 01:19:08 +0100302//usage: "[-swtlu] [-f FILE]"
Davide Cavalca658a4372011-01-22 18:55:32 +0100303//usage: )
304//usage:#define hwclock_full_usage "\n\n"
Denys Vlasenkocaba1a12020-12-16 01:19:08 +0100305//usage: "Show or set hardware clock (RTC)\n"
306///////: "\n -r Show hardware clock time"
307///////-r is default, don't bother showing it in help
Davide Cavalca658a4372011-01-22 18:55:32 +0100308//usage: "\n -s Set system time from hardware clock"
309//usage: "\n -w Set hardware clock from system time"
Denys Vlasenko036585a2017-08-08 16:38:18 +0200310//usage: IF_LONG_OPTS(
311//usage: "\n --systz Set in-kernel timezone, correct system time"
312//usage: )
Davide Cavalca658a4372011-01-22 18:55:32 +0100313//usage: "\n if hardware clock is in local time"
Denys Vlasenko46465ec2011-07-04 04:34:57 +0200314//usage: "\n -u Assume hardware clock is kept in UTC"
Denys Vlasenko036585a2017-08-08 16:38:18 +0200315//usage: IF_LONG_OPTS(
316//usage: "\n --localtime Assume hardware clock is kept in local time"
317//usage: )
Davide Cavalca658a4372011-01-22 18:55:32 +0100318//usage: "\n -f FILE Use specified device (e.g. /dev/rtc2)"
319
Denys Vlasenko036585a2017-08-08 16:38:18 +0200320//TODO: get rid of incompatible -t and -l aliases to --systz and --localtime
321
Denis Vlasenko92258542006-11-01 10:25:35 +0000322#define HWCLOCK_OPT_LOCALTIME 0x01
323#define HWCLOCK_OPT_UTC 0x02
324#define HWCLOCK_OPT_SHOW 0x04
325#define HWCLOCK_OPT_HCTOSYS 0x08
326#define HWCLOCK_OPT_SYSTOHC 0x10
Davide Cavalca658a4372011-01-22 18:55:32 +0100327#define HWCLOCK_OPT_SYSTZ 0x20
328#define HWCLOCK_OPT_RTCFILE 0x40
Glenn L McGrath689e4b92004-02-22 09:11:33 +0000329
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000330int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000331int hwclock_main(int argc UNUSED_PARAM, char **argv)
Robert Griebl1cd04452002-07-21 16:50:49 +0000332{
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100333 const char *rtcname = NULL;
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000334 unsigned opt;
Robert Griebl6bb80872004-03-22 21:27:39 +0000335 int utc;
Robert Griebl1cd04452002-07-21 16:50:49 +0000336
Denys Vlasenko036585a2017-08-08 16:38:18 +0200337#if ENABLE_LONG_OPTS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000338 static const char hwclock_longopts[] ALIGN1 =
Davide Cavalca658a4372011-01-22 18:55:32 +0100339 "localtime\0" No_argument "l" /* short opt is non-standard */
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +0000340 "utc\0" No_argument "u"
341 "show\0" No_argument "r"
342 "hctosys\0" No_argument "s"
343 "systohc\0" No_argument "w"
Davide Cavalca658a4372011-01-22 18:55:32 +0100344 "systz\0" No_argument "t" /* short opt is non-standard */
345 "rtc\0" Required_argument "f"
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000346 ;
Robert Griebl1cd04452002-07-21 16:50:49 +0000347#endif
Denys Vlasenko589051b2014-02-25 17:52:10 +0100348
349 /* Initialize "timezone" (libc global variable) */
350 tzset();
351
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200352 opt = getopt32long(argv,
353 "^lurswtf:" "\0" "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l",
354 hwclock_longopts,
355 &rtcname
356 );
Robert Griebl1cd04452002-07-21 16:50:49 +0000357
Robert Griebl6bb80872004-03-22 21:27:39 +0000358 /* If -u or -l wasn't given check if we are using utc */
Mike Frysingerb31566e2005-04-16 04:48:48 +0000359 if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME))
Mike Frysinger6b160e42008-02-15 02:27:19 +0000360 utc = (opt & HWCLOCK_OPT_UTC);
Robert Griebl6bb80872004-03-22 21:27:39 +0000361 else
Mike Frysinger6b160e42008-02-15 02:27:19 +0000362 utc = rtc_adjtime_is_utc();
Mike Frysingerb31566e2005-04-16 04:48:48 +0000363
Mike Frysinger6b160e42008-02-15 02:27:19 +0000364 if (opt & HWCLOCK_OPT_HCTOSYS)
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100365 to_sys_clock(&rtcname, utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000366 else if (opt & HWCLOCK_OPT_SYSTOHC)
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100367 from_sys_clock(&rtcname, utc);
Davide Cavalca658a4372011-01-22 18:55:32 +0100368 else if (opt & HWCLOCK_OPT_SYSTZ)
369 set_system_clock_timezone(utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000370 else
371 /* default HWCLOCK_OPT_SHOW */
Denys Vlasenko6959f6b2010-01-07 08:31:46 +0100372 show_clock(&rtcname, utc);
Mike Frysinger6b160e42008-02-15 02:27:19 +0000373
Denis Vlasenko459be352007-06-17 19:09:05 +0000374 return 0;
Robert Griebl1cd04452002-07-21 16:50:49 +0000375}