faketime-0.2.2/000075500000000000000000000000001110145017400132705ustar00rootroot00000000000000faketime-0.2.2/.gitignore000064400000000000000000000003021110145017400152530ustar00rootroot00000000000000*.1 *.la *.lo *.o *.tar.* .deps .libs COPYING INSTALL Makefile Makefile.in aclocal.m4 autom4te.cache config.* configure depcomp doc faketime install-sh lib libtool ltmain.sh m4 missing stamp-h1 faketime-0.2.2/.indent.pro000064400000000000000000000002151110145017400153470ustar00rootroot00000000000000-bad -bap -bbb -nbc -bbo -bl -bli0 -bls -ce -cdw -cli8 -cs -di8 -nfc1 -nfca -i8 -lp -saf -sai -saw -sob -ss -pcs -nprs -psl -ts8 -npcs -cbi0 faketime-0.2.2/AUTHORS000064400000000000000000000000201110145017400143300ustar00rootroot00000000000000Dmitry V. Levin faketime-0.2.2/ChangeLog000064400000000000000000000000741110145017400150430ustar00rootroot00000000000000http://git.altlinux.org/people/ldv/packages/?p=faketime.git faketime-0.2.2/Makefile.am000064400000000000000000000032131110145017400153230ustar00rootroot00000000000000# Copyright (C) 2005 Dmitry V. Levin # # Makefile for the faketime project. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. SUBDIRS = lib WARNINGS = -W -Wall -Waggregate-return -Wcast-align -Wconversion \ -Wdisabled-optimization -Wmissing-declarations \ -Wmissing-format-attribute -Wmissing-noreturn \ -Wmissing-prototypes -Wpointer-arith -Wshadow \ -Wstrict-prototypes -Wwrite-strings -Werror ACLOCAL_AMFLAGS = -I m4 AM_CFLAGS = -std=gnu99 $(WARNINGS) AM_LDFLAGS = -no-undefined -avoid-version -module \ -export-symbols $(top_srcdir)/plugin.sym -ldl INCLUDES = -I$(top_srcdir)/lib lib_LTLIBRARIES = faketime.la faketime_la_SOURCES = plugin.c bin_PROGRAMS = faketime faketime_SOURCES = util.c faketime_LDADD = $(top_builddir)/lib/libgnu.la @LIB_CLOCK_GETTIME@ man_MANS = faketime.1 HELP2MAN1 = help2man -N -s1 %.1: % %.1.inc $(HELP2MAN1) --include=$(top_srcdir)/$<.1.inc $(top_builddir)/$< --output=$@ EXTRA_DIST = faketime.1.inc faketime.spec plugin.sym CLEANFILES = $(man_MANS) *~ faketime-0.2.2/NEWS000064400000000000000000000000001110145017400137550ustar00rootroot00000000000000faketime-0.2.2/README000064400000000000000000000001231110145017400141440ustar00rootroot00000000000000The faketime utility helps to execute programs with changed notion of system time. faketime-0.2.2/configure.ac000064400000000000000000000020441110145017400155560ustar00rootroot00000000000000dnl Copyright (C) 2005,2008 Dmitry V. Levin dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by dnl the Free Software Foundation; either version 2 of the License, or dnl (at your option) any later version. dnl This program is distributed in the hope that it will be useful, dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl You should have received a copy of the GNU General Public License dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. AC_INIT([faketime],[0.2.1],[ldv@altlinux.org]) AC_CONFIG_SRCDIR([plugin.c]) AM_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) AC_PROG_CC gl_EARLY gl_INIT AC_DISABLE_STATIC AC_PROG_LIBTOOL AC_CONFIG_FILES([Makefile lib/Makefile]) AC_OUTPUT faketime-0.2.2/faketime.1.inc000064400000000000000000000017471110145017400157200ustar00rootroot00000000000000.\" Copyright (C) 2005 Dmitry V. Levin .\" .\" Additional documentation for the faketime command. .\" .\" This file is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or .\" (at your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with this program; if not, write to the Free Software .\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. [NAME] \fBfaketime\fR \- execute program with changed notion of system time [SEE ALSO] .BR date (1), .BR touch (1), info "\fBDate input formats\fR". faketime-0.2.2/faketime.spec000064400000000000000000000020231110145017400157260ustar00rootroot00000000000000Name: faketime Version: 0.2.2 Release: alt1 Summary: Execute program with changed notion of system time License: GPL Group: Development/Other Packager: Dmitry V. Levin Source: faketime-%version.tar Source1: gnulib.tar BuildPreReq: help2man %description The faketime utility helps to execute programs with changed notion of system time. %prep %setup -q -a1 ./gnulib.sh gnulib sed -i 's/return (/return (int)(/' lib/timespec.h %build autoreconf -fisv %configure %make_build %install %makeinstall rm %buildroot%_libdir/*.la %files %_bindir/* %_libdir/*.so %_man1dir/* %changelog * Tue Oct 28 2008 Dmitry V. Levin 0.2.2-alt1 - Fixed build with fresh gcc. * Sat Aug 30 2008 Dmitry V. Levin 0.2.1-alt1 - Updated gnulib. * Sun Apr 15 2007 Dmitry V. Levin 0.2-alt1 - Changed option processing to stop after the first non-option argument (at). - Fixed to build with current gnulib. * Thu Dec 15 2005 Dmitry V. Levin 0.1-alt1 - Initial revision. faketime-0.2.2/gnulib.sh000075500000000000000000000005311110145017400151060ustar00rootroot00000000000000#!/bin/sh -e fatal() { printf %s\\n "${0##*/}: $*" >&2 exit 1 } [ $# -eq 1 ] || fatal 'Please specify the name of the directory containing gnulib' [ -d "$1" ] || fatal "$1 is not a directory" tool="$1/gnulib-tool" [ -f "$tool" -a -x "$tool" ] || fatal "$tool is not available" mkdir -p doc lib m4 "$tool" --import --dir=. getdate posixtm faketime-0.2.2/plugin.c000064400000000000000000000114761110145017400147430ustar00rootroot00000000000000/* Copyright (C) 2005, 2008 Dmitry V. Levin The faketime plugin. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include #include #include #include #include #ifndef HAVE__THREAD #define __thread #endif static int debug = 0; static __thread sig_atomic_t recursion = 0; static time_t time_abs = 0, time_off = 0; static void __attribute__ ((constructor)) init_sym(void) { const char *name = "FAKETIME"; const char *value = getenv(name) ? : ""; char *p = 0; unsigned long n; time_t t = 0; if (!*value) { fprintf(stderr, "%s: %s\n", name, strerror(EINVAL)); exit(1); } errno = 0; n = strtoul(value, &p, 10); if (!p || *p) errno = EINVAL; else { t = (time_t) n; if ((unsigned long) t != n) errno = ERANGE; } if (!p || *p || (n == ULONG_MAX && errno == ERANGE) || ((unsigned long) t != n)) { fprintf(stderr, "%s: %s: %s\n", name, value, strerror(errno)); exit(1); } if (value[0] == '-' || value[0] == '+') time_off = (time_t) t; else time_abs = (time_t) t; } static void *load_sym(const char *name) { void *addr; const char *msg; (void) dlerror(); addr = dlsym(RTLD_NEXT, name); if ((msg = dlerror())) { fprintf(stderr, "dlsym(%s): %s\n", name, msg); abort(); } return addr; } void debug_printf(const char *, ...) __attribute__ ((__format__(__printf__, 1, 2))); void __attribute__ ((__format__(__printf__, 1, 2))) debug_printf(const char *fmt, ...) { va_list args; if (!debug) return; va_start(args, fmt); (void) vfprintf(stderr, fmt, args); va_end(args); } time_t time(time_t *t) { static time_t (*next_time) (time_t *); time_t rc; if (!next_time) next_time = load_sym("time"); debug_printf("time(%p) = <", t); ++recursion; rc = next_time(t); --recursion; debug_printf("%lu>\n", (unsigned long) rc); if (rc == (time_t) - 1) return rc; if (!recursion) { debug_printf("time: %lu -> ", (unsigned long) rc); if (time_off) { rc += time_off; } else if (time_abs) { rc = time_abs; } debug_printf("%lu\n", (unsigned long) rc); } if (t) *t = rc; return rc; } int ftime(struct timeb *tp) { static int (*next_ftime) (struct timeb *); int rc; if (!next_ftime) next_ftime = load_sym("ftime"); debug_printf("ftime(%p) = <", tp); ++recursion; rc = next_ftime(tp); --recursion; debug_printf("%d>\n", rc); if (rc) return rc; if (!recursion && tp) { debug_printf("ftime: %lu -> ", (unsigned long) tp->time); if (time_off) { tp->time += time_off; } else if (time_abs) { tp->time = time_abs; tp->millitm = 0; } debug_printf("%lu\n", (unsigned long) tp->time); } return rc; } int gettimeofday(struct timeval *tv, struct timezone *tz) { static int (*next_gettimeofday) (struct timeval *, struct timezone *); int rc; if (!next_gettimeofday) next_gettimeofday = load_sym("gettimeofday"); debug_printf("gettimeofday(%p, %p) = <", tv, tz); ++recursion; rc = next_gettimeofday(tv, tz); --recursion; debug_printf("%d>\n", rc); if (rc) return rc; if (!recursion && tv) { debug_printf("gettimeofday: %lu -> ", (unsigned long) tv->tv_sec); if (time_off) { tv->tv_sec += time_off; } else if (time_abs) { tv->tv_sec = time_abs; tv->tv_usec = 0; } debug_printf("%lu\n", (unsigned long) tv->tv_sec); } return rc; } int clock_gettime(clockid_t clk_id, struct timespec *tp) { static int (*next_clock_gettime) (clockid_t, struct timespec *); int rc; if (!next_clock_gettime) next_clock_gettime = load_sym("clock_gettime"); debug_printf("clock_gettime(%d, %p) = <", clk_id, tp); ++recursion; rc = next_clock_gettime(clk_id, tp); --recursion; debug_printf("%d>\n", rc); if (rc || clk_id != CLOCK_REALTIME) return rc; if (!recursion && tp) { debug_printf("clock_gettime: %lu -> ", (unsigned long) tp->tv_sec); if (time_off) { tp->tv_sec += time_off; } else if (time_abs) { tp->tv_sec = time_abs; tp->tv_nsec = 0; } debug_printf("%lu\n", (unsigned long) tp->tv_sec); } return rc; } faketime-0.2.2/plugin.sym000064400000000000000000000000461110145017400153200ustar00rootroot00000000000000time ftime gettimeofday clock_gettime faketime-0.2.2/util.c000064400000000000000000000120471110145017400144150ustar00rootroot00000000000000/* Copyright (C) 2005 Dmitry V. Levin The faketime utility. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include #include #include "getdate.h" #include "posixtm.h" #include "timespec.h" static void __attribute__ ((noreturn)) show_usage(const char *str) { if (str) fprintf(stderr, "%s: %s\n", program_invocation_short_name, str); fprintf(stderr, "Try `%s --help' for more information.\n", program_invocation_short_name); exit(EXIT_FAILURE); } static void __attribute__ ((noreturn)) print_version(void) { printf("%s", PACKAGE_STRING "\n" "\nCopyright (C) 2005 Dmitry V. Levin \n" "\nThis is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "\nWritten by Dmitry V. Levin \n"); exit(EXIT_SUCCESS); } static void __attribute__ ((noreturn)) print_help(void) { printf("Execute program with changed notion of system time.\n" "\nUsage: %s [options] ...\n" "\nValid options are:\n" " -d STRING:\n" " use time described by STRING\n" " -r FILE:\n" " use the last modification time of FILE\n" " -t STAMP:\n" " use timestamp in [[CC]YY]MMDDhhmm[.ss] format\n" " -i:\n" " do not freeze the time, increment it in usual way\n" " -V, --version:\n" " print program version and exit\n" " -h, --help:\n" " print this help text and exit\n" "\nTime specifications for the -d and -t options have\n" "the same format as in date(1) and touch(1) utilities.\n", program_invocation_short_name); exit(EXIT_SUCCESS); } static char const short_options[] = "+d:r:t:iVh"; static struct option const long_options[] = { {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; int main(int ac, char **av) { int optc; int relative = 0; struct timespec now, when; const char *d_str = 0, *r_str = 0, *t_str = 0; const char *preload; char *env; if (ac < 2) show_usage("insufficient arguments"); while ((optc = getopt_long(ac, av, short_options, long_options, NULL)) != -1) { switch (optc) { case 'd': d_str = optarg; break; case 'r': r_str = optarg; break; case 't': t_str = optarg; break; case 'i': relative = 1; break; case 'V': print_version(); break; case 'h': print_help(); break; default: show_usage(NULL); break; } } if (optind >= ac) show_usage("insufficient arguments"); if (t_str && (r_str || d_str)) show_usage("cannot specify times from more than one source"); gettime(&now); memset(&when, 0, sizeof when); if (t_str) { if (!posixtime (&when.tv_sec, t_str, PDS_LEADING_YEAR | PDS_CENTURY | PDS_SECONDS)) error(EXIT_FAILURE, 0, "%s: invalid date format", t_str); } else if (r_str) { struct stat stb; if (stat(r_str, &stb)) error(EXIT_FAILURE, errno, "%s: failed to get attributes", r_str); when.tv_sec = stb.st_mtime; if (d_str && !get_date(&when, d_str, &when)) error(EXIT_FAILURE, 0, "%s: invalid date format", d_str); } else if (d_str) { if (!get_date(&when, d_str, NULL)) error(EXIT_FAILURE, 0, "%s: invalid date format", d_str); } else show_usage("no time source specified"); if (relative) { if (asprintf (&env, "%+ld", (long) when.tv_sec - (long) now.tv_sec) < 0) error(EXIT_FAILURE, errno, "asprintf"); } else { if (asprintf(&env, "%lu", (unsigned long) when.tv_sec) < 0) error(EXIT_FAILURE, errno, "asprintf"); } if (setenv("FAKETIME", env, 1)) error(EXIT_FAILURE, errno, "putenv"); free(env); if ((preload = getenv("LD_PRELOAD"))) { if (asprintf(&env, "%s:%s", "faketime.so", preload) < 0) error(EXIT_FAILURE, errno, "asprintf"); if (setenv("LD_PRELOAD", env, 1)) error(EXIT_FAILURE, errno, "putenv"); free(env); } else { if (setenv("LD_PRELOAD", "faketime.so", 1)) error(EXIT_FAILURE, errno, "putenv"); } execvp(av[optind], (char *const *) av + optind); error(EXIT_FAILURE, errno, "execvp: %s", av[optind]); return EXIT_FAILURE; }