On 2 May 2014 03:52, Alexander Samilovskih <alexsamilovskih@xxxxxxxxx> wrote: > There are several places where gettimeofday should be replaced by > clock_gettime(CLOCK_MONOTONIC_RAW). According to manual pages > gettimeofday affected by discontinues jumps made by system > administrator, can be slewed by ntpd or kinda stuff. So when we > subtract two different timestamps from gettimeofday we can get > confusing results > > sys-utils/eject.c > libmount/lock.c > maybe some other places... Hi Alexander, The diff you sent does not seem to work. fatal: corrupt patch at line 123 The format you get from $ git format-patch HEAD~1 would be appreciated. > diff --git a/include/timeutils.h b/include/timeutils.h > index bcae613..7cf972d 100644 > --- a/include/timeutils.h > +++ b/include/timeutils.h > @@ -51,5 +51,6 @@ typedef uint64_t nsec_t; > #define FORMAT_TIMESPAN_MAX 64 > > int parse_timestamp(const char *t, usec_t *usec); > +int gettime_monotonic(struct timeval *tv); > > #endif /* UTIL_LINUX_TIME_UTIL_H */ > diff --git a/lib/timeutils.c b/lib/timeutils.c > index 7fe6218..06ae597 100644 > --- a/lib/timeutils.c > +++ b/lib/timeutils.c > @@ -336,3 +336,24 @@ int parse_timestamp(const char *t, usec_t *usec) > > return 0; > } > + > +int gettime_monotonic(struct timeval *tv) > +{ > +#ifdef CLOCK_MONOTONIC > + //Can slew only by ntp and adjtime Could you use /* comment */ style rather than // from C++ world. > + 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 A comment could ease understanding what is going on, such as #else /* CLOCK_MONOTONIC is not available */ > + return gettimeofday(tv, NULL); > +#endif > +} Th rest looks pretty ok. -- Sami Kerola http://www.iki.fi/kerolasa/ -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html