#include "raid_agent.h"

void SetTimer();

static struct itimerval itimer, old_itimer;

int main(int argc, char *argv[])
{
	pid_t pid;

	if (argc == 2 && strstr(argv[1], "-d")) {
		if ((pid = fork()) != 0)
			exit(0);
		setsid();
	}
	
	fprintf(stderr, "\n Calling iptrans_init() \n");
	iptrans_init();
	
	fprintf(stderr, "\n Calling snmp_init() \n");
	snmp_init(4957);
	
	raid_agent_init(0);
	
	SetTimer();
	while (1) {
		usleep(50);
	}
	return 1;
}

void SetTimer()
{
	struct sigaction act;
	act.sa_handler = raid_agent_timer;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	if (sigaction(SIGALRM, &act, NULL) < 0) 
	{
		perror("Produce Sigaction");
		exitLog("omcCleaner:SetTimer, sigaction function error");
		exit(1);
	}

	itimer.it_interval.tv_sec = 0;
	itimer.it_interval.tv_usec = 10 * 1000;
	itimer.it_value.tv_sec = 0;
	itimer.it_value.tv_usec = 10 * 1000;

	if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) 
	{
		printf("Setting Timer  error! \n");
		exitLog("omcCleaner:SetTimer, setitimer function error");
		exit(1);
	}
}
