summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Hommel <wolfcw@users.noreply.github.com>2021-02-26 20:46:27 +0100
committerGitHub <noreply@github.com>2021-02-26 20:46:27 +0100
commit0e6b1b24603948dab13f165f03a75e357e44d518 (patch)
tree3f06e6b192f69585277a981c3766f58d06c0a11b
parent1297568caf75400779febc2e9761179d7c270a5b (diff)
parent5e62eafcc290bbbbff213c043894767277237dda (diff)
downloadlibfaketime-0e6b1b24603948dab13f165f03a75e357e44d518.tar.gz
Merge pull request #309 from dkg/faketime-pid
faketime: add -p option to wrapper for setting PID
-rw-r--r--man/faketime.13
-rw-r--r--src/faketime.c17
2 files changed, 20 insertions, 0 deletions
diff --git a/man/faketime.1 b/man/faketime.1
index 5a22732..2b329ea 100644
--- a/man/faketime.1
+++ b/man/faketime.1
@@ -23,6 +23,9 @@ show version information and quit.
\fB\-m\fR
use the multi-threading variant of libfaketime.
.TP
+\fB\-p <PID>\fR
+pretend that the program's process ID is PID. (only available if built with FAKE_PID)
+.TP
\fB\-f\fR
use the advanced timestamp specification format.
.TP
diff --git a/src/faketime.c b/src/faketime.c
index 23d6abf..af618f2 100644
--- a/src/faketime.c
+++ b/src/faketime.c
@@ -75,6 +75,9 @@ void usage(const char *name)
" -m : Use the multi-threaded version of libfaketime\n"
" -f : Use the advanced timestamp specification format (see manpage)\n"
" --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
"\n"
"Examples:\n"
"%s 'last friday 5 pm' /bin/date\n"
@@ -107,6 +110,8 @@ int main (int argc, char **argv)
int curr_opt = 1;
bool use_mt = false, use_direct = false;
long offset;
+ bool fake_pid = false;
+ const char *pid_val;
while(curr_opt < argc)
{
@@ -116,6 +121,16 @@ int main (int argc, char **argv)
curr_opt++;
continue;
}
+ if (0 == strcmp(argv[curr_opt], "-p"))
+ {
+ fake_pid = true;
+ pid_val = argv[curr_opt + 1];
+ curr_opt += 2;
+#ifndef FAKE_PID
+ fprintf(stderr, "faketime: -p argument probably won't work (try rebuilding with -DFAKE_PID)\n");
+#endif
+ continue;
+ }
else if (0 == strcmp(argv[curr_opt], "-f"))
{
use_direct = true;
@@ -198,6 +213,8 @@ int main (int argc, char **argv)
/* simply pass format string along */
setenv("FAKETIME", argv[curr_opt], true);
}
+ if (fake_pid)
+ setenv("FAKETIME_FAKEPID", pid_val, true);
int keepalive_fds[2];
(void) (pipe(keepalive_fds) + 1);