/*
* 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
#endif
static int SignalSignals(void);
-\f
+
/********************************\
* *
* Stuff for managing IoRequests *
static void *(*sigProc[NSOFTSIG])(void *);
static void *sigRock[NSOFTSIG];
-\f
+
static struct IoRequest *iorFreeList = 0;
static struct TM_Elem *Requests; /* List of requests */
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.
*/
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;
}
}
{
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.
*
#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.
#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)
if (fd_set1 == NULL || fd_set1->fd_count == 0)
return;
-
+
if (fd_set2 == NULL || fd_set2->fd_count == 0) {
FD_ZERO(fd_set1);
}
}
}
#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)
{
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;
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);
/* 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
}
#endif
iomgr_errno = errno;
- lwp_abort();
+ opr_abort();
}
}
}
LWP_DispatchProcess();
}
- return (void *)-1; /* keeps compilers happy. */
+ AFS_UNREACHED(return((void *)-1)); /* keeps compilers happy. */
}
-\f
+
/************************\
* *
* Signalling routines *
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) ||
{
/* 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;
return;
})
}
-\f
+
/*****************************************************\
* *
* Signal handling routine (not to be confused with *
static int SignalSignals (void)
{
bool gotone = FALSE;
- register int i;
- register void *(*p)(void *);
+ int i;
+ void *(*p)(void *);
afs_int32 stackSize;
anySigsDelivered = FALSE;
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]);
return gotone;
}
-\f
+
/***************************\
* *
* User-callable routines *
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 */
}
-unsigned char allOnes[100];
-
int IOMGR_Initialize(void)
{
PROCESS pid;
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);
}
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) {
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;
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);
if (fds < req->nfds)
fds = req->nfds;
})
-
+
tv.tv_sec = 0;
tv.tv_usec = 0;
#ifdef AFS_NT40_ENV
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
fprintf(stderr, "IOMGR_Select: fds=%d, more than max %d\n",
fds, FD_SETSIZE);
fflush(stderr);
- lwp_abort();
+ opr_abort();
}
#endif
#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 ...
*/
* can also get this error return
*/
if (code < 0 && errno == EAGAIN)
- goto again;
+ goto again;
#endif
#ifdef AFS_NT40_ENV
if (code == SOCKET_ERROR) {
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 */
return 0;
}
-\f
+
#ifndef AFS_NT40_ENV
/* Cause delivery of signal signo to result in a LWP_SignalProcess of
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;
timeout.tv_usec = 0;
IOMGR_Select(0, 0, 0, 0, &timeout);
}
-#endif /* USE_PTHREADS */