Skip to content

Commit

Permalink
Merge pull request #465 from Rob--W/add-disable-shm-option
Browse files Browse the repository at this point in the history
Add --disable-shm / FAKETIME_DISABLE_SHM
  • Loading branch information
wolfcw authored Mar 19, 2024
2 parents 23bec38 + 39fdbde commit b716122
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ for long-running systems (servers with high uptime) and systems on which
a lot of processes are started (e.g., servers handling many containers
or similar virtualization mechanisms).

Use of shared memory can be disabled by setting the FAKETIME_DISABLE_SHM
environment variable, or equivalently, passing --disable-shm to faketime.


Intercepting time-setting calls
-------------------------------
Expand Down
3 changes: 3 additions & 0 deletions man/faketime.1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ use the advanced timestamp specification format.
\fB\--exclude-monotonic\fR
Do not fake time when the program makes a call to clock_gettime with a CLOCK_MONOTONIC clock.
.TP
\fB\--disable-shm\fR
Disable use of shared memory by libfaketime.
.TP
\fB\--date-prog <PATH>\fR
Use a specific GNU-date compatible implementation of the helper used to transform "timestamp format" strings into programmatically usable dates, instead of a compile-time default guess for the generic target platform.

Expand Down
11 changes: 11 additions & 0 deletions src/faketime.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void usage(const char *name)
" --exclude-monotonic : Prevent monotonic clock from drifting (not the raw monotonic one)\n"
#ifdef FAKE_PID
" -p PID : Pretend that the program's process ID is PID\n"
#endif
#ifndef FAKE_STATELESS
" --disable-shm : Disable use of shared memory by libfaketime.\n"
#endif
" --date-prog PROG : Use specified GNU-compatible implementation of 'date' program\n"
"\n"
Expand Down Expand Up @@ -150,6 +153,14 @@ int main (int argc, char **argv)
curr_opt++;
continue;
}
#ifndef FAKE_STATELESS
else if (0 == strcmp(argv[curr_opt], "--disable-shm"))
{
setenv("FAKETIME_DISABLE_SHM", "1", true);
curr_opt++;
continue;
}
#endif
else if (0 == strcmp(argv[curr_opt], "--date-prog"))
{
curr_opt++;
Expand Down
5 changes: 4 additions & 1 deletion src/libfaketime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2790,7 +2790,10 @@ static void ftpl_really_init(void)
#ifdef FAKE_STATELESS
if (0) ft_shm_init();
#else
ft_shm_init();
tmp_env = getenv("FAKETIME_DISABLE_SHM");
if (!tmp_env || tmp_env[0] == '0') {
ft_shm_init();
}
#endif
#ifdef FAKE_STAT
if (getenv("NO_FAKE_STAT")!=NULL)
Expand Down

0 comments on commit b716122

Please sign in to comment.