vboxadd_timesync.c revision e60b397fc7f34482960cc63f63db84d6a02226d1
/** @file
*
* VirtualBox timesync daemon for Linux
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <time.h>
#include <VBox/VBoxGuest.h>
static void usage(void)
{
printf("vboxadd-timesync [--interval <seconds>]\n"
" [--daemonize]\n");
}
{
struct timespec requestedSleepTime;
for (;;)
{
int err;
struct timespec remainingSleepTime;
if (err)
{
/* if the sleep was interrupted, remember remaining sleep time */
{
}
else
{
/* not good... */
}
}
else
{
/* nanosleep completed and took at least the requested time */
break;
}
}
}
{
{
};
int secInterval = 10;
int fDaemonize = 0;
int c, fd;
/* command line parsing */
for (;;)
{
if (c == -1)
break;
switch (c)
{
case 'i':
{
break;
}
case 'd':
{
fDaemonize = 1;
break;
}
case 'h':
{
usage();
return 0;
}
case ':':
case '?':
{
/* unrecognized option (?) or parameter missing (:) */
return 1;
}
default:
break;
}
}
/* open the driver */
if (fd < 0)
{
return 1;
}
/* prepare the request structure */
if (!fDaemonize)
printf("VirtualBox timesync daemon.\n"
"(C) 2008 Sun Microsystems, Inc.\n"
"\nSync interval: %d seconds.\n", secInterval);
if (fDaemonize)
daemon(1, 0);
do
{
/* perform VMM request */
{
{
/** Set the system time.
* @@todo r=frank: This is too choppy. Adapt time smoother and try
* to prevent negative time differences. */
}
else
{
}
}
else
{
}
/* wait for the next run */
} while (1);
return 0;
}