time-sync: allow passing an arbitrary time.

During testing it can be useful to set an arbitrary (non-current) time on the
device. Extend time-sync to accept an additional (optional) parameter with the
time to set. Only changes date / time, no timezone.

Change-Id: Ib320777cb245cff19ca00b20540db3a43a4e488f
This commit is contained in:
Dominik Riebeling 2013-06-09 17:18:14 +02:00
parent 11280e20cc
commit 9574b30066
1 changed files with 19 additions and 5 deletions

View File

@ -16,6 +16,7 @@
*
*/
#define _XOPEN_SOURCE /* to enable strptime() */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@ -27,14 +28,27 @@ int
main (int argc, char **argv)
{
if (argc < 2) {
printf ("usage: %s <device>\n", basename(argv[0]));
return 1;
printf ("usage: %s <device> [time]\n", basename(argv[0]));
return 1;
}
if (sync_time (argv[1], NULL)) {
printf ("Error occured while syncing time.\n");
struct tm time;
struct tm* ptime = NULL;
if (argc > 2) {
if(strptime(argv[2], "%Y-%m-%dT%H:%M:%S", &time)) {
ptime = &time;
}
else {
printf ("Could not parse time. Using local time.\n");
printf ("Time string needs to use the format YYYY-MM-DDThh:mm:ss\n");
printf ("(ISO 8601 format)\n");
}
}
if (sync_time (argv[1], ptime)) {
printf ("Error occured while syncing time.\n");
} else {
printf ("Time was synced!\n");
printf ("Time was synced!\n");
}
return 0;