summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/timer.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1998-05-21 21:49:08 +0000
committerbrian <brian@FreeBSD.org>1998-05-21 21:49:08 +0000
commit56df88b778aee0e60678672b107a48a8ea05cb48 (patch)
tree13b88ca17b38e787c84b0cd242677b3c3c0b93c3 /usr.sbin/ppp/timer.c
parente077fa331b8a428923ded3a95d0b8d47084cf670 (diff)
downloadFreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.zip
FreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.tar.gz
MFMP: Make ppp multilink capable.
See the file README.changes, and re-read the man page.
Diffstat (limited to 'usr.sbin/ppp/timer.c')
-rw-r--r--usr.sbin/ppp/timer.c179
1 files changed, 70 insertions, 109 deletions
diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c
index fa53b39..c8e41f1 100644
--- a/usr.sbin/ppp/timer.c
+++ b/usr.sbin/ppp/timer.c
@@ -17,67 +17,68 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timer.c,v 1.26 1997/12/29 22:23:52 brian Exp $
+ * $Id: timer.c,v 1.27.2.11 1998/05/08 01:15:18 brian Exp $
*
* TODO:
*/
-#include <signal.h>
-#ifdef SIGALRM
#include <errno.h>
-#endif
+#include <signal.h>
+#include <stdio.h>
#include <sys/time.h>
+#include <termios.h>
#include <unistd.h>
-#include "command.h"
-#include "mbuf.h"
#include "log.h"
#include "sig.h"
#include "timer.h"
+#include "descriptor.h"
+#include "prompt.h"
static struct pppTimer *TimerList = NULL;
static void StopTimerNoBlock(struct pppTimer *);
static void InitTimerService(void);
+static const char *
+tState2Nam(u_int state)
+{
+ static const char *StateNames[] = { "stopped", "running", "expired" };
+
+ if (state >= sizeof StateNames / sizeof StateNames[0])
+ return "unknown";
+ return StateNames[state];
+}
+
void
-StopTimer(struct pppTimer * tp)
+timer_Stop(struct pppTimer * tp)
{
-#ifdef SIGALRM
int omask;
omask = sigblock(sigmask(SIGALRM));
-#endif
StopTimerNoBlock(tp);
-#ifdef SIGALRM
sigsetmask(omask);
-#endif
}
void
-StartTimer(struct pppTimer * tp)
+timer_Start(struct pppTimer * tp)
{
struct pppTimer *t, *pt;
u_long ticks = 0;
-
-#ifdef SIGALRM
int omask;
omask = sigblock(sigmask(SIGALRM));
-#endif
- if (tp->state != TIMER_STOPPED) {
+ if (tp->state != TIMER_STOPPED)
StopTimerNoBlock(tp);
- }
+
if (tp->load == 0) {
- LogPrintf(LogDEBUG, "timer %x has 0 load!\n", tp);
+ log_Printf(LogTIMER, "%s timer[%p] has 0 load!\n", tp->name, tp);
sigsetmask(omask);
return;
}
pt = NULL;
for (t = TimerList; t; t = t->next) {
- LogPrintf(LogDEBUG, "StartTimer: %x(%d): ticks: %d, rest: %d\n",
- t, t->state, ticks, t->rest);
if (ticks + t->rest >= tp->load)
break;
ticks += t->rest;
@@ -86,8 +87,13 @@ StartTimer(struct pppTimer * tp)
tp->state = TIMER_RUNNING;
tp->rest = tp->load - ticks;
- LogPrintf(LogDEBUG, "StartTimer: Inserting %x before %x, rest = %d\n",
- tp, t, tp->rest);
+
+ if (t)
+ log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p] before %s "
+ "timer[%p], delta = %ld\n", tp->name, tp, t->name, t, tp->rest);
+ else
+ log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p]\n", tp->name, tp);
+
/* Insert given *tp just before *t */
tp->next = t;
if (pt) {
@@ -99,9 +105,7 @@ StartTimer(struct pppTimer * tp)
if (t)
t->rest -= tp->rest;
-#ifdef SIGALRM
sigsetmask(omask);
-#endif
}
static void
@@ -110,12 +114,10 @@ StopTimerNoBlock(struct pppTimer * tp)
struct pppTimer *t, *pt;
/*
- * A Running Timer should be removing TimerList, But STOPPED/EXPIRED is
- * already removing TimerList. So just marked as TIMER_STOPPED. Do not
- * change tp->enext!! (Might be Called by expired proc)
+ * A RUNNING timer must be removed from TimerList (->next list).
+ * A STOPPED timer isn't in any list, but may have a bogus [e]next field.
+ * An EXPIRED timer is in the ->enext list.
*/
- LogPrintf(LogDEBUG, "StopTimer: %x, next = %x state=%x\n",
- tp, tp->next, tp->state);
if (tp->state != TIMER_RUNNING) {
tp->next = NULL;
tp->state = TIMER_STOPPED;
@@ -130,24 +132,30 @@ StopTimerNoBlock(struct pppTimer * tp)
} else {
TimerList = t->next;
if (TimerList == NULL) /* Last one ? */
- TermTimerService(); /* Terminate Timer Service */
+ timer_TermService(); /* Terminate Timer Service */
}
if (t->next)
t->next->rest += tp->rest;
} else
- LogPrintf(LogERROR, "Oops, timer not found!!\n");
+ log_Printf(LogERROR, "Oops, %s timer not found!!\n", tp->name);
tp->next = NULL;
tp->state = TIMER_STOPPED;
}
static void
-TimerService()
+TimerService(void)
{
struct pppTimer *tp, *exp, *wt;
- if (LogIsKept(LogDEBUG))
- ShowTimers();
+ if (log_IsKept(LogTIMER)) {
+ static time_t t;
+ time_t n = time(NULL); /* Only show timers every second */
+
+ if (n > t)
+ timer_Show(LogTIMER, NULL);
+ t = n;
+ }
tp = TimerList;
if (tp) {
tp->rest--;
@@ -162,22 +170,19 @@ TimerService()
wt = tp->next;
tp->enext = exp;
exp = tp;
- LogPrintf(LogDEBUG, "TimerService: Add %x to exp\n", tp);
tp = wt;
} while (tp && (tp->rest == 0));
TimerList = tp;
if (TimerList == NULL) /* No timers ? */
- TermTimerService(); /* Terminate Timer Service */
- LogPrintf(LogDEBUG, "TimerService: next is %x(%d)\n",
- TimerList, TimerList ? TimerList->rest : 0);
+ timer_TermService(); /* Terminate Timer Service */
/*
* Process all expired timers.
*/
while (exp) {
#ifdef notdef
- StopTimer(exp);
+ timer_Stop(exp);
#endif
if (exp->func)
(*exp->func) (exp->arg);
@@ -193,73 +198,31 @@ TimerService()
}
void
-ShowTimers()
+timer_Show(int LogLevel, struct prompt *prompt)
{
struct pppTimer *pt;
-
- LogPrintf(LogDEBUG, "---- Begin of Timer Service List---\n");
- for (pt = TimerList; pt; pt = pt->next)
- LogPrintf(LogDEBUG, "%x: load = %d, rest = %d, state =%x\n",
- pt, pt->load, pt->rest, pt->state);
- LogPrintf(LogDEBUG, "---- End of Timer Service List ---\n");
-}
-
-#ifdef SIGALRM
-
-static void
-nointr_dosleep(u_int sec, u_int usec)
-{
- struct timeval to, st, et;
-
- gettimeofday(&st, NULL);
- et.tv_sec = st.tv_sec + sec;
- et.tv_usec = st.tv_usec + usec;
- to.tv_sec = sec;
- to.tv_usec = usec;
- for (;;) {
- if (select(0, NULL, NULL, NULL, &to) == 0 ||
- errno != EINTR) {
- break;
- } else {
- gettimeofday(&to, NULL);
- if (to.tv_sec > et.tv_sec + 1 ||
- (to.tv_sec == et.tv_sec + 1 && to.tv_usec > et.tv_usec) ||
- to.tv_sec < st.tv_sec ||
- (to.tv_sec == st.tv_sec && to.tv_usec < st.tv_usec)) {
- LogPrintf(LogWARN, "Clock adjusted between %d and %d seconds "
- "during sleep !\n",
- to.tv_sec - st.tv_sec, sec + to.tv_sec - st.tv_sec);
- st.tv_sec = to.tv_sec;
- st.tv_usec = to.tv_usec;
- et.tv_sec = st.tv_sec + sec;
- et.tv_usec = st.tv_usec + usec;
- to.tv_sec = sec;
- to.tv_usec = usec;
- } else if (to.tv_sec > et.tv_sec ||
- (to.tv_sec == et.tv_sec && to.tv_usec >= et.tv_usec)) {
- break;
- } else {
- to.tv_sec = et.tv_sec - to.tv_sec;
- if (et.tv_usec < to.tv_usec) {
- to.tv_sec--;
- to.tv_usec = 1000000 + et.tv_usec - to.tv_usec;
- } else
- to.tv_usec = et.tv_usec - to.tv_usec;
- }
- }
+ int rest = 0;
+
+#define SECS(val) ((val) / SECTICKS)
+#define HSECS(val) (((val) % SECTICKS) * 100 / SECTICKS)
+#define DISP \
+ "%s timer[%p]: freq = %ld.%02lds, next = %d.%02ds, state = %s\n", \
+ pt->name, pt, SECS(pt->load), HSECS(pt->load), SECS(rest), \
+ HSECS(rest), tState2Nam(pt->state)
+
+ if (!prompt)
+ log_Printf(LogLevel, "---- Begin of Timer Service List---\n");
+
+ for (pt = TimerList; pt; pt = pt->next) {
+ rest += pt->rest;
+ if (prompt)
+ prompt_Printf(prompt, DISP);
+ else
+ log_Printf(LogLevel, DISP);
}
-}
-void
-nointr_sleep(u_int sec)
-{
- nointr_dosleep(sec, 0);
-}
-
-void
-nointr_usleep(u_int usec)
-{
- nointr_dosleep(0, usec);
+ if (!prompt)
+ log_Printf(LogLevel, "---- End of Timer Service List ---\n");
}
static void
@@ -267,23 +230,21 @@ InitTimerService()
{
struct itimerval itimer;
- pending_signal(SIGALRM, (void (*) (int)) TimerService);
+ sig_signal(SIGALRM, (void (*) (int)) TimerService);
itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
- LogPrintf(LogERROR, "Unable to set itimer.\n");
+ log_Printf(LogERROR, "Unable to set itimer.\n");
}
void
-TermTimerService(void)
+timer_TermService(void)
{
struct itimerval itimer;
itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
if (setitimer(ITIMER_REAL, &itimer, NULL) == -1)
- LogPrintf(LogERROR, "Unable to set itimer.\n");
- pending_signal(SIGALRM, SIG_IGN);
+ log_Printf(LogERROR, "Unable to set itimer.\n");
+ sig_signal(SIGALRM, SIG_IGN);
}
-
-#endif
OpenPOWER on IntegriCloud