mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
hwclock: make commented-out code compilable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6959f6bc23
commit
0c58cc706f
@ -23,7 +23,12 @@
|
|||||||
* "time between hwclock was started and we saw CMOS tick" quantity.
|
* "time between hwclock was started and we saw CMOS tick" quantity.
|
||||||
* It's useless since hwclock is started at a random moment,
|
* It's useless since hwclock is started at a random moment,
|
||||||
* thus the quantity is also random, useless. Showing 0.000000 does not
|
* thus the quantity is also random, useless. Showing 0.000000 does not
|
||||||
* deprive us from any useful info. */
|
* deprive us from any useful info.
|
||||||
|
*
|
||||||
|
* SHOW_HWCLOCK_DIFF code in this file shows the difference between system
|
||||||
|
* and hw clock. It is useful, but not compatible with standard hwclock.
|
||||||
|
* Thus disabled.
|
||||||
|
*/
|
||||||
#define SHOW_HWCLOCK_DIFF 0
|
#define SHOW_HWCLOCK_DIFF 0
|
||||||
|
|
||||||
|
|
||||||
@ -40,13 +45,14 @@ static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
|
|||||||
rtc_read_tm(&tm, fd);
|
rtc_read_tm(&tm, fd);
|
||||||
|
|
||||||
#if SHOW_HWCLOCK_DIFF
|
#if SHOW_HWCLOCK_DIFF
|
||||||
int before;
|
{
|
||||||
before = tm.tm_sec;
|
int before = tm.tm_sec;
|
||||||
while (1) {
|
while (1) {
|
||||||
rtc_read_tm(&tm, fd);
|
rtc_read_tm(&tm, fd);
|
||||||
gettimeofday(sys_tv, NULL);
|
gettimeofday(sys_tv, NULL);
|
||||||
if (before != tm.tm_sec)
|
if (before != tm.tm_sec)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -58,29 +64,32 @@ static time_t read_rtc(const char **pp_rtcname, struct timeval *sys_tv, int utc)
|
|||||||
|
|
||||||
static void show_clock(const char **pp_rtcname, int utc)
|
static void show_clock(const char **pp_rtcname, int utc)
|
||||||
{
|
{
|
||||||
|
#if SHOW_HWCLOCK_DIFF
|
||||||
|
struct timeval sys_tv;
|
||||||
|
#endif
|
||||||
time_t t;
|
time_t t;
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
t = read_rtc(pp_rtcname, &sys_tv, utc);
|
t = read_rtc(pp_rtcname, &sys_tv, utc);
|
||||||
cp = ctime(&t);
|
cp = ctime(&t);
|
||||||
strchrnul(cp, '\n')[0] = '\0';
|
strchrnul(cp, '\n')[0] = '\0';
|
||||||
|
#if !SHOW_HWCLOCK_DIFF
|
||||||
printf("%s 0.000000 seconds\n", cp);
|
printf("%s 0.000000 seconds\n", cp);
|
||||||
|
#else
|
||||||
#if SHOW_HWCLOCK_DIFF
|
{
|
||||||
struct timeval sys_tv;
|
long diff = sys_tv.tv_sec - t;
|
||||||
long diff;
|
if (diff < 0 /*&& tv.tv_usec != 0*/) {
|
||||||
diff = sys_tv.tv_sec - t;
|
/* Why? */
|
||||||
if (diff < 0 /*&& tv.tv_usec != 0*/) {
|
/* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */
|
||||||
/* Why? */
|
/* 45.520820 43.520820 */
|
||||||
/* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */
|
/* - 44.000000 - 45.000000 */
|
||||||
/* 45.520820 43.520820 */
|
/* = 0.520820 = -1.479180, not -2.520820! */
|
||||||
/* - 44.000000 - 45.000000 */
|
diff++;
|
||||||
/* = 0.520820 = -1.479180, not -2.520820! */
|
/* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
|
||||||
diff++;
|
sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
|
||||||
/* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
|
}
|
||||||
sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
|
printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
|
||||||
}
|
}
|
||||||
printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user