Override clock_gettime(2) called with CLOCK_REALTIME argument.
* datefudge.c: override clock_gettime(2) called with CLOCK_REALTIME
argument to make it possible to fake `date' command (closes: #416175).
* Update man page, add a simple example.
Robert Luberda
16 years ago
0 | /* | |
0 | /* vim:ts=4:sts=4:sw=4:et:cindent | |
1 | 1 | * datefudge.c: Twist system date back N seconds |
2 | 2 | * |
3 | 3 | * Copyright (C) 2001-2003, Matthias Urlichs <smurf@noris.de> |
4 | * | |
5 | * $Id: datefudge.c 10 2008-05-10 06:19:48Z robert $ | |
4 | 6 | */ |
5 | 7 | #define _GNU_SOURCE |
6 | 8 | |
16 | 18 | #include <time.h> |
17 | 19 | #include <sys/time.h> |
18 | 20 | |
19 | #define _NAME(foo) #foo | |
20 | #define NAME(foo) _NAME(foo) | |
21 | ||
22 | #if 0 | |
23 | #define N_open "open" | |
24 | #else | |
25 | #if __GLIBC_MINOR__ >= 1 | |
26 | #define N_open NAME(__libc_open) | |
27 | #else | |
28 | #define N_open NAME(__open) | |
29 | #endif | |
30 | #endif | |
31 | ||
32 | 21 | int fudge = 0; |
33 | 22 | |
34 | static void | |
35 | init_fudge (void) | |
36 | { | |
37 | const char *fud; | |
23 | static void init_fudge (void) { | |
24 | const char *fud; | |
38 | 25 | |
39 | if(fudge)return; | |
26 | if(fudge)return; | |
40 | 27 | |
41 | fud = getenv("DATEFUDGE"); | |
42 | if(fud == NULL) return; | |
43 | fudge = atoi(fud); | |
28 | fud = getenv("DATEFUDGE"); | |
29 | if(fud == NULL) return; | |
30 | fudge = atoi(fud); | |
44 | 31 | } |
45 | 32 | |
46 | 33 | /* |
50 | 37 | */ |
51 | 38 | |
52 | 39 | time_t time(time_t *x) { |
53 | static time_t (*libc_time)(time_t *) = NULL; | |
54 | time_t res; | |
40 | static time_t (*libc_time)(time_t *) = NULL; | |
41 | time_t res; | |
55 | 42 | |
56 | init_fudge(); | |
57 | if(!libc_time) | |
58 | libc_time = (typeof(libc_time))dlsym (RTLD_NEXT, NAME(time)); | |
59 | res = (*libc_time)(x); | |
60 | if(x) *x -= fudge; | |
61 | res -= fudge; | |
62 | return res; | |
43 | init_fudge(); | |
44 | if(!libc_time) | |
45 | libc_time = (typeof(libc_time))dlsym (RTLD_NEXT, __func__); | |
46 | res = (*libc_time)(x); | |
47 | if(x) *x -= fudge; | |
48 | res -= fudge; | |
49 | return res; | |
63 | 50 | } |
64 | 51 | |
65 | 52 | int __gettimeofday(struct timeval *x, struct timezone *y) { |
66 | static time_t (*libc_gettimeofday)(struct timeval *, struct timezone *) = NULL; | |
67 | int res; | |
53 | static int (*libc_gettimeofday)(struct timeval *, struct timezone *) = NULL; | |
54 | int res; | |
68 | 55 | |
69 | init_fudge(); | |
70 | if(!libc_gettimeofday) | |
71 | libc_gettimeofday = (typeof(libc_gettimeofday))dlsym (RTLD_NEXT, NAME(__gettimeofday)); | |
72 | res = (*libc_gettimeofday)(x,y); | |
73 | if(res) return res; | |
74 | x->tv_sec -= fudge; | |
75 | return 0; | |
56 | init_fudge(); | |
57 | if(!libc_gettimeofday) | |
58 | libc_gettimeofday = (typeof(libc_gettimeofday))dlsym (RTLD_NEXT, __func__); | |
59 | res = (*libc_gettimeofday)(x,y); | |
60 | if(res) return res; | |
61 | x->tv_sec -= fudge; | |
62 | return 0; | |
76 | 63 | } |
77 | int gettimeofday(struct timeval *x, struct timezone *y) | |
78 | { return __gettimeofday(x,y); } | |
79 | 64 | |
65 | int gettimeofday(struct timeval *x, struct timezone *y) { | |
66 | return __gettimeofday(x,y); | |
67 | } | |
68 | ||
69 | ||
70 | int clock_gettime(clockid_t x, struct timespec *y) { | |
71 | static int (*libc_clock_gettime)(clockid_t, struct timespec*); | |
72 | int res; | |
73 | ||
74 | init_fudge(); | |
75 | if (!libc_clock_gettime) | |
76 | libc_clock_gettime = (typeof(libc_clock_gettime))dlsym (RTLD_NEXT, __func__); | |
77 | res = (*libc_clock_gettime)(x,y); | |
78 | if (res || CLOCK_REALTIME != x) return res; | |
79 | y->tv_sec -= fudge; | |
80 | return 0; | |
81 | } | |
82 | ||
83 | ||
84 | ||
85 | ||
86 |
0 | .TH DATEFUDGE "1" "March 2003" "datefudge @VERSION@" M.Urlichs | |
0 | .\" vim:ft=nroff | |
1 | .TH DATEFUDGE "1" "May 10th, 2008" "datefudge @VERSION@" Debian | |
1 | 2 | .SH NAME |
2 | 3 | datefudge \- pretend the system time is different |
3 | 4 | .SH SYNOPSIS |
4 | .B datefudge | |
5 | \fIat_date program [arguments...]\fR | |
5 | \fBdatefudge\fR \fIat_date program\fR [\fIarguments\fR ...] | |
6 | 6 | .SH DESCRIPTION |
7 | .\" \fIdatefudge\fR pretends that the system time is different. | |
8 | 7 | .PP |
9 | This is done by pre-loading a small library which modifies the | |
10 | \fItime(2)\fR and \fIgettimeofday(2)\fR system calls. | |
8 | \fBdatefudge\fR is a small utility that pretends that the system time is different | |
9 | by pre-loading a small library which modifies the | |
10 | \fBtime\fR(2), \fBgettimeofday\fR(2) and \fBclock_gettime\fR(2) system calls. | |
11 | 11 | .SH OPTIONS |
12 | 12 | \fB\-\-help\fR |
13 | 13 | print short usage information and exit. |
14 | 14 | .TP |
15 | 15 | \fB\-\-version\fR |
16 | 16 | print version information and exit. |
17 | .SH EXAMPLE | |
18 | .nf | |
19 | \fI$ datefudge "2007\-04\-01 10:23" date \-R\fR | |
20 | Sun, 01 Apr 2007 10:23:00 +0200 | |
21 | .fi | |
17 | 22 | .SH AUTHOR |
18 | Written by Matthias Urlichs <smurf@noris.de> | |
23 | Written by Matthias Urlichs <smurf@noris.de>. Modified by | |
24 | Robert Luberda <robert@debian.org>. | |
19 | 25 | .SH BUGS |
20 | 26 | There is no attempt to make this change undetectable by the program. |
21 | 27 | In particular, file modification times are \fBnot\fR modified. |
22 | .SH "REPORTING BUGS" | |
23 | Send email to Matthias Urlichs <smurf@noris.de>. | |
28 | .\".SH "REPORTING BUGS" | |
29 | .\"Send email to Matthias Urlichs <smurf@noris.de>. | |
24 | 30 | .SH COPYRIGHT |
25 | 31 | Copyright \(co 2003 by Matthias Urlichs. |
26 | 32 | .PP |
30 | 36 | .br |
31 | 37 | For more information about these matters, see the file named COPYING. |
32 | 38 | .SH "SEE ALSO" |
33 | ld.so(1), time(2), gettimeofday(2) | |
39 | \fBld.so\fR(1), \fBtime\fR(2), \fBgettimeofday\fR(2), \fBclock_gettime\fR(2) |
0 | datefudge (1.14) UNRELEASED; urgency=low | |
0 | datefudge (1.14) unstable; urgency=low | |
1 | 1 | |
2 | 2 | * New maintainer (closes: #429467). |
3 | 3 | * Standards-Version: 3.7.3 (no changes). |
4 | 4 | * Use debhelper v7 and its minimised rules file. |
5 | * datefudge.c: override clock_gettime(2) called with CLOCK_REALTIME | |
6 | argument to make it possible to fake `date' command (closes: #416175). | |
7 | * Update man page, add a simple example. | |
5 | 8 | |
6 | -- Robert Luberda <robert@debian.org> Tue, 06 May 2008 22:20:52 +0200 | |
9 | -- Robert Luberda <robert@debian.org> Sat, 10 May 2008 08:21:02 +0200 | |
7 | 10 | |
8 | 11 | datefudge (1.13) unstable; urgency=low |
9 | 12 |
0 | README |