Commit 8a564d12 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: added jmptime

Like adjtime (previous commit), this is used to adjust the local time,
but in this case the program performs a time jump (warp) using
settimeofday().
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent cfd8a834
......@@ -11,7 +11,7 @@ OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -Wall -ggdb -I../include/ppsi
PROGS = ptpdump adjtime
PROGS = ptpdump adjtime jmptime
all: $(PROGS)
......
/* CERN 2013 (author A. Rubini), part of the ppsi project, GPL v2 or later */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include "convert.h"
/*
* This is a simple tools to slightly change the system time, by jumping
* it forward or backward. Please see ./adjtime for a smooth update.
*/
int main(int argc, char **argv)
{
struct timeval tv, otv;
if (argc != 2) {
fprintf(stderr, "%s: use \"%s <delta>\"\n"
" <delta> is a floating-point number of seconds\n",
argv[0], argv[0]);
exit(1);
}
if (str_to_tv(argv[1], &tv) < 0) {
fprintf(stderr, "%s: not a time (float) number \"%s\"\n",
argv[0], argv[1]);
exit(1);
}
fprintf(stderr, "Requesting time-jump: %s seconds\n", tv_to_str(&tv));
if (gettimeofday(&otv, NULL) < 0) {
fprintf(stderr, "%s: gettimeofday(): %s\n", argv[0],
strerror(errno));
exit(1);
}
otv.tv_sec += tv.tv_sec;
otv.tv_usec += tv.tv_usec;
if (otv.tv_usec > 1000 * 1000) {
otv.tv_usec -= 1000 * 1000;
otv.tv_sec++;
}
if (settimeofday(&otv, NULL) < 0) {
fprintf(stderr, "%s: settimeofday(): %s\n", argv[0],
strerror(errno));
exit(1);
}
exit(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment