libfaketime icon indicating copy to clipboard operation
libfaketime copied to clipboard

$SECONDS variable becomes negative after 10 seconds

Open mrechte opened this issue 1 year ago • 3 comments

This code will never end, because $SECONDS becomes negative after 10 seconds:

LD_PRELOAD=src/libfaketime.so.1 FAKETIME="@2000-01-01 11:12:13" \
  FAKETIME_DONT_RESET=1 \
  /bin/bash -c 'while [ $SECONDS -lt 20 ]; do date; echo $SECONDS; sleep 1; done'

Compiled and run on ArchLinux.

mrechte avatar May 22 '24 14:05 mrechte

Nice one, thanks for reporting. :-)

Reproduces with bash on other platforms, but for example with zsh it works as expected. With bash, also other variables such as $EPOCHSECONDS are affected after ~10 seconds. Not sure where that comes from yet.

wolfcw avatar May 29 '24 15:05 wolfcw

Any update? Not really an issue for me, just I am VERY curious why it happens. And why it's 10 seconds. 😅

AgainPsychoX avatar Aug 07 '24 09:08 AgainPsychoX

Sorry, not yet. It is only known to affect bash so far (i.e., it does not seem to be a generic problem), and I didn't take the time to look into the bash implementation details yet. Maybe someone more familiar with the inner workings of bash could assist? :-)

wolfcw avatar Aug 07 '24 09:08 wolfcw