Codebase list datefudge / 6ec6a8e
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
4 changed file(s) with 71 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
0 /*
0 /* vim:ts=4:sts=4:sw=4:et:cindent
11 * datefudge.c: Twist system date back N seconds
22 *
33 * Copyright (C) 2001-2003, Matthias Urlichs <smurf@noris.de>
4 *
5 * $Id: datefudge.c 10 2008-05-10 06:19:48Z robert $
46 */
57 #define _GNU_SOURCE
68
1618 #include <time.h>
1719 #include <sys/time.h>
1820
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
3221 int fudge = 0;
3322
34 static void
35 init_fudge (void)
36 {
37 const char *fud;
23 static void init_fudge (void) {
24 const char *fud;
3825
39 if(fudge)return;
26 if(fudge)return;
4027
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);
4431 }
4532
4633 /*
5037 */
5138
5239 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;
5542
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;
6350 }
6451
6552 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;
6855
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;
7663 }
77 int gettimeofday(struct timeval *x, struct timezone *y)
78 { return __gettimeofday(x,y); }
7964
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
12 .SH NAME
23 datefudge \- pretend the system time is different
34 .SH SYNOPSIS
4 .B datefudge
5 \fIat_date program [arguments...]\fR
5 \fBdatefudge\fR \fIat_date program\fR [\fIarguments\fR ...]
66 .SH DESCRIPTION
7 .\" \fIdatefudge\fR pretends that the system time is different.
87 .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.
1111 .SH OPTIONS
1212 \fB\-\-help\fR
1313 print short usage information and exit.
1414 .TP
1515 \fB\-\-version\fR
1616 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
1722 .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>.
1925 .SH BUGS
2026 There is no attempt to make this change undetectable by the program.
2127 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>.
2430 .SH COPYRIGHT
2531 Copyright \(co 2003 by Matthias Urlichs.
2632 .PP
3036 .br
3137 For more information about these matters, see the file named COPYING.
3238 .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
11
22 * New maintainer (closes: #429467).
33 * Standards-Version: 3.7.3 (no changes).
44 * 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.
58
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
710
811 datefudge (1.13) unstable; urgency=low
912
0 README