Tricking Linux apps about current time with environment variables

4

1

Sometimes it is possible to trick a Linux app by calling it like this:

HOME=/tmp/foo myapp

This would make myapp think /tmp/foo is the home directory, it won't try to get the user id, find its home directory via getpwent().

This is useful when myapp must be forced to dump some of its config files into a non-standard location different than ~.

A similar trick can be done like this:

LANG=foo LC_ALL=bar myapp

This is useful when myapp needs to be called once with a different locale without having to make the change persistent by using the export bash built-in or even modify stuff in /etc/profile.

Is it possible to pull the same trick with time and date? The goal is to make an app use another time than the system ones. The final goal - to make timestamps that appear in logs/commit messages not being tied to the system time.

geek

Posted 2010-05-21T17:23:18.977

Reputation: 7 120

+1 on the question because it's an interesting idea with interesting use cases that I'd never considered. I'm just sorry I can't provide an answer. – Doug Harris – 2010-05-21T17:37:17.197

For moderators: feel free to mark this question as duplicate of the one mentioned by Dennis Williamson in his answer. – geek – 2010-05-21T17:52:38.033

Cross-site duplicates are not usually closed. – Paused until further notice. – 2010-05-21T19:02:41.850

Answers

2

This answer from Stack Overflow suggests a library called libfaketime.

Paused until further notice.

Posted 2010-05-21T17:23:18.977

Reputation: 86 075