| * Please, don't add this file to libcommon because clock_gettime() requires |
| * -lrt on systems with old libc. |
| int get_boot_time(struct timeval *boot_time) |
| struct timespec hires_uptime; |
| struct timeval lores_uptime; |
| if (gettimeofday(&now, NULL) != 0) { |
| warn(_("gettimeofday failed")); |
| if (clock_gettime(CLOCK_BOOTTIME, &hires_uptime) == 0) { |
| TIMESPEC_TO_TIMEVAL(&lores_uptime, &hires_uptime); |
| timersub(&now, &lores_uptime, boot_time); |
| warn(_("sysinfo failed")); |
| boot_time->tv_sec = now.tv_sec - info.uptime; |
| int gettime_monotonic(struct timeval *tv) |
| /* Can slew only by ntp and adjtime */ |
| # ifdef CLOCK_MONOTONIC_RAW |
| /* Linux specific, cant slew */ |
| if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) { |
| if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) { |
| tv->tv_usec = ts.tv_nsec / 1000; |
| return gettimeofday(tv, NULL); |