From 1f1d79b8feacb68073133da638994ecd8e350fd8 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Thu, 23 Oct 1997 21:32:48 +0000 Subject: [PATCH] Restore back non-interruptable sleep/usleep just redefine them to not mix with standard library functions --- usr.sbin/ppp/defs.h | 10 ++++++- usr.sbin/ppp/timer.c | 64 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index 1ae8b839f8c5..6e2835a5a12d 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: defs.h,v 1.18 1997/08/25 00:29:10 brian Exp $ + * $Id: defs.h,v 1.19 1997/09/10 02:20:28 brian Exp $ * * TODO: */ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -104,4 +105,11 @@ char *dstsystem; #define FALSE (0) #endif +#ifdef SIGALRM +#define sleep nointr_sleep +#define usleep nointr_usleep +u_int sleep(u_int sec); +void usleep(u_int usec); +#endif + #endif /* _DEFS_H_ */ diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index 8454f695b68a..3070346065fc 100644 --- a/usr.sbin/ppp/timer.c +++ b/usr.sbin/ppp/timer.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: timer.c,v 1.18 1997/08/25 00:29:30 brian Exp $ + * $Id: timer.c,v 1.19 1997/10/23 20:11:01 ache Exp $ * * TODO: */ @@ -197,6 +197,68 @@ ShowTimers() } #ifdef SIGALRM +u_int +sleep(u_int sec) +{ + struct timeval to, st, et; + long sld, nwd, std; + + gettimeofday(&st, NULL); + to.tv_sec = sec; + to.tv_usec = 0; + std = st.tv_sec * 1000000 + st.tv_usec; + for (;;) { + if (select(0, NULL, NULL, NULL, &to) == 0 || + errno != EINTR) { + break; + } else { + gettimeofday(&et, NULL); + sld = to.tv_sec * 1000000 + to.tv_sec; + nwd = et.tv_sec * 1000000 + et.tv_usec - std; + if (sld > nwd) + sld -= nwd; + else + sld = 1; /* Avoid both tv_sec/usec is 0 */ + + /* Calculate timeout value for select */ + to.tv_sec = sld / 1000000; + to.tv_usec = sld % 1000000; + } + } + return (0L); +} + +void +usleep(u_int usec) +{ + struct timeval to, st, et; + long sld, nwd, std; + + gettimeofday(&st, NULL); + to.tv_sec = 0; + to.tv_usec = usec; + std = st.tv_sec * 1000000 + st.tv_usec; + for (;;) { + if (select(0, NULL, NULL, NULL, &to) == 0 || + errno != EINTR) { + break; + } else { + gettimeofday(&et, NULL); + sld = to.tv_sec * 1000000 + to.tv_sec; + nwd = et.tv_sec * 1000000 + et.tv_usec - std; + if (sld > nwd) + sld -= nwd; + else + sld = 1; /* Avoid both tv_sec/usec is 0 */ + + /* Calculate timeout value for select */ + to.tv_sec = sld / 1000000; + to.tv_usec = sld % 1000000; + + } + } +} + void InitTimerService(void) {