diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2000-08-12 21:55:49 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2000-08-12 21:55:49 +0000 |
commit | c3cd75415d60bc002b20182ffd3383ea9e901a80 (patch) | |
tree | 211dfd0f771f89d6abe14fa94cab53985a9d0116 /contrib/sendmail/src/clock.c | |
parent | 231592eb7942ebd4becae24ea8e018acea3742a9 (diff) | |
parent | 4332139a9a11f773ffe5109bed871561e3c290a1 (diff) | |
download | FreeBSD-src-c3cd75415d60bc002b20182ffd3383ea9e901a80.zip FreeBSD-src-c3cd75415d60bc002b20182ffd3383ea9e901a80.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r64562,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/sendmail/src/clock.c')
-rw-r--r-- | contrib/sendmail/src/clock.c | 99 |
1 files changed, 72 insertions, 27 deletions
diff --git a/contrib/sendmail/src/clock.c b/contrib/sendmail/src/clock.c index e6466e6..33b38f4 100644 --- a/contrib/sendmail/src/clock.c +++ b/contrib/sendmail/src/clock.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1998 Sendmail, Inc. All rights reserved. + * Copyright (c) 1998, 1999 Sendmail, Inc. and its suppliers. + * All rights reserved. * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -11,14 +12,17 @@ */ #ifndef lint -static char sccsid[] = "@(#)clock.c 8.35 (Berkeley) 2/2/1999"; -#endif /* not lint */ +static char id[] = "@(#)$Id: clock.c,v 8.52.18.2 2000/05/25 23:33:30 gshapiro Exp $"; +#endif /* ! lint */ -# include "sendmail.h" +#include <sendmail.h> + +#ifndef sigmask +# define sigmask(s) (1 << ((s) - 1)) +#endif /* ! sigmask */ + +static void endsleep __P((void)); -# ifndef sigmask -# define sigmask(s) (1 << ((s) - 1)) -# endif /* ** SETEVENT -- set an event to happen at a specific time. @@ -40,8 +44,6 @@ static char sccsid[] = "@(#)clock.c 8.35 (Berkeley) 2/2/1999"; EVENT *FreeEventList; /* list of free events */ -static SIGFUNC_DECL tick __P((int)); - EVENT * setevent(intvl, func, arg) time_t intvl; @@ -55,8 +57,8 @@ setevent(intvl, func, arg) if (intvl <= 0) { - syserr("554 setevent: intvl=%ld\n", intvl); - return (NULL); + syserr("554 5.3.0 setevent: intvl=%ld\n", intvl); + return NULL; } wasblocked = blocksignal(SIGALRM); @@ -83,16 +85,16 @@ setevent(intvl, func, arg) *evp = ev; if (tTd(5, 5)) - printf("setevent: intvl=%ld, for=%ld, func=%lx, arg=%d, ev=%lx\n", + dprintf("setevent: intvl=%ld, for=%ld, func=%lx, arg=%d, ev=%lx\n", (long) intvl, (long)(now + intvl), (u_long) func, arg, (u_long) ev); - setsignal(SIGALRM, tick); + (void) setsignal(SIGALRM, tick); intvl = EventQueue->ev_time - now; (void) alarm((unsigned) intvl < 1 ? 1 : intvl); if (wasblocked == 0) (void) releasesignal(SIGALRM); - return (ev); + return ev; } /* ** CLREVENT -- remove an event from the event queue. @@ -115,7 +117,7 @@ clrevent(ev) int wasblocked; if (tTd(5, 5)) - printf("clrevent: ev=%lx\n", (u_long) ev); + dprintf("clrevent: ev=%lx\n", (u_long) ev); if (ev == NULL) return; @@ -137,9 +139,52 @@ clrevent(ev) /* restore clocks and pick up anything spare */ if (wasblocked == 0) - releasesignal(SIGALRM); + (void) releasesignal(SIGALRM); if (EventQueue != NULL) - kill(getpid(), SIGALRM); + (void) kill(getpid(), SIGALRM); + else + { + /* nothing left in event queue, no need for an alarm */ + (void) alarm(0); + } +} +/* +** CLEAR_EVENTS -- remove all events from the event queue. +** +** Parameters: +** none. +** +** Returns: +** none. +*/ + +void +clear_events() +{ + register EVENT *ev; + int wasblocked; + + if (tTd(5, 5)) + dprintf("clear_events: EventQueue=%lx\n", (u_long) EventQueue); + + if (EventQueue == NULL) + return; + + /* nothing will be left in event queue, no need for an alarm */ + (void) alarm(0); + wasblocked = blocksignal(SIGALRM); + + /* find the end of the EventQueue */ + for (ev = EventQueue; ev->ev_link != NULL; ev = ev->ev_link) + continue; + + ev->ev_link = FreeEventList; + FreeEventList = EventQueue; + EventQueue = NULL; + + /* restore clocks and pick up anything spare */ + if (wasblocked == 0) + (void) releasesignal(SIGALRM); } /* ** TICK -- take a clock tick @@ -159,20 +204,20 @@ clrevent(ev) */ /* ARGSUSED */ -static SIGFUNC_DECL +SIGFUNC_DECL tick(sig) int sig; { register time_t now; register EVENT *ev; int mypid = getpid(); - int olderrno = errno; + int save_errno = errno; (void) alarm(0); now = curtime(); if (tTd(5, 4)) - printf("tick: now=%ld\n", (long) now); + dprintf("tick: now=%ld\n", (long) now); /* reset signal in case System V semantics */ (void) setsignal(SIGALRM, tick); @@ -187,7 +232,7 @@ tick(sig) ev = EventQueue; EventQueue = EventQueue->ev_link; if (tTd(5, 6)) - printf("tick: ev=%lx, func=%lx, arg=%d, pid=%d\n", + dprintf("tick: ev=%lx, func=%lx, arg=%d, pid=%d\n", (u_long) ev, (u_long) ev->ev_func, ev->ev_arg, ev->ev_pid); @@ -208,14 +253,14 @@ tick(sig) } /* call ev_func */ - errno = olderrno; + errno = save_errno; (*f)(arg); (void) alarm(0); now = curtime(); } if (EventQueue != NULL) (void) alarm((unsigned) (EventQueue->ev_time - now)); - errno = olderrno; + errno = save_errno; return SIGFUNC_RETURN; } /* @@ -235,12 +280,12 @@ tick(sig) ** be run during that interval. */ + static bool SleepDone; -static void endsleep __P((void)); #ifndef SLEEP_T # define SLEEP_T unsigned int -#endif +#endif /* ! SLEEP_T */ SLEEP_T sleep(intvl) @@ -254,9 +299,9 @@ sleep(intvl) (void) setevent((time_t) intvl, endsleep, 0); was_held = releasesignal(SIGALRM); while (!SleepDone) - pause(); + (void) pause(); if (was_held > 0) - blocksignal(SIGALRM); + (void) blocksignal(SIGALRM); return (SLEEP_T) 0; } |