copied to util-linux at August 2013.
Copyright 2010 Lennart Poettering
+ Copyright (C) 2014 Karel Zak <kzak@redhat.com>
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
int parse_timestamp(const char *t, usec_t *usec);
+int gettime_monotonic(struct timeval *tv);
+
#endif /* UTIL_LINUX_TIME_UTIL_H */
return 0;
}
+
+
+int gettime_monotonic(struct timeval *tv)
+{
+#ifdef CLOCK_MONOTONIC
+ /* Can slew only by ntp and adjtime */
+ int ret;
+ struct timespec ts;
+
+# ifdef CLOCK_MONOTONIC_RAW
+ /* Linux specific, cant slew */
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
+# else
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
+# endif
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+ }
+ return ret;
+#else
+ return gettimeofday(tv, NULL);
+#endif
+}
#include "closestream.h"
#include "pathnames.h"
#include "mountP.h"
+#include "timeutils.h"
/*
* lock handler
struct sigaction sa, osa;
int ret = 0;
- gettimeofday(&now, NULL);
+ gettime_monotonic(&now);
if (now.tv_sec >= maxtime)
return 1; /* timeout */
}
close(i);
- gettimeofday(&maxtime, NULL);
+ gettime_monotonic(&maxtime);
maxtime.tv_sec += MOUNTLOCK_MAXTIME;
waittime.tv_sec = 0;
if (ml->lockfile_fd < 0) {
/* Strange... Maybe the file was just deleted? */
int errsv = errno;
- gettimeofday(&now, NULL);
+ gettime_monotonic(&now);
if (errsv == ENOENT && now.tv_sec < maxtime.tv_sec) {
ml->locked = 0;
continue;
/* start the test in exactly defined time */
if (synctime) {
- gettimeofday(&tv, NULL);
+ gettime_monotonic(&tv);
if (synctime && synctime - tv.tv_sec > 1) {
usecs = ((synctime - tv.tv_sec) * 1000000UL) -
(1000000UL - tv.tv_usec);
#include "strutils.h"
#include "c.h"
#include "closestream.h"
+#include "timeutils.h"
#ifndef BLKDISCARD
#define BLKDISCARD _IO(0x12,119)
int c, fd, verbose = 0, secure = 0, secsize;
uint64_t end, blksize, step, range[2], stats[2];
struct stat sb;
- struct timespec now, last;
+ struct timeval now, last;
static const struct option longopts[] = {
{ "help", 0, 0, 'h' },
"to sector size %i"), path, range[1], secsize);
stats[0] = range[0], stats[1] = 0;
- clock_gettime(CLOCK_MONOTONIC, &last);
+ gettime_monotonic(&last);
for (range[0] = range[0]; range[0] < end; range[0] += range[1]) {
if (range[0] + range[1] > end)
/* reporting progress */
if (verbose && step) {
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettime_monotonic(&now);
if (last.tv_sec < now.tv_sec) {
print_stats(path, stats);
stats[0] = range[0], stats[1] = 0;
#include "xalloc.h"
#include "pathnames.h"
#include "sysfs.h"
+#include "timeutils.h"
/*
* sg_io_hdr_t driver_status -- see kernel include/scsi/scsi.h
* needed. In my experience the function needs less than 0.05
* seconds if the tray was already open, and at least 1.5 seconds
* if it was closed. */
- gettimeofday(&time_start, NULL);
+ gettime_monotonic(&time_start);
/* Send the CDROMEJECT command to the device. */
if (!eject_cdrom(fd))
/* Get the second timestamp, to measure the time needed to open
* the tray. */
- gettimeofday(&time_stop, NULL);
+ gettime_monotonic(&time_stop);
time_elapsed = (time_stop.tv_sec * 1000000 + time_stop.tv_usec) -
(time_start.tv_sec * 1000000 + time_start.tv_usec);