[LTP] [PATCH v4 4/8] lib: new restore_wallclock field to restore realtime clock
Cyril Hrubis
chrubis@suse.cz
Wed Jan 30 14:53:24 CET 2019
Hi!
I've changed the tst_wallclock.c so that it restores the time only if it
was saved previously, otherwise we will either set completely wrong time
if something has failed prior call to tst_wallclock_save() or generage
bogus error messages when the test exits because of unsufficient
priviledges.
full diff:
diff --git a/lib/tst_wallclock.c b/lib/tst_wallclock.c
index 1513882f4..f1c96c0cf 100644
--- a/lib/tst_wallclock.c
+++ b/lib/tst_wallclock.c
@@ -16,6 +16,8 @@
static struct timespec real_begin, mono_begin;
+static int clock_saved;
+
void tst_wallclock_save(void)
{
/* save initial monotonic time to restore it when needed */
@@ -25,12 +27,19 @@ void tst_wallclock_save(void)
if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_begin))
tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
+
+ clock_saved = 1;
}
void tst_wallclock_restore(void)
{
static struct timespec mono_end, elapsed, adjust;
+ if (!clock_saved)
+ return;
+
+ clock_saved = 0;
+
if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_end))
tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list