Deleted Added
full compact
timer.c (37192) timer.c (41799)
1/*
2 * PPP Timer Processing Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Timer Processing Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: timer.c,v 1.30 1998/06/20 01:36:38 brian Exp $
20 * $Id: timer.c,v 1.31 1998/06/27 14:18:11 brian Exp $
21 *
22 * TODO:
23 */
24
21 *
22 * TODO:
23 */
24
25#include <errno.h>
25#include <signal.h>
26#include <stdio.h>
27#include <sys/time.h>
28#include <termios.h>
29
30#include "log.h"
31#include "sig.h"
32#include "timer.h"

--- 58 unchanged lines hidden (view full) ---

91 else
92 log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p]\n", tp->name, tp);
93
94 /* Insert given *tp just before *t */
95 tp->next = t;
96 if (pt) {
97 pt->next = tp;
98 } else {
26#include <signal.h>
27#include <stdio.h>
28#include <sys/time.h>
29#include <termios.h>
30
31#include "log.h"
32#include "sig.h"
33#include "timer.h"

--- 58 unchanged lines hidden (view full) ---

92 else
93 log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p]\n", tp->name, tp);
94
95 /* Insert given *tp just before *t */
96 tp->next = t;
97 if (pt) {
98 pt->next = tp;
99 } else {
99 timer_InitService();
100 TimerList = tp;
100 TimerList = tp;
101 timer_InitService(0); /* Start the Timer Service */
101 }
102 if (t)
103 t->rest -= tp->rest;
104
105 sigsetmask(omask);
106}
107
108static void

--- 29 unchanged lines hidden (view full) ---

138
139 tp->next = NULL;
140 tp->state = TIMER_STOPPED;
141}
142
143static void
144TimerService(void)
145{
102 }
103 if (t)
104 t->rest -= tp->rest;
105
106 sigsetmask(omask);
107}
108
109static void

--- 29 unchanged lines hidden (view full) ---

139
140 tp->next = NULL;
141 tp->state = TIMER_STOPPED;
142}
143
144static void
145TimerService(void)
146{
146 struct pppTimer *tp, *exp, *wt;
147 struct pppTimer *tp, *exp, *next;
147
148 if (log_IsKept(LogTIMER)) {
149 static time_t t; /* Only show timers globally every second */
150 time_t n = time(NULL);
151
152 if (n > t)
153 timer_Show(LogTIMER, NULL);
154 t = n;
155 }
148
149 if (log_IsKept(LogTIMER)) {
150 static time_t t; /* Only show timers globally every second */
151 time_t n = time(NULL);
152
153 if (n > t)
154 timer_Show(LogTIMER, NULL);
155 t = n;
156 }
157
156 tp = TimerList;
157 if (tp) {
158 tp = TimerList;
159 if (tp) {
158 tp->rest--;
159 if (tp->rest == 0) {
160 tp->rest = 0;
160
161
161 /*
162 * Multiple timers may expires at once. Create list of expired timers.
163 */
164 exp = NULL;
165 do {
166 tp->state = TIMER_EXPIRED;
167 wt = tp->next;
168 tp->enext = exp;
169 exp = tp;
170 tp = wt;
171 } while (tp && (tp->rest == 0));
172
173 TimerList = tp;
174 if (TimerList == NULL) /* No timers ? */
175 timer_TermService(); /* Terminate Timer Service */
176
177 /*
178 * Process all expired timers.
179 */
180 while (exp) {
181#ifdef notdef
182 timer_Stop(exp);
183#endif
184 if (exp->func)
185 (*exp->func) (exp->arg);
186
187 /*
188 * Just Removing each item from expired list And exp->enext will be
189 * intialized at next expire in this funtion.
190 */
191 exp = exp->enext;
192 }
162 /* Multiple timers might expire at once. Create a list of expired timers */
163 exp = NULL;
164 do {
165 tp->state = TIMER_EXPIRED;
166 next = tp->next;
167 tp->enext = exp;
168 exp = tp;
169 tp = next;
170 } while (tp && tp->rest == 0);
171
172 TimerList = tp;
173 if (TimerList != NULL) /* Any timers remaining ? */
174 timer_InitService(1); /* Restart the Timer Service */
175 else
176 timer_TermService(); /* Stop the Timer Service */
177
178 /* Process all expired timers */
179 while (exp) {
180 next = exp->enext;
181 exp->enext = NULL;
182 if (exp->func)
183 (*exp->func)(exp->arg);
184 exp = next;
193 }
194 }
195}
196
197void
198timer_Show(int LogLevel, struct prompt *prompt)
199{
200 struct pppTimer *pt;

--- 17 unchanged lines hidden (view full) ---

218 log_Printf(LogLevel, DISP);
219 }
220
221 if (!prompt)
222 log_Printf(LogLevel, "---- End of Timer Service List ---\n");
223}
224
225void
185 }
186 }
187}
188
189void
190timer_Show(int LogLevel, struct prompt *prompt)
191{
192 struct pppTimer *pt;

--- 17 unchanged lines hidden (view full) ---

210 log_Printf(LogLevel, DISP);
211 }
212
213 if (!prompt)
214 log_Printf(LogLevel, "---- End of Timer Service List ---\n");
215}
216
217void
226timer_InitService()
218timer_InitService(int restart)
227{
228 struct itimerval itimer;
229
219{
220 struct itimerval itimer;
221
230 sig_signal(SIGALRM, (void (*) (int)) TimerService);
231 itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
232 itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
233 if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
234 log_Printf(LogERROR, "Unable to set itimer.\n");
222 if (TimerList) {
223 if (!restart)
224 sig_signal(SIGALRM, (void (*)(int))TimerService);
225 itimer.it_interval.tv_sec = 0;
226 itimer.it_interval.tv_usec = 0;
227 itimer.it_value.tv_sec = TimerList->rest / SECTICKS;
228 itimer.it_value.tv_usec = (TimerList->rest % SECTICKS) * TICKUNIT;
229 if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
230 log_Printf(LogERROR, "Unable to set itimer (%s)\n", sys_errlist[errno]);
231 }
235}
236
237void
238timer_TermService(void)
239{
240 struct itimerval itimer;
241
242 itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
243 itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
244 if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
232}
233
234void
235timer_TermService(void)
236{
237 struct itimerval itimer;
238
239 itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
240 itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
241 if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
245 log_Printf(LogERROR, "Unable to set itimer.\n");
242 log_Printf(LogERROR, "Unable to set itimer (%s)\n", sys_errlist[errno]);
246 sig_signal(SIGALRM, SIG_IGN);
247}
243 sig_signal(SIGALRM, SIG_IGN);
244}