Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

int main ( int  argc,
char *  argv[] 
)

Set the system time. @todo r=frank: This is too choppy. Adapt time smoother and try to prevent negative time differences.

Definition at line 71 of file vboxadd_timesync.c.

References IOCTL_VBOXGUEST_VMMREQUEST, NULL, and VBOX_SUCCESS.

Referenced by QIMessageBox::QIMessageBox().

{
    const struct option options[] =
    {
        { "interval",  required_argument, NULL, 'i' },
        { "daemonize", no_argument,       NULL, 'd' },
        { "help",      no_argument,       NULL, 'h' },
        { NULL,        0,                 NULL, 0   }
    };
    int secInterval = 10;
    int fDaemonize = 0;
    int c, fd;
    VMMDevReqHostTime req;

    /* command line parsing */
    for (;;)
    {
        c = getopt_long(argc, argv, "", options, NULL);
        if (c == -1)
            break;
        switch (c)
        {
            case 'i':
            {
                secInterval = atoi(optarg);
                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 */
    fd = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
    if (fd < 0)
    {
        printf("Error opening kernel module! rc = %d\n", errno);
        return 1;
    }

    /* prepare the request structure */
    vmmdevInitRequest((VMMDevRequestHeader*)&req, VMMDevReq_GetHostTime);

    if (!fDaemonize)
        printf("VirtualBox timesync daemon.\n"
               "(C) 2005-2008 innotek GmbH\n"
               "\nSync interval: %d seconds.\n", secInterval);

    if (fDaemonize)
        daemon(1, 0);

    do
    {
        /* perform VMM request */
        if (ioctl(fd, IOCTL_VBOXGUEST_VMMREQUEST, (void*)&req) >= 0)
        {
            if (VBOX_SUCCESS(req.header.rc))
            {
                /** Set the system time.
                 *  @@todo r=frank: This is too choppy. Adapt time smoother and try
                 *                  to prevent negative time differences. */
                struct timeval tv;
                tv.tv_sec  =  req.time / (uint64_t)1000;
                tv.tv_usec = (req.time % (uint64_t)1000) * 1000;
                settimeofday(&tv, NULL);
            }
            else
            {
                printf("Error querying host time! header.rc = %d\n", req.header.rc);
            }
        }
        else
        {
            printf("Error performing VMM request! errno = %d\n", errno);
        }
          /* wait for the next run */
        safe_sleep(secInterval);

    } while (1);

    close(fd);

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index