源代码:
/*snmp_alarm.c*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "snmp_alarm.h"
#define SNMP_MALLOC_STRUCT(s) (struct s *) calloc(1, sizeof(struct s))
static struct snmp_alarm *thealarms = NULL;
static int start_alarms = 0;
static unsigned int regnum = 1;
int init_alarm_post_config()
{
start_alarms = 1;
set_an_alarm();
return 0;
}
void sa_update_entry(struct snmp_alarm *a)
{
if(a->t_last.tv_sec == 0 && a->t_last.tv_usec == 0) {
struct timeval t_now;
/*
* Never been called yet, call time `t' from now.
*/
gettimeofday(&t_now, NULL);
a->t_last.tv_sec = t_now.tv_sec;
a->t_last.tv_usec = t_now.tv_usec;
a->t_next.tv_sec = t_now.tv_sec + a->t.tv_sec;
a->t_next.tv_usec = t_now.tv_usec + a->t.tv_usec;
while(a->t_next.tv_usec >= 1000000) {
a->t_next.tv_usec -= 1000000;
a->t_next.tv_sec += 1;
}
}
else if(a->t_next.tv_sec == 0 && a->t_next.tv_usec == 0) {
/*
* We've been called but not reset for the next call.
*/
if(a->flags & SA_REPEAT) {
if(a->t.tv_sec == 0 && a->t.tv_usec == 0) {
printf("update_entry: illegal interval specified\n");
snmp_alarm_unregister(a->clientreg);
return;
}
a->t_next.tv_sec = a->t_last.tv_sec + a->t.tv_sec;
a->t_next.tv_usec = a->t_last.tv_usec + a->t.tv_usec;
while(a->t_next.tv_usec >= 1000000) {
a->t_next.tv_usec -= 1000000;
a->t_next.tv_sec += 1;
}
}
else {
/*
* Single time call, remove it.
*/
snmp_alarm_unregister(a->clientreg);
}
}
}
void snmp_alarm_unregister(unsigned int clientreg