summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Hommel <wolf@code-wizards.com>2013-08-24 21:24:57 +0200
committerWolfgang Hommel <wolf@code-wizards.com>2013-08-24 21:24:57 +0200
commit03fbad9bca802e883ec445d7991ea0183ca0f62a (patch)
tree680a11d7ed2d632cc6ae2f9dffb29ac0c22a95cd
parent2dceb574acf96474e9d157c19c260bde4f825d19 (diff)
downloadlibfaketime-03fbad9bca802e883ec445d7991ea0183ca0f62a.tar.gz
Revert a0e3346..2dceb57
This rolls back to commit a0e33461a0cd92d916bbcdbfcdee4574411aee93.
-rw-r--r--README27
l---------lib/faketime1
-rw-r--r--man/faketime.18
-rw-r--r--src/Makefile4
-rw-r--r--src/faketime.c20
-rw-r--r--src/libfaketime.c53
6 files changed, 25 insertions, 88 deletions
diff --git a/README b/README
index 63cfba9..05fdafa 100644
--- a/README
+++ b/README
@@ -171,34 +171,15 @@ FAKETIME="2002-12-24 20:30:00".
(Thanks to a major contribution by David North, TDI in version 0.7)
+The format which _must_ be used for _start_at_ dates is "@YYYY-MM-DD hh:mm:ss".
+For example, the 24th of December, 2002, 8:30 PM would have to be specified as
+FAKETIME="@2002-12-24 20:30:00".
+
The absolute dates described in 4b simulate a STOPPED system clock at the
specified absolute time. The 'start at' format allows a 'relative' clock
operation as described below in section 4d, but using a 'start at' time
instead of an offset time.
-There are two subtypes of 'start at' dates, namely "@YYYY-MM-DD
-hh:mm:ss" and "^YYYY-MM-DD hh:mm:ss". The date *must* be written as
-indicated (see example below).
-
-The 'at' and 'caret' specifications differ with respect to what
-happens when subprocesses are spawned: with @ each subprocess "sees"
-the same faked starting time, regardless of the time at which it was
-spawned; the caret, instead, creates a single shared clock for the
-process group. The caret requires the use of the "faketime" wrapper.
-
-For example (24th of December, 2002, 8:30 PM)
-
- faketime -f '@2002-12-24 20:30:00' /bin/bash -c 'date; sleep 2; date'
-
-will print the same time twice, because each invocation of the
-"date" command sees its own independent faked clock, while
-
- faketime -f '^2002-12-24 20:30:00' /bin/bash -c 'date; sleep 2; date'
-
-will show dates 2 seconds apart because the two processes share a
-single faked clock.
-
-
4d) Using offsets for relative dates
------------------------------------
diff --git a/lib/faketime b/lib/faketime
deleted file mode 120000
index e057607..0000000
--- a/lib/faketime
+++ /dev/null
@@ -1 +0,0 @@
-../src/ \ No newline at end of file
diff --git a/man/faketime.1 b/man/faketime.1
index c88946b..0d9323b 100644
--- a/man/faketime.1
+++ b/man/faketime.1
@@ -33,9 +33,7 @@ faketime '2008-12-24 08:15:42' /bin/date
faketime -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y i2,0' /bin/bash -c 'while true; do date ; sleep 1 ; done'
-faketime -f '^2008-12-24 08:15:42' /bin/bash -c 'date; while true; do date; sleep 1 ; done'
-In the two latter cases all spawned processes will use the same global clock without
-restaring it at the start of each process.
+In this single case all spawned processes will use the same global clock without restaring it at the start of each process.
(Please note that it depends on your locale settings whether . or , has to be used for fractional offsets)
.fi
@@ -51,8 +49,8 @@ If you want to specify an absolute point in time, exactly this format must be us
Relative time offset: \fB"[+/-]123[m/h/d/y]\fR, e.g. "+60m", "+2y"
This is the most often used format and specifies the faked time relatively to the current real time. The first character of the format string \fBmust\fR be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale settings, so if "+2,5y" does not work, you might want to try "+2.5y".
.TP
-Start-at timestamps: \fB"@YYYY-MM-DD hh:mm:ss"\fR and \fB"^YYYY-MM-DD hh:mm:ss"\fR
-The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock. With the @ (at) syntax, each new subprocess will start at the specified time. With ^ (caret), subprocesses will share a global starting time.
+Start-at timestamps: \fB"@YYYY-MM-DD hh:mm:ss"\fR
+The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock.
.SH ADVANCED USAGE
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option \fB\-f\fR), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, \fB"+5y x10"\fR will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using \fB"-7d x0,2"\fR, which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter. You can also make faketime to advance the reported time by a preset interval upon each time() call independently from the system's time using \fB"-7d i2,0"\fR, where
\fB"i"\fR is followed by the increase interval in seconds.
diff --git a/src/Makefile b/src/Makefile
index 960c576..51b5100 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -52,9 +52,9 @@ INSTALL ?= install
PREFIX ?= /usr/local
-CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -DFAKE_INTERNAL_CALLS -fPIC -DPOSIX_REALTIME -DLIMITEDFAKING -DSPAWNSUPPORT -DPREFIX='"'$(PREFIX)'"' -g -D_FORTIFY_SOURCE=2 -O
+CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -DFAKE_INTERNAL_CALLS -fPIC -DPOSIX_REALTIME -DLIMITEDFAKING -DSPAWNSUPPORT -DPREFIX='"'$(PREFIX)'"'
LIB_LDFLAGS += -shared
-LDFLAGS += -lrt -lpthread
+LDFLAGS += -lrt
LDADD += -ldl -lm -lpthread
SRC = libfaketime.c
diff --git a/src/faketime.c b/src/faketime.c
index 1d7be75..163ed5c 100644
--- a/src/faketime.c
+++ b/src/faketime.c
@@ -45,12 +45,6 @@ static const char *date_cmd = "date";
/* semaphore and shared memory names */
char sem_name[PATH_BUFSIZE] = {0}, shm_name[PATH_BUFSIZE] = {0};
-/* This should match libfaketime.c */
-typedef struct {
- uint64_t counter;
- time_t starttime;
-} shared_data_t;
-
void usage(const char *name) {
printf("\n");
@@ -71,8 +65,7 @@ void usage(const char *name) {
printf("%s -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n", name);
printf("%s -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n", name);
printf("%s -f '+2,5y i2,0' /bin/bash -c 'date; while true; do date; sleep 1 ; done'\n", name);
- printf("%s -f '^2008-12-24 08:15:42' /bin/bash -c 'date; while true; do date; sleep 1 ; done'\n", name);
- printf("In the two latter cases all spawned processes will use the same global clock\n");
+ printf("In this single case all spawned processes will use the same global clock\n");
printf("without restaring it at the start of each process.\n\n");
printf("(Please note that it depends on your locale settings whether . or , has to be used for fractions)\n");
printf("\n");
@@ -168,7 +161,7 @@ int main (int argc, char **argv)
/* create semaphores and shared memory */
int shm_fd;
sem_t *sem;
- shared_data_t *ticks;
+ uint64_t *ticks;
char shared_objs[PATH_BUFSIZE];
snprintf(sem_name, PATH_BUFSIZE -1 ,"/faketime_sem_%d", getpid());
@@ -189,14 +182,14 @@ int main (int argc, char **argv)
}
/* set shm size */
- if (-1 == ftruncate(shm_fd, sizeof(shared_data_t))) {
+ if (-1 == ftruncate(shm_fd, sizeof(uint64_t))) {
perror("ftruncate");
cleanup_shobjs();
exit(EXIT_FAILURE);
}
/* map shm */
- if (MAP_FAILED == (ticks = mmap(NULL, sizeof(shared_data_t), PROT_READ|PROT_WRITE,
+ if (MAP_FAILED == (ticks = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE,
MAP_SHARED, shm_fd, 0))) {
perror("mmap");
cleanup_shobjs();
@@ -210,9 +203,8 @@ int main (int argc, char **argv)
}
/* init elapsed time ticks to zero */
- ticks->counter = 0;
- ticks->starttime = time(NULL);
- if (-1 == munmap(ticks, (sizeof(shared_data_t)))) {
+ *ticks = 0;
+ if (-1 == munmap(ticks, (sizeof(uint64_t)))) {
perror("munmap");
cleanup_shobjs();
exit(EXIT_FAILURE);
diff --git a/src/libfaketime.c b/src/libfaketime.c
index 6161f79..f709027 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -90,20 +90,11 @@ int fake_clock_gettime(clockid_t clk_id, struct timespec *tp);
*/
/**
- * When advancing time linearly with each time(), etc. call, or using
- * the "^" syntax, the shared_data_t structure holds the global
- * inter-process data. It is kept in shared memory and locked by the
- * ticks_sem semaphore. The definition of shared_data_t below should
- * be kept synchronized with the one in faketime.c (possibly to be put
- * in a header file) */
+ * When advancing time linearly with each time(), etc. call, the calls are
+ * counted in shared memory pointed at by ticks and protected by ticks_sem
+ * semaphore */
static sem_t *ticks_sem = NULL;
-
-typedef struct {
- uint64_t counter;
- time_t starttime;
-} shared_data_t;
-static shared_data_t *ticks = NULL;
-
+static uint64_t *ticks = NULL;
void ft_cleanup (void) __attribute__ ((destructor));
@@ -117,6 +108,7 @@ static void ft_shm_init (void)
printf("Error parsing semaphor name and shared memory id from string: %s", ft_shared);
exit(1);
}
+
if (SEM_FAILED == (ticks_sem = sem_open(sem_name, 0))) {
perror("sem_open");
exit(1);
@@ -126,7 +118,7 @@ static void ft_shm_init (void)
perror("shm_open");
exit(1);
}
- if (MAP_FAILED == (ticks = mmap(NULL, sizeof(shared_data_t), PROT_READ|PROT_WRITE,
+ if (MAP_FAILED == (ticks = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE,
MAP_SHARED, ticks_shm_fd, 0))) {
perror("mmap");
exit(1);
@@ -137,7 +129,7 @@ static void ft_shm_init (void)
void ft_cleanup (void)
{
/* detach from shared memory */
- munmap(ticks, sizeof(shared_data_t));
+ munmap(ticks, sizeof(uint64_t));
sem_close(ticks_sem);
}
@@ -153,7 +145,7 @@ static time_t next_time(double ticklen)
}
/* calculate and update elapsed time */
- ret = ticklen * (ticks->counter)++;
+ ret = ticklen * (*ticks)++;
/* unlock */
if (sem_post(ticks_sem) == -1) {
perror("sem_post");
@@ -653,8 +645,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
real_clock_gettime = dlsym(RTLD_NEXT, "__clock_gettime");
/* check whether dlsym() worked */
- /* Toni: the right-hand clause was necessary in fc17 x86 */
- if (dlerror() == NULL && real_clock_gettime ) {
+ if (dlerror() == NULL) {
has_real_clock_gettime = 1;
}
END_SINGLE_IF
@@ -683,13 +674,6 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
*/
static time_t ftpl_starttime = 0;
-/*
- * A guard variable to quench the action of fake_time in case it is
- * called by the shm system calls (e.g. sem_open calls __fxstat64 in
- * fc17 x86). (Toni)
- */
-static int in_constructor = 1;
-
void __attribute__ ((constructor)) ftpl_init(void)
{
time_t temp_tt;
@@ -702,7 +686,6 @@ void __attribute__ ((constructor)) ftpl_init(void)
#endif
ftpl_starttime = _ftpl_time(&temp_tt);
- in_constructor = 0;
}
static void remove_trailing_eols(char *line)
@@ -954,26 +937,12 @@ static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER;
/* Contributed by David North, TDI in version 0.7 */
case '@': /* Specific time, but clock along relative to that starttime */
- case '^': /* Specific time, but clock along relative to a starttime *shared* between processes */
user_faked_time_tm.tm_isdst = -1;
(void) strptime(&user_faked_time[1], user_faked_time_fmt, &user_faked_time_tm);
user_faked_time_time_t = mktime(&user_faked_time_tm);
if (user_faked_time_time_t != -1) {
-
- if (user_faked_time[0] == '@' || in_constructor ) {
- user_offset = - ( (long long int)ftpl_starttime - (long long int)user_faked_time_time_t );
- } else {
- /* Caret: specific time, relative to starttime, but shared among processes.
- * See comment to in_constructor. Contributed by Toni G.
- * Here: user_faked_time[0] == '^' && !in_constructor
- */
- if (!ticks_sem) {
- fprintf(stderr,"faketime problem: process-shared relative times require the faketime wrapper\n");
- exit(-1);
- }
- user_offset=- ( (long long int)ticks->starttime - (long long int)user_faked_time_time_t );
- }
+ user_offset = - ( (long long int)ftpl_starttime - (long long int)user_faked_time_time_t );
/* Speed-up / slow-down contributed by Karl Chen in v0.8 */
if (strchr(user_faked_time, 'x') != NULL) {
@@ -989,8 +958,6 @@ static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER;
*time_tptr += user_offset;
}
break;
-
-
}
#ifdef PTHREAD_SINGLETHREADED_TIME