Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/gnu/dist/sendmail/sendmail Pull up revisions 1.5-1.7 (r...



details:   https://anonhg.NetBSD.org/src/rev/90d1ebad1b26
branches:  netbsd-1-5
changeset: 492796:90d1ebad1b26
user:      he <he%NetBSD.org@localhost>
date:      Wed Feb 20 23:12:36 2002 +0000

description:
Pull up revisions 1.5-1.7 (requested by itojun):
  Upgrade to sendmail version 8.11.6.

diffstat:

 gnu/dist/sendmail/sendmail/clock.c |  265 ++++++++++++++++++++++++++++++++----
 1 files changed, 233 insertions(+), 32 deletions(-)

diffs (truncated from 418 to 300 lines):

diff -r 4c561c0bc94b -r 90d1ebad1b26 gnu/dist/sendmail/sendmail/clock.c
--- a/gnu/dist/sendmail/sendmail/clock.c        Wed Feb 20 23:12:33 2002 +0000
+++ b/gnu/dist/sendmail/sendmail/clock.c        Wed Feb 20 23:12:36 2002 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
  *     All rights reserved.
  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
  * Copyright (c) 1988, 1993
@@ -12,7 +12,7 @@
  */
 
 #ifndef lint
-static char id[] = "@(#)Id: clock.c,v 8.52.18.3 2000/09/17 17:04:26 gshapiro Exp";
+static char id[] = "@(#)Id: clock.c,v 8.52.18.18 2001/08/14 16:07:04 ca Exp";
 #endif /* ! lint */
 
 #include <sendmail.h>
@@ -21,7 +21,8 @@
 # define sigmask(s)    (1 << ((s) - 1))
 #endif /* ! sigmask */
 
-static void    endsleep __P((void));
+static SIGFUNC_DECL    sm_tick __P((int));
+static void            endsleep __P((void));
 
 
 /*
@@ -42,7 +43,8 @@
 **             none.
 */
 
-EVENT  *FreeEventList;         /* list of free events */
+static EVENT   *volatile EventQueue;           /* head of event queue */
+static EVENT   *volatile FreeEventList;        /* list of free events */
 
 EVENT *
 setevent(intvl, func, arg)
@@ -50,46 +52,98 @@
        void (*func)();
        int arg;
 {
+       register EVENT *ev;
+
+       if (intvl <= 0)
+       {
+               syserr("554 5.3.0 setevent: intvl=%ld\n", intvl);
+               return NULL;
+       }
+
+       ENTER_CRITICAL();
+       if (FreeEventList == NULL)
+       {
+               FreeEventList = (EVENT *) xalloc(sizeof *FreeEventList);
+               FreeEventList->ev_link = NULL;
+       }
+       LEAVE_CRITICAL();
+
+       ev = sigsafe_setevent(intvl, func, arg);
+
+       if (tTd(5, 5))
+               dprintf("setevent: intvl=%ld, for=%ld, func=%lx, arg=%d, ev=%lx\n",
+                       (long) intvl, (long) (curtime() + intvl),
+                       (u_long) func, arg,
+                       ev == NULL ? 0 : (u_long) ev);
+
+       return ev;
+}
+
+/*
+**
+**     NOTE:   THIS CAN BE CALLED FROM A SIGNAL HANDLER.  DO NOT ADD
+**             ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
+**             DOING.
+*/
+
+EVENT *
+sigsafe_setevent(intvl, func, arg)
+       time_t intvl;
+       void (*func)();
+       int arg;
+{
        register EVENT **evp;
        register EVENT *ev;
        auto time_t now;
        int wasblocked;
 
        if (intvl <= 0)
-       {
-               syserr("554 5.3.0 setevent: intvl=%ld\n", intvl);
                return NULL;
-       }
 
        wasblocked = blocksignal(SIGALRM);
        now = curtime();
 
        /* search event queue for correct position */
-       for (evp = &EventQueue; (ev = *evp) != NULL; evp = &ev->ev_link)
+       for (evp = (EVENT **) (&EventQueue);
+            (ev = *evp) != NULL;
+            evp = &ev->ev_link)
        {
                if (ev->ev_time >= now + intvl)
                        break;
        }
 
+       ENTER_CRITICAL();
+       if (FreeEventList == NULL)
+       {
+               /*
+               **  This shouldn't happen.  If called from setevent(),
+               **  we have just malloced a FreeEventList entry.  If
+               **  called from a signal handler, it should have been
+               **  from an existing event which sm_tick() just added to the
+               **  FreeEventList.
+               */
+
+               LEAVE_CRITICAL();
+               return NULL;
+       }
+       else
+       {
+               ev = FreeEventList;
+               FreeEventList = ev->ev_link;
+       }
+       LEAVE_CRITICAL();
+
        /* insert new event */
-       ev = FreeEventList;
-       if (ev == NULL)
-               ev = (EVENT *) xalloc(sizeof *ev);
-       else
-               FreeEventList = ev->ev_link;
        ev->ev_time = now + intvl;
        ev->ev_func = func;
        ev->ev_arg = arg;
        ev->ev_pid = getpid();
+       ENTER_CRITICAL();
        ev->ev_link = *evp;
        *evp = ev;
+       LEAVE_CRITICAL();
 
-       if (tTd(5, 5))
-               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);
-
-       (void) setsignal(SIGALRM, tick);
+       (void) setsignal(SIGALRM, sm_tick);
        intvl = EventQueue->ev_time - now;
        (void) alarm((unsigned) intvl < 1 ? 1 : intvl);
        if (wasblocked == 0)
@@ -123,7 +177,9 @@
 
        /* find the parent event */
        wasblocked = blocksignal(SIGALRM);
-       for (evp = &EventQueue; *evp != NULL; evp = &(*evp)->ev_link)
+       for (evp = (EVENT **) (&EventQueue);
+            *evp != NULL;
+            evp = &(*evp)->ev_link)
        {
                if (*evp == ev)
                        break;
@@ -132,9 +188,11 @@
        /* now remove it */
        if (*evp != NULL)
        {
+               ENTER_CRITICAL();
                *evp = ev->ev_link;
                ev->ev_link = FreeEventList;
                FreeEventList = ev;
+               LEAVE_CRITICAL();
        }
 
        /* restore clocks and pick up anything spare */
@@ -178,16 +236,18 @@
        for (ev = EventQueue; ev->ev_link != NULL; ev = ev->ev_link)
                continue;
 
+       ENTER_CRITICAL();
        ev->ev_link = FreeEventList;
        FreeEventList = EventQueue;
        EventQueue = NULL;
+       LEAVE_CRITICAL();
 
        /* restore clocks and pick up anything spare */
        if (wasblocked == 0)
                (void) releasesignal(SIGALRM);
 }
 /*
-**  TICK -- take a clock tick
+**  SM_TICK -- take a clock sm_tick
 **
 **     Called by the alarm clock.  This routine runs events as needed.
 **     Always called as a signal handler, so we assume that SIGALRM
@@ -201,38 +261,82 @@
 **
 **     Side Effects:
 **             calls the next function in EventQueue.
+**
+**     NOTE:   THIS CAN BE CALLED FROM A SIGNAL HANDLER.  DO NOT ADD
+**             ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
+**             DOING.
 */
 
 /* ARGSUSED */
-SIGFUNC_DECL
-tick(sig)
+static SIGFUNC_DECL
+sm_tick(sig)
        int sig;
 {
        register time_t now;
        register EVENT *ev;
-       int mypid = getpid();
+       pid_t mypid;
        int save_errno = errno;
 
        (void) alarm(0);
+
+       FIX_SYSV_SIGNAL(sig, sm_tick);
+
+       errno = save_errno;
+       CHECK_CRITICAL(sig);
+
+       mypid = getpid();
+       while (PendingSignal != 0)
+       {
+               int sigbit = 0;
+               int sig = 0;
+
+               if (bitset(PEND_SIGHUP, PendingSignal))
+               {
+                       sigbit = PEND_SIGHUP;
+                       sig = SIGHUP;
+               }
+               else if (bitset(PEND_SIGINT, PendingSignal))
+               {
+                       sigbit = PEND_SIGINT;
+                       sig = SIGINT;
+               }
+               else if (bitset(PEND_SIGTERM, PendingSignal))
+               {
+                       sigbit = PEND_SIGTERM;
+                       sig = SIGTERM;
+               }
+               else if (bitset(PEND_SIGUSR1, PendingSignal))
+               {
+                       sigbit = PEND_SIGUSR1;
+                       sig = SIGUSR1;
+               }
+               else
+               {
+                       /* If we get here, we are in trouble */
+                       abort();
+               }
+               PendingSignal &= ~sigbit;
+               kill(mypid, sig);
+       }
+
        now = curtime();
-
        if (tTd(5, 4))
-               dprintf("tick: now=%ld\n", (long) now);
+               dprintf("sm_tick: now=%ld\n", (long) now);
 
-       /* reset signal in case System V semantics */
-       (void) setsignal(SIGALRM, tick);
        while ((ev = EventQueue) != NULL &&
               (ev->ev_time <= now || ev->ev_pid != mypid))
        {
                void (*f)();
                int arg;
-               int pid;
+               pid_t pid;
 
                /* process the event on the top of the queue */
+               ENTER_CRITICAL();
                ev = EventQueue;
                EventQueue = EventQueue->ev_link;
+               LEAVE_CRITICAL();
                if (tTd(5, 6))
-                       dprintf("tick: ev=%lx, func=%lx, arg=%d, pid=%d\n",
+                       dprintf("sm_tick: ev=%lx, func=%lx, arg=%d, pid=%d\n",
                                (u_long) ev, (u_long) ev->ev_func,
                                ev->ev_arg, ev->ev_pid);
 
@@ -240,9 +344,11 @@
                f = ev->ev_func;
                arg = ev->ev_arg;
                pid = ev->ev_pid;
+               ENTER_CRITICAL();
                ev->ev_link = FreeEventList;
                FreeEventList = ev;
-               if (pid != getpid())
+               LEAVE_CRITICAL();
+               if (pid != mypid)
                        continue;
                if (EventQueue != NULL)



Home | Main Index | Thread Index | Old Index