1/*
2 * Copyright 2004, ASUSTek Inc.
3 * All Rights Reserved.
4 *
5 * THIS SOFTWARE IS OFFERED "AS IS", AND ASUS GRANTS NO WARRANTIES OF ANY
6 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9 *
10 * $Id: ntp.c,v 1.1.1.1 2008/10/15 03:28:48 james26_jang Exp $
11 */
12
13#include <stdio.h>
14#include <signal.h>
15#include <time.h>
16#include <sys/time.h>
17#include <unistd.h>
18#include <stdlib.h>
19#include <sys/types.h>
20
21#include <bcmnvram.h>
22#include <shutils.h>
23#include <rc.h>
24#include <stdarg.h>
25
26static void catch_sig(int sig)
27{
28	if (sig == SIGUSR1)
29	{
30		//printf("SIGUSR1 catched\n");
31	}
32}
33
34int ntp_main(void)
35{
36	char servers[32];
37	//char *ntpclient_argv[] = {"ntpclient", "-h", servers, "-i", "3", "-l", "-s", NULL};
38	pid_t pid;
39	FILE *fp;
40	int ret;
41
42	strcpy(servers, nvram_safe_get("ntp_servers"));
43
44	if (!strlen(servers)) return 0;
45
46	fp=fopen("/var/run/ntp.pid","w");
47	if (fp==NULL) exit(0);
48	fprintf(fp, "%d", getpid());
49	fclose(fp);
50
51	signal(SIGUSR1, catch_sig);
52
53	while(1)
54	{
55		ret=eval("ntpclient", "-h", servers, "-i", "3", "-l", "-s");
56		pause();
57	}
58}
59