Example #1
0
static void ntp_service()
{
	static int first_sync = 1;

	if (first_sync) {
		first_sync = 0;

		nvram_set("reload_svc_radio", "1");
		nvram_set("svc_ready", "1");

		setup_timezone();

		if (is_routing_enabled())
			notify_rc("restart_upnp");
#ifdef RTCONFIG_IPV6
#ifdef RTCONFIG_WIDEDHCP6
/* switch to monotonic clock usage *//*
		if (get_ipv6_service() != IPV6_DISABLED) {
			notify_rc("restart_dhcp6s");
			notify_rc("restart_radvd");
		}
*/
#endif /* RTCONFIG_WIDEDHCP6 */
#endif
#ifdef RTCONFIG_DISK_MONITOR
		notify_rc("restart_diskmon");
#endif
	}
}
Example #2
0
int ntp_main(int argc, char *argv[])
{
	FILE *fp;
	int ret;

//	strcpy(servers, nvram_safe_get("ntp_servers"));
	strcpy(servers, nvram_safe_get("ntp_server0"));
	nvram_set("ntp_server_tried", servers);

	if (!strlen(servers))
		return 0;
	
	fp = fopen("/var/run/ntp.pid","w");
	if (fp == NULL)
		exit(0);
	fprintf(fp, "%d", getpid());
	fclose(fp);

	fprintf(stderr, "starting ntp...\n");

	signal(SIGTSTP, catch_sig);
	signal(SIGALRM, catch_sig);

	while (1)
	{
		ret = doSystem("ntpclient -h %s -i 3 -l -s &", servers);
		sleep(3);
		setup_timezone();
		
		// only dst_timezone 
		if(nvram_safe_get("time_zone_dst")){
			struct tm local;
			time_t now;
			int diff_sec;

			time(&now);
			localtime_r(&now, &local);
			//cprintf("%s: %d-%d-%d, %d:%d:%d dst:%d\n", __FUNCTION__, local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec, local.tm_isdst); //tmp test
	
			/* every hour */
			// 3597 = 3600 - 3, because of sleep(3)
			if((local.tm_min != 0) || (local.tm_sec != 0)){
				diff_sec = (3600-3) - (local.tm_min*60 + local.tm_sec);
				if(diff_sec == 0) diff_sec = 3597;
				//fprintf(stderr, "diff_sec: %d \n", diff_sec);
				alarm(diff_sec);
			}
			else{
				alarm(3597);
			}
		}

		pause();
	}	
}