-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatchdog.c
127 lines (107 loc) · 3.02 KB
/
watchdog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <sys/time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include "watchdog.h"
extern long Watchdog_timeout;
extern long Net_timeout;
extern int Forwardtimer;
static timer_t Wtimer;
static struct itimerspec Wits;
static struct sigevent wsevent;// Dnt touch this. Why need static? - den.zavg
static timer_t Rtimer;
static struct itimerspec Rits;
static struct sigevent rsevent;// Dnt touch this. Why need static? - den.zavg
void
cre_timers() {
wsevent.sigev_notify = SIGEV_SIGNAL;
wsevent.sigev_signo = SIGALRM;
wsevent.sigev_value.sival_int = 1;
if (timer_create(CLOCK_REALTIME,&wsevent,&Wtimer) != 0) {
Perror("Cant create interval timer:");
Exit(1);
}
bzero(&Wits,sizeof(Wits));
rsevent.sigev_notify = SIGEV_SIGNAL;
rsevent.sigev_signo = SIGRTMIN;
rsevent.sigev_value.sival_int = 1;
if (timer_create(CLOCK_REALTIME,&rsevent,&Rtimer) != 0) {
Perror("Cant create interval timer:");
Exit(1);
}
bzero(&Rits,sizeof(Rits));
}
void
set_watch_dog (void) {
// struct itimerval iti;
// bzero(&iti,sizeof(iti));
// iti.it_value.tv_sec = Watchdog_timeout;
// if ((setitimer(ITIMER_REAL,&iti,NULL)) != 0) {
// Perror("Cant set Watch Dog interval timer.");
// Exit(1);
// }
Wits.it_value.tv_sec = Watchdog_timeout;
if (timer_settime(Wtimer,0,&Wits,NULL) != 0) {
Perror("Cant set Watch Dog interval timer:");
Exit(1);
}
}
void
set_read_timeout (void) {
Rits.it_value.tv_nsec = Forwardtimer * 5000000;
if (timer_settime(Rtimer,0,&Rits,NULL) != 0) {
Perror("Cant set interval timer for Forward_idle_timeout:");
Exit(1);
}
}
void
reset_read_timeout (void) {
Rits.it_value.tv_nsec = 0;
if (timer_settime(Rtimer,0,&Rits,NULL) != 0) {
Perror("Cant reset interval timer for Forward_idle_timeout:");
Exit(1);
}
}
void
set_net_timeout (void) {
// struct itimerval iti;
// bzero(&iti,sizeof(iti));
// iti.it_value.tv_sec = Net_timeout;
// if ((setitimer(ITIMER_REAL,&iti,NULL)) != 0) {
// Perror("Cant set interval timer.");
// Exit(1);
// }
Wits.it_value.tv_sec = Net_timeout;
if (timer_settime(Wtimer,0,&Wits,NULL) != 0) {
Perror("Cant set interval timer.");
Exit(1);
}
}
void
reset_timer (void) {
// struct itimerval iti;
// bzero(&iti,sizeof(iti));
// iti.it_value.tv_sec = 0;
// if ((setitimer(ITIMER_REAL,&iti,NULL)) != 0) {
// Perror("Cant reset interval timer.");
// Exit(1);
// }
Wits.it_value.tv_sec = 0;
if (timer_settime(Wtimer,0,&Wits,NULL) != 0) {
Perror("Cant reset interval timer.");
Exit(1);
}
}