Commit fe40f349 authored by Vitezslav Kriz's avatar Vitezslav Kriz

libfaketime: fix problem with TIMESTAMP_FILE synchronization

Clearing and writing to TIMESTAMP_FILE is not atomic and libfaketime
can read empty file which represents default behavior and returning
realtime. Create and move new file is atomic and prevent this issue.
parent 79f47cbf
Pipeline #18550 passed with stage
in 1 minute and 16 seconds
......@@ -712,15 +712,16 @@ class Step:
def __time_passes(self):
""" Modify system time. """
time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'r')
file_old = os.environ["FAKETIME_TIMESTAMP_FILE"]
file_next = os.environ["FAKETIME_TIMESTAMP_FILE"] + ".next"
with open(file_old, 'r') as time_file:
line = time_file.readline().strip()
t = time.mktime(datetime.strptime(line, '@%Y-%m-%d %H:%M:%S').timetuple())
t += self.delay
time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w')
with open(file_next, 'w') as time_file:
time_file.write(datetime.fromtimestamp(t).strftime('@%Y-%m-%d %H:%M:%S') + "\n")
os.replace(file_next, file_old)
# def __assert(self, ctx):
# """ Assert that a passed expression evaluates to True. """
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment