[LTP] [PATCH 2/2] c: Use $LTP_TIMEOUT_MUL also in retry functions
Li Wang
liwang@redhat.com
Fri Jul 19 07:02:47 CEST 2019
On Thu, Jul 18, 2019 at 4:40 PM Petr Vorel <pvorel@suse.cz> wrote:
>...
> #ifndef TST_COMMON_H__
> @@ -51,15 +40,22 @@
>
> #define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY) \
> ({ int tst_delay_ = 1; \
> + float m = 1; \
> + char *mul = getenv("LTP_TIMEOUT_MUL"); \
We also need a prefix/suffix in the variable definition to make sure
that it will
not alias with anything that has been passed to the FUNC, just like what we do
for the tst_delay_.
e.g. if the FUNC is defined as foo_func(m); the m variable will be aliased and
the function will do something very unexpected.
> + if (mul) { \
> + m = atof(mul); \
> + if (m < 1) \
> + tst_brk(TBROK, "Invalid timeout multiplier '%s'", mul); \
If we reverse some code order in tst_set_timeout() function, then here
we have no need to check if m < 1 again, since the LTP_TIMEOUT_MUL
valid check will be finished in setup() early phase.
(This comment is just FYI, and I also think it's OK to check twice.)
--------------------------------------
void tst_set_timeout(int timeout)
{
float m = 1;
char *mul = getenv("LTP_TIMEOUT_MUL");
if (mul) {
m = atof(mul);
if (m < 1)
tst_brk(TBROK, "Invalid timeout multiplier '%s'", mul);
}
if (timeout == -1) {
tst_res(TINFO, "Timeout per run is disabled");
return;
}
results->timeout = timeout * m + 0.5;
tst_res(TINFO, "Timeout per run is %uh %02um %02us",
results->timeout/3600, (results->timeout%3600)/60,
results->timeout % 60);
if (getpid() == lib_pid)
alarm(results->timeout);
else
heartbeat();
}
--
Regards,
Li Wang
More information about the ltp
mailing list