pax_global_header00006660000000000000000000000064121333513370014513gustar00rootroot0000000000000052 comment=43dd6c008db6c4298de1a52f0841f5bf0f0dc110 faketime-0.2.5/000075500000000000000000000000001213335133700133025ustar00rootroot00000000000000faketime-0.2.5/.gear/000075500000000000000000000000001213335133700142765ustar00rootroot00000000000000faketime-0.2.5/.gear/rules000064400000000000000000000000071213335133700153500ustar00rootroot00000000000000tar: . faketime-0.2.5/AUTHORS000064400000000000000000000000201213335133700143420ustar00rootroot00000000000000Dmitry V. Levin faketime-0.2.5/ChangeLog000064400000000000000000000001201213335133700150450ustar00rootroot00000000000000http://git.altlinux.org/people/ldv/packages/?p=faketime.git;a=shortlog;h=master faketime-0.2.5/Makefile.am000064400000000000000000000031331213335133700153360ustar00rootroot00000000000000# Copyright (C) 2005-2013 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, see . SUBDIRS = lib gnulib-tests 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/libfaketime.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.5/NEWS000064400000000000000000000000001213335133700137670ustar00rootroot00000000000000faketime-0.2.5/README000064400000000000000000000001231213335133700141560ustar00rootroot00000000000000The faketime utility helps to execute programs with changed notion of system time. faketime-0.2.5/bootstrap.conf000064400000000000000000000003111213335133700161610ustar00rootroot00000000000000# gnulib modules used by this package. gnulib_modules=' git-version-gen parse-datetime posixtm ' gnulib_tool_option_extras="--tests-base=gnulib-tests --with-tests --symlink --makefile-name=gnulib.mk" faketime-0.2.5/configure.ac000064400000000000000000000021671213335133700155760ustar00rootroot00000000000000dnl Copyright (C) 2005-2013 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, see . AC_INIT([faketime], m4_esyscmd([build-aux/git-version-gen .tarball-version]), [ldv@altlinux.org]) AC_CONFIG_SRCDIR([plugin.c]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([lib/config.h:lib/config.hin]) 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 gnulib-tests/Makefile]) AC_OUTPUT faketime-0.2.5/faketime.1.inc000064400000000000000000000016441213335133700157260ustar00rootroot00000000000000.\" Copyright (C) 2005-2013 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, see . [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.5/faketime.spec000064400000000000000000000032721213335133700157470ustar00rootroot00000000000000Name: faketime Version: 0.2.5 Release: alt1 Summary: Execute program with changed notion of system time License: GPLv3+ Group: Development/Other # git://git.altlinux.org/gears/f/faketime.git Source: %name-%version.tar BuildRequires: help2man, gnulib >= 0.0.7902.92f3a4c %description The faketime utility helps to execute programs with changed notion of system time. %prep %setup install -pm755 %_datadir/gnulib/build-aux/bootstrap . echo -n %version > .tarball-version mkdir build-aux # remove timespectod() to avoid compilation warnings in unused code. sed '/Return an approximation/,/}$/d' < %_datadir/gnulib/lib/timespec.h > timespec.h %build ./bootstrap --gnulib-srcdir=%_datadir/gnulib --no-git --skip-po --force %configure %make_build %install %makeinstall_std rm %buildroot%_libdir/*.la %check %make_build -k check %files %_bindir/* %_libdir/*.so %_man1dir/* %changelog * Wed Apr 17 2013 Dmitry V. Levin 0.2.5-alt1 - Converted from getdate to parse_datetime gnulib module. - Enabled gnulib testsuite. - Built with system gnulib v0.0.7902-g92f3a4c. * Sun Nov 20 2011 Dmitry V. Levin 0.2.4-alt1 - Updated gnulib to v0.0-6453-g6a4c64c. * Fri Feb 12 2010 Dmitry V. Levin 0.2.3-alt1 - Updated to fresh gnulib. * 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.5/gnulib-tests/000075500000000000000000000000001213335133700157225ustar00rootroot00000000000000faketime-0.2.5/gnulib-tests/Makefile.am000064400000000000000000000000221213335133700177500ustar00rootroot00000000000000include gnulib.mk faketime-0.2.5/lib/000075500000000000000000000000001213335133700140505ustar00rootroot00000000000000faketime-0.2.5/lib/Makefile.am000064400000000000000000000001521213335133700161020ustar00rootroot00000000000000MOSTLYCLEANFILES= noinst_LTLIBRARIES= BUILT_SOURCES= EXTRA_DIST= MAINTAINERCLEANFILES= include gnulib.mk faketime-0.2.5/plugin.c000064400000000000000000000113651213335133700147520ustar00rootroot00000000000000/* Copyright (C) 2005-2013 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, see . */ #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.5/plugin.sym000064400000000000000000000000461213335133700153320ustar00rootroot00000000000000time ftime gettimeofday clock_gettime faketime-0.2.5/util.c000064400000000000000000000117671213335133700144370ustar00rootroot00000000000000/* Copyright (C) 2005-2013 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, see . */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include #include #include "parse-datetime.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 && !parse_datetime(&when, d_str, &when)) error(EXIT_FAILURE, 0, "%s: invalid date format", d_str); } else if (d_str) { if (!parse_datetime(&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; }