Remove DUX/OSF code
[openafs.git] / src / lwp / iomgr.c
index 088825c..670fd29 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
+#include <roken.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <malloc.h>
-extern void lwp_abort(void);
-#else
-#include <unistd.h>            /* select() prototype */
-#include <sys/types.h>         /* fd_set on older platforms */
-#include <sys/time.h>          /* struct timeval, select() prototype */
-#ifndef FD_SET
-# include <sys/select.h>       /* fd_set on newer platforms */
-#endif
-#include <sys/file.h>
-#endif /* AFS_NT40_ENV */
-#include "lwp.h"
-#include "timer.h"
-#include <signal.h>
-#include <errno.h>
-#ifdef AFS_SUN5_ENV
-#include <fcntl.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
 #endif
 
-#if    defined(USE_PTHREADS) || defined(USE_SOLARIS_THREADS)
+#include <afs/opr.h>
 
-void IOMGR_Initialize()        /* noop */
-{ }
-
-void IOMGR_Sleep (seconds)
-  unsigned seconds;
-{
-    struct timespec itv;
-
-    itv.tv_sec = seconds;
-    itv.tv_nsec = 0;
-    assert(pthread_mutex_unlock(&lwp_mutex) == 0);
-    assert(pthread_delay_np(&itv) == 0);
-    assert(pthread_mutex_lock(&lwp_mutex) == 0);
-}
-
-#else
-
-#ifdef AFS_DECOSF_ENV
-extern void *malloc();
-#endif /* AFS_DECOSF_ENV */
+#include "lwp.h"
+#include "timer.h"
 
 typedef unsigned char bool;
 #define FALSE  0
@@ -98,7 +60,7 @@ typedef unsigned char bool;
 #endif
 
 static int SignalSignals(void);
-\f
+
 /********************************\
 *                               *
 *  Stuff for managing IoRequests *
@@ -151,7 +113,7 @@ static int sigDelivered[NSIG];              /* True for signals delivered so far.
 static void *(*sigProc[NSOFTSIG])(void *);
 static void *sigRock[NSOFTSIG];
 
-\f
+
 static struct IoRequest *iorFreeList = 0;
 
 static struct TM_Elem *Requests;       /* List of requests */
@@ -165,7 +127,7 @@ static void SignalIO(int fds, fd_set *rfds, fd_set *wfds, fd_set *efs,
                    int code);
 static void SignalTimeout(int code, struct timeval *timeout);
 
-/* fd_set pool managment. 
+/* fd_set pool managment.
  * Use the pool instead of creating fd_set's on the stack. fd_set's can be
  * 8K in size, so making three could put 24K in the limited space of an LWP
  * stack.
@@ -190,19 +152,19 @@ void IOMGR_FreeFDSet(fd_set *s)
  */
 fd_set *IOMGR_AllocFDSet(void)
 {
-    struct IOMGR_fd_set *t;
+    fd_set *t;
     if (iomgrFreeFDSets) {
-       t =  iomgrFreeFDSets;
+       t = (fd_set *) iomgrFreeFDSets;
        iomgrFreeFDSets = iomgrFreeFDSets->next;
     }
     else {
-       t = (struct IOMGR_fd_set *)malloc(sizeof(fd_set));
+       t = malloc(sizeof(fd_set));
     }
     if (!t)
-       return (fd_set*)0;
+       return NULL;
     else {
-       FD_ZERO((fd_set*)t);
-       return (fd_set*)t;
+       FD_ZERO(t);
+       return t;
     }
 }
 
@@ -212,17 +174,17 @@ static struct IoRequest *NewRequest(void)
 {
     struct IoRequest *request;
 
-    if ((request=iorFreeList))
+    if ((request=iorFreeList)) {
        iorFreeList = (struct IoRequest *) (request->next);
-    else request = (struct IoRequest *) malloc(sizeof(struct IoRequest));
+       memset(request, 0, sizeof(struct IoRequest));
+    } else request = calloc(1, sizeof(struct IoRequest));
 
-    memset((char*)request, 0, sizeof(struct IoRequest));
     return request;
 }
 
 #define Purge(list) FOR_ALL_ELTS(req, list, { free(req->BackPointer); })
 
-\f
+
 /* FD_SET support routines. All assume the fd_set size is a multiple of an int
  * so we can at least do logical operations on ints instead of chars.
  *
@@ -237,11 +199,12 @@ static struct IoRequest *NewRequest(void)
 #define FD_N_ZERO(nfds, x) memset((char*)(x), 0, (INTS_PER_FDS(nfds))*sizeof(int))
 #endif
 
-#if defined(AFS_LINUX22_ENV) && (__GLIBC_MINOR__ > 0)
-/* Build for both glibc 2.0.x and 2.1.x */
-#define FDS_BITS __fds_bits
+/* On Linux without __USE_XOPEN, we have __fds_bits. With __USE_XOPEN, or
+ * non-Linux, we have fds_bits. */
+#if defined(AFS_LINUX22_ENV) && (__GLIBC_MINOR__ > 0) && !defined(__USE_XOPEN)
+# define FDS_BITS __fds_bits
 #else
-#define FDS_BITS fds_bits
+# define FDS_BITS fds_bits
 #endif
 
 /* FDSetCmp - returns 1 if any bits in fd_set1 are also set in fd_set2.
@@ -306,7 +269,7 @@ static void FDSetSet(int nfds, fd_set *fd_set1, fd_set *fd_set2)
 #endif
 }
 
-/* FDSetAnd - fd_set1  <- fd_set1 & fd_set2. 
+/* FDSetAnd - fd_set1  <- fd_set1 & fd_set2.
  */
 #ifdef AFS_NT40_ENV
 static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
@@ -316,7 +279,7 @@ static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
 
     if (fd_set1 == NULL || fd_set1->fd_count == 0)
        return;
-    
+
     if (fd_set2 == NULL || fd_set2->fd_count == 0) {
        FD_ZERO(fd_set1);
     }
@@ -343,8 +306,8 @@ static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
     }
 }
 #endif
-           
-/* FDSetEmpty - return true if fd_set is empty 
+
+/* FDSetEmpty - return true if fd_set is empty
  */
 static int FDSetEmpty(int nfds, fd_set *fds)
 {
@@ -416,7 +379,7 @@ static void *IOMGR(void *dummy)
            FT_GetTimeOfDay(&junk, 0);    /* force accurate time check */
            TM_Rescan(Requests);
            for (;;) {
-               register struct IoRequest *req;
+               struct IoRequest *req;
                struct TM_Elem *expired;
                expired = TM_GetExpired(Requests);
                if (expired == NULL) break;
@@ -450,7 +413,7 @@ static void *IOMGR(void *dummy)
        IOMGR_nfds = 0;
 
        FOR_ALL_ELTS(r, Requests, {
-           register struct IoRequest *req;
+           struct IoRequest *req;
            req = (struct IoRequest *) r -> BackPointer;
            FDSetSet(req->nfds, &IOMGR_readfds,   req->readfds);
            FDSetSet(req->nfds, &IOMGR_writefds,  req->writefds);
@@ -564,7 +527,7 @@ static void *IOMGR(void *dummy)
               /* Tape drives on Sun boxes do not support select and return ENXIO */
               if (errno == ENXIO) e=0, code=1;
 #endif
-#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_AIX32_ENV)
+#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX32_ENV)
               /* For SGI and SVR4 - poll & select can return EAGAIN ... */
               if (errno == EAGAIN) e=0;
 #endif
@@ -587,7 +550,7 @@ static void *IOMGR(void *dummy)
                  }
 #endif
                  iomgr_errno = errno;
-                 lwp_abort();
+                 opr_abort();
               }
            }
 
@@ -620,9 +583,9 @@ static void *IOMGR(void *dummy)
        }
        LWP_DispatchProcess();
     }
-    return (void *)-1; /* keeps compilers happy. */
+    AFS_UNREACHED(return((void *)-1)); /* keeps compilers happy. */
 }
-\f
+
 /************************\
 *                       *
 *  Signalling routines          *
@@ -635,8 +598,8 @@ static void SignalIO(int fds, fd_set *readfds, fd_set *writefds,
     int nfds;
     /* Look at everyone who's bit mask was affected */
     FOR_ALL_ELTS(r, Requests, {
-       register struct IoRequest *req;
-       register PROCESS pid;
+       struct IoRequest *req;
+       PROCESS pid;
        req = (struct IoRequest *) r -> BackPointer;
        nfds = MIN(fds, req->nfds);
        if (FDSetCmp(nfds, req->readfds, readfds) ||
@@ -658,8 +621,8 @@ static void SignalTimeout(int code, struct timeval *timeout)
 {
     /* Find everyone who has specified timeout */
     FOR_ALL_ELTS(r, Requests, {
-       register struct IoRequest *req;
-       register PROCESS pid;
+       struct IoRequest *req;
+       PROCESS pid;
        req = (struct IoRequest *) r -> BackPointer;
        if (TM_eql(&r->TimeLeft, timeout)) {
            req -> result = code;
@@ -670,7 +633,7 @@ static void SignalTimeout(int code, struct timeval *timeout)
            return;
     })
 }
-\f
+
 /*****************************************************\
 *                                                    *
 *  Signal handling routine (not to be confused with   *
@@ -693,8 +656,8 @@ static void SigHandler (int signo)
 static int SignalSignals (void)
 {
     bool gotone = FALSE;
-    register int i;
-    register void *(*p)(void *);
+    int i;
+    void *(*p)(void *);
     afs_int32 stackSize;
 
     anySigsDelivered = FALSE;
@@ -704,12 +667,12 @@ static int SignalSignals (void)
     for (i=0; i < NSOFTSIG; i++) {
        PROCESS pid;
        if ((p=sigProc[i])) /* This yields!!! */
-           LWP_CreateProcess2(p, stackSize, LWP_NORMAL_PRIORITY, 
+           LWP_CreateProcess2(p, stackSize, LWP_NORMAL_PRIORITY,
                               sigRock[i], "SignalHandler", &pid);
        sigProc[i] = 0;
     }
 
-    for (i = 1; i <= NSIG; ++i)  /* forall !badsig(i) */
+    for (i = 1; i < NSIG; ++i)  /* forall !badsig(i) */
        if ((sigsHandled & mysigmask(i)) && sigDelivered[i] == TRUE) {
            sigDelivered[i] = FALSE;
            LWP_NoYieldSignal (sigEvents[i]);
@@ -718,7 +681,7 @@ static int SignalSignals (void)
     return gotone;
 }
 
-\f
+
 /***************************\
 *                          *
 *  User-callable routines   *
@@ -731,7 +694,7 @@ static PROCESS IOMGR_Id = NULL;
 
 int IOMGR_SoftSig(void *(*aproc)(void *), void *arock)
 {
-    register int i;
+    int i;
     for (i=0;i<NSOFTSIG;i++) {
        if (sigProc[i] == 0) {
            /* a free entry */
@@ -747,8 +710,6 @@ int IOMGR_SoftSig(void *(*aproc)(void *), void *arock)
 }
 
 
-unsigned char allOnes[100];
-
 int IOMGR_Initialize(void)
 {
     PROCESS pid;
@@ -767,9 +728,8 @@ int IOMGR_Initialize(void)
     sigsHandled = 0;
     anySigsDelivered = TRUE; /* A soft signal may have happened before
        IOMGR_Initialize:  so force a check for signals regardless */
-    memset(allOnes, 0xff, sizeof(allOnes));
 
-    return LWP_CreateProcess(IOMGR, AFS_LWP_MINSTACKSIZE, 0, (void *) 0, 
+    return LWP_CreateProcess(IOMGR, AFS_LWP_MINSTACKSIZE, 0, (void *) 0,
                             "IO MANAGER", &IOMGR_Id);
 }
 
@@ -783,7 +743,7 @@ int IOMGR_Finalize(void)
     IOMGR_Id = NULL;
     return status;
 }
-\f
+
 /* signal I/O for anyone who is waiting for a FD or a timeout; not too cheap,
  * since forces select and timeofday check */
 int IOMGR_Poll(void) {
@@ -795,7 +755,7 @@ int IOMGR_Poll(void) {
     FT_GetTimeOfDay(&tv, 0);    /* force accurate time check */
     TM_Rescan(Requests);
     for (;;) {
-       register struct IoRequest *req;
+       struct IoRequest *req;
        struct TM_Elem *expired;
        expired = TM_GetExpired(Requests);
        if (expired == NULL) break;
@@ -830,7 +790,7 @@ int IOMGR_Poll(void) {
     fds = 0;
 
     FOR_ALL_ELTS(r, Requests, {
-       register struct IoRequest *req;
+       struct IoRequest *req;
        req = (struct IoRequest *) r -> BackPointer;
        FDSetSet(req->nfds, readfds,   req->readfds);
        FDSetSet(req->nfds, writefds,  req->writefds);
@@ -838,7 +798,7 @@ int IOMGR_Poll(void) {
        if (fds < req->nfds)
            fds = req->nfds;
     })
-       
+
     tv.tv_sec = 0;
     tv.tv_usec = 0;
 #ifdef AFS_NT40_ENV
@@ -861,10 +821,10 @@ int IOMGR_Poll(void) {
     return 0;
 }
 
-int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds, 
+int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds,
                 fd_set *exceptfds, struct timeval *timeout)
 {
-    register struct IoRequest *request;
+    struct IoRequest *request;
     int result;
 
 #ifndef AFS_NT40_ENV
@@ -872,7 +832,7 @@ int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds,
        fprintf(stderr, "IOMGR_Select: fds=%d, more than max %d\n",
                fds, FD_SETSIZE);
        fflush(stderr);
-       lwp_abort();
+       opr_abort();
     }
 #endif
 
@@ -883,11 +843,11 @@ int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds,
 #ifdef DEBUG
            if (lwp_debug != 0) puts("[Polling SELECT]");
 #endif /* DEBUG */
-#if    defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_NT40_ENV)
+#if    defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_NT40_ENV)
 again:
 #endif
            code = select(fds, readfds, writefds, exceptfds, timeout);
-#if    defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_AIX32_ENV)
+#if    defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX32_ENV)
            /*
             * For SGI and SVR4 - poll & select can return EAGAIN ...
             */
@@ -896,7 +856,7 @@ again:
             * can also get this error return
             */
            if (code < 0 && errno == EAGAIN)
-               goto again;     
+               goto again;
 #endif
 #ifdef AFS_NT40_ENV
            if (code == SOCKET_ERROR) {
@@ -958,10 +918,10 @@ again:
     FreeRequest(request);
     return (result > 1 ? 1 : result);
 }
-\f
+
 int IOMGR_Cancel(PROCESS pid)
 {
-    register struct IoRequest *request;
+    struct IoRequest *request;
 
     if ((request = pid->iomgrRequest) == 0) return -1; /* Pid not found */
 
@@ -981,7 +941,7 @@ int IOMGR_Cancel(PROCESS pid)
 
     return 0;
 }
-\f
+
 #ifndef AFS_NT40_ENV
 /* Cause delivery of signal signo to result in a LWP_SignalProcess of
    event. */
@@ -994,7 +954,7 @@ int IOMGR_Signal (int signo, char *event)
     if (event == NULL)
        return LWP_EBADEVENT;
     sa.sa_handler = SigHandler;
-    sa.sa_mask = *((sigset_t *) allOnes);      /* mask all signals */
+    sigfillset(&sa.sa_mask);   /* mask all signals */
     sa.sa_flags = 0;
     sigsHandled |= mysigmask(signo);
     sigEvents[signo] = event;
@@ -1023,4 +983,3 @@ void IOMGR_Sleep (int seconds)
     timeout.tv_usec = 0;
     IOMGR_Select(0, 0, 0, 0, &timeout);
 }
-#endif /* USE_PTHREADS */