4 * Licensed under GPLv2, see file LICENSE in this source tree.
10 #if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS
11 # define ADJTIME_PATH "/var/lib/hwclock/adjtime"
13 # define ADJTIME_PATH "/etc/adjtime"
16 int FAST_FUNC
rtc_adjtime_is_utc(void)
19 FILE *f
= fopen_for_read(ADJTIME_PATH
);
24 while (fgets(buffer
, sizeof(buffer
), f
)) {
25 if (strncmp(buffer
, "UTC", 3) == 0) {
36 /* rtc opens are exclusive.
37 * Try to run two "hwclock -w" at the same time to see it.
38 * Users wouldn't expect that to fail merely because /dev/rtc
39 * was momentarily busy, let's try a bit harder on errno == EBUSY.
41 static int open_loop_on_busy(const char *name
, int flags
)
45 * Tested with two parallel "hwclock -w" loops.
46 * With try = 10, no failures with 2x1000000 loop iterations.
51 rtc
= open(name
, flags
);
56 /* EBUSY. Last try, exit on error instead of returning -1 */
57 return xopen(name
, flags
);
63 int FAST_FUNC
rtc_xopen(const char **default_rtc
, int flags
)
73 name
= ""; /*else: we have rtc name, don't try other names */
76 rtc
= open_loop_on_busy(*default_rtc
, flags
);
80 return xopen(*default_rtc
, flags
);
83 name
+= strlen(name
) + 1;
87 void FAST_FUNC
rtc_read_tm(struct tm
*ptm
, int fd
)
89 memset(ptm
, 0, sizeof(*ptm
));
90 xioctl(fd
, RTC_RD_TIME
, ptm
);
91 ptm
->tm_isdst
= -1; /* "not known" */
94 time_t FAST_FUNC
rtc_tm2time(struct tm
*ptm
, int utc
)
96 char *oldtz
= oldtz
; /* for compiler */
100 oldtz
= getenv("TZ");
101 putenv((char*)"TZ=UTC0");