示例#1
0
static void
ntpc_handler(void)
{
    int ntp_period = nvram_get_int("ntp_period");

    if (ntp_period < 1)
        return;

    if (ntp_period > 336)
        ntp_period = 336; // max two weeks

    ntp_period = ntp_period * 360;

    // update ntp every period time
    ntpc_timer = (ntpc_timer + 1) % ntp_period;
    if (ntpc_timer == 0) {
        setenv_tz();
        refresh_ntp();
    } else if (!is_ntpc_updated()) {
        int ntp_skip = 3;	// update every 30s

        ntpc_tries++;
        if (ntpc_tries > 60)
            ntp_skip = 30;	// update every 5m
        else if (ntpc_tries > 9)
            ntp_skip = 6;	// update every 60s

        if (!(ntpc_tries % ntp_skip))
            refresh_ntp();
    }
}
示例#2
0
static void 
ntpc_handler(void)
{
	time_t now;
	int ntp_period;
	struct tm local;
	static int ntp_first_tryes = 12; // try 12 times every 10 sec

	ntp_period = nvram_get_int("ntp_period");
	if (ntp_period < 1) ntp_period = 1;
	if (ntp_period > 336) ntp_period = 336; // two weeks
	ntp_period = ntp_period * 360;

	// update ntp every period time
	ntpc_timer = (ntpc_timer + 1) % ntp_period;
	if (ntpc_timer == 0)
	{
		refresh_ntp();
	}
	else if (ntp_first_tryes > 0)
	{
		time(&now);
		localtime_r(&now, &local);
		
		/* Less than 2012 */
		if (local.tm_year < (2012-1900))
		{
			refresh_ntp();
			ntp_first_tryes--;
		}
		else
		{
			ntp_first_tryes = 0;
			logmessage("NTP Scheduler", "System time changed.");
		}
	}
}