adjtime.c 1.02 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) 2013 CERN (www.cern.ch)
 * Author: Alessandro Rubini
 *
 * Released according to the GNU GPL, version 2 or any later version.
 */
Alessandro Rubini's avatar
Alessandro Rubini committed
7 8 9 10 11 12 13 14 15 16

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include "convert.h"

/*
17
 * This is a simple tool to slightly change the system time, in order
Alessandro Rubini's avatar
Alessandro Rubini committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 * to check when (and how) PTP resynchronizes it
 */

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 adjustment: %s seconds\n", tv_to_str(&tv));
	if (adjtime(&tv, &otv) < 0) {
		fprintf(stderr, "%s: adjtime(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	fprintf(stderr, "Previous adjustment: %s seconds\n", tv_to_str(&otv));
	exit(0);
}