Remove DUX/OSF code
[openafs.git] / src / lwp / lwp.c
index 3e1290b..de9d651 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-
-#include <stdlib.h>
-#include <stdio.h>
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#include <time.h>
+#include <roken.h>
 
 /* allocate externs here */
 #define  LWP_KERNEL
 #include "lwp.h"
+
 #ifdef AFS_AIX32_ENV
 #include <ulimit.h>
 #include <sys/errno.h>
 #pragma alloca
 int setlim(int limcon, uchar_t hard, int limit);
 #endif
-#ifdef AFS_SGI64_ENV
-extern char *getenv();
-#include <time.h>
-#endif
-#include <string.h>
 
 #ifndef AFS_ARM_LINUX20_ENV
-#if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
-extern int PRE_Block;          /* from preempt.c */
+#if defined(AFS_S390_LINUX20_ENV)
+int PRE_Block; /* Remnants of preemption support. */
 #else
-extern char PRE_Block;         /* from preempt.c */
+char PRE_Block;        /* Remnants of preemption support. */
 #endif
 #endif
 
@@ -291,7 +281,7 @@ LWP_CreateProcess(void *(*ep) (void *), int stacksize, int priority, void *parm,
     /* Throw away all dead process control blocks */
     purge_dead_pcbs();
     if (lwp_init) {
-       temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
+       temp = malloc(sizeof(struct lwp_pcb));
        if (temp == NULL) {
            Set_LWP_RC();
            return LWP_ENOMEM;
@@ -347,11 +337,12 @@ LWP_CreateProcess(void *(*ep) (void *), int stacksize, int priority, void *parm,
        stackmemory = stackptr;
 #else
 #ifdef AFS_DARWIN_ENV
-       if ((stackmemory = (char *)malloc(stacksize + STACK_ALIGN - 1)) == NULL)
+       if ((stackmemory = malloc(stacksize + STACK_ALIGN - 1)) == NULL)
 #else /* !AFS_DARWIN_ENV */
-       if ((stackmemory = (char *)malloc(stacksize + 7)) == NULL)
+       if ((stackmemory = malloc(stacksize + 7)) == NULL)
 #endif /* !AFS_DARWIN_ENV */
        {
+           free(temp);
            Set_LWP_RC();
            return LWP_ENOMEM;
        }
@@ -363,6 +354,8 @@ LWP_CreateProcess(void *(*ep) (void *), int stacksize, int priority, void *parm,
 #endif /* !AFS_DARWIN_ENV */
 #endif
        if (priority < 0 || priority >= MAX_PRIORITIES) {
+           free(temp);
+           free(stackmemory);
            Set_LWP_RC();
            return LWP_EBADPRI;
        }
@@ -444,7 +437,7 @@ LWP_CreateProcess2(void *(*ep) (void *), int stacksize, int priority, void *parm
     /* Throw away all dead process control blocks */
     purge_dead_pcbs();
     if (lwp_init) {
-       temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
+       temp = malloc(sizeof(struct lwp_pcb));
        if (temp == NULL) {
            Set_LWP_RC();
            return LWP_ENOMEM;
@@ -454,7 +447,7 @@ LWP_CreateProcess2(void *(*ep) (void *), int stacksize, int priority, void *parm
        else
            stacksize =
                STACK_ALIGN * ((stacksize + STACK_ALIGN - 1) / STACK_ALIGN);
-       if ((stackptr = (char *)malloc(stacksize)) == NULL) {
+       if ((stackptr = malloc(stacksize)) == NULL) {
            Set_LWP_RC();
            return LWP_ENOMEM;
        }
@@ -624,8 +617,8 @@ LWP_InitializeProcessSupport(int priority, PROCESS * pid)
     blocked.count = 0;
     qwaiting.head = NULL;
     qwaiting.count = 0;
-    lwp_init = (struct lwp_ctl *)malloc(sizeof(struct lwp_ctl));
-    temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
+    lwp_init = malloc(sizeof(struct lwp_ctl));
+    temp = malloc(sizeof(struct lwp_pcb));
     if (lwp_init == NULL || temp == NULL)
        Abort_LWP("Insufficient Storage to Initialize LWP Support");
     LWPANCHOR.processcnt = 1;
@@ -733,9 +726,8 @@ LWP_MwaitProcess(int wcount, void *evlist[])
        }
        if (ecount > lwp_cpptr->eventlistsize) {
 
-           lwp_cpptr->eventlist =
-               (void **)realloc(lwp_cpptr->eventlist,
-                                ecount * sizeof(void *));
+           lwp_cpptr->eventlist = realloc(lwp_cpptr->eventlist,
+                                          ecount * sizeof(void *));
            lwp_cpptr->eventlistsize = ecount;
        }
        for (i = 0; i < ecount; i++)
@@ -990,11 +982,15 @@ Overflow_Complain(void)
     currenttime = time(0);
     timeStamp = ctime(&currenttime);
     timeStamp[24] = 0;
-    write(2, timeStamp, strlen(timeStamp));
-
-    write(2, msg1, strlen(msg1));
-    write(2, lwp_cpptr->name, strlen(lwp_cpptr->name));
-    write(2, msg2, strlen(msg2));
+    if (write(2, timeStamp, strlen(timeStamp)) < 0)
+       return;
+
+    if (write(2, msg1, strlen(msg1)) < 0)
+       return;
+    if (write(2, lwp_cpptr->name, strlen(lwp_cpptr->name)) < 0)
+       return;
+    if (write(2, msg2, strlen(msg2)) < 0)
+       return;
 }
 
 static void
@@ -1043,7 +1039,7 @@ Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
            i++;
     temp->name[31] = '\0';
     temp->status = READY;
-    temp->eventlist = (void **)malloc(EVINITSIZE * sizeof(void *));
+    temp->eventlist = malloc(EVINITSIZE * sizeof(void *));
     temp->eventlistsize = EVINITSIZE;
     temp->eventcnt = 0;
     temp->wakevent = 0;