bozo: Remove dead code and minor cleanup
[openafs.git] / src / bozo / bnode.c
index 9d32684..077a446 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 <afs/procmgmt.h>
+#include <roken.h>
 
 #include <stddef.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <io.h>
-#else
-#include <sys/file.h>
-#include <sys/time.h>
-#endif
-#ifdef BOZO_SAVE_CORES
-#include <time.h>
-#endif
-#include <sys/stat.h>
-#include <string.h>
 
-#include <afs/procmgmt.h>      /* signal(), kill(), wait(), etc. */
 #include <lwp.h>
+#include <rx/rx.h>
 #include <afs/audit.h>
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
+#include <opr/queue.h>
+
 #include "bnode.h"
+#include "bnode_internal.h"
 #include "bosprototypes.h"
 
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN4_ENV)
-/* All known versions of AIX lack WCOREDUMP but this works */
-#define WCOREDUMP(x) ((x) & 0x80)
+#ifndef WCOREDUMP
+#define WCOREDUMP(x) ((x) & 0200)
 #endif
 
 #define BNODE_LWP_STACKSIZE    (16 * 1024)
+#define BNODE_ERROR_COUNT_MAX   16   /* maximum number of retries */
+#define BNODE_ERROR_DELAY_MAX   60   /* maximum retry delay (seconds) */
 
-int bnode_waiting = 0;
 static PROCESS bproc_pid;      /* pid of waker-upper */
-static struct bnode *allBnodes = 0;    /* list of all bnodes */
-static struct bnode_proc *allProcs = 0;        /* list of all processes for which we're waiting */
-static struct bnode_type *allTypes = 0;        /* list of registered type handlers */
+static struct opr_queue allBnodes;     /**< List of all bnodes */
+static struct opr_queue allProcs;      /**< List of all processes for which we're waiting */
+static struct opr_queue allTypes;      /**< List of all registered type handlers */
 
 static struct bnode_stats {
     int weirdPids;
 } bnode_stats;
 
+extern const char *DoCore;
+extern const char *DoPidFiles;
 #ifndef AFS_NT40_ENV
 extern char **environ;         /* env structure */
 #endif
 
+int hdl_notifier(struct bnode_proc *tp);
+
 /* Remember the name of the process, if any, that failed last */
 static void
-RememberProcName(register struct bnode_proc *ap)
+RememberProcName(struct bnode_proc *ap)
 {
-    register struct bnode *tbnodep;
+    struct bnode *tbnodep;
 
     tbnodep = ap->bnode;
     if (tbnodep->lastErrorName) {
        free(tbnodep->lastErrorName);
        tbnodep->lastErrorName = NULL;
     }
-    if (ap->coreName) {
-       tbnodep->lastErrorName = (char *)malloc(strlen(ap->coreName) + 1);
-       strcpy(tbnodep->lastErrorName, ap->coreName);
-    }
+    if (ap->coreName)
+       tbnodep->lastErrorName = strdup(ap->coreName);
 }
 
 /* utility for use by BOP_HASCORE functions to determine where a core file might
  * be stored.
  */
 int
-bnode_CoreName(register struct bnode *abnode, char *acoreName, char *abuffer)
-{
-    strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH);
+bnode_CoreName(struct bnode *abnode, char *acoreName, char *abuffer)
+{
+    if (DoCore) {
+       strcpy(abuffer, DoCore);
+       strcat(abuffer, "/");
+       strcat(abuffer, AFSDIR_CORE_FILE);
+    } else
+       strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH);
     if (acoreName) {
        strcat(abuffer, acoreName);
        strcat(abuffer, ".");
@@ -94,12 +88,12 @@ bnode_CoreName(register struct bnode *abnode, char *acoreName, char *abuffer)
 
 /* save core file, if any */
 static void
-SaveCore(register struct bnode *abnode, register struct bnode_proc
+SaveCore(struct bnode *abnode, struct bnode_proc
         *aproc)
 {
     char tbuffer[256];
     struct stat tstat;
-    register afs_int32 code;
+    afs_int32 code = 0;
     char *corefile = NULL;
 #ifdef BOZO_SAVE_CORES
     struct timeval Start;
@@ -109,15 +103,22 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc
 
     /* Linux always appends the PID to core dumps from threaded processes, so
      * we have to scan the directory to find core files under another name. */
-    code = stat(AFSDIR_SERVER_CORELOG_FILEPATH, &tstat);
+    if (DoCore) {
+       strcpy(tbuffer, DoCore);
+       strcat(tbuffer, "/");
+       strcat(tbuffer, AFSDIR_CORE_FILE);
+    } else
+       code = stat(AFSDIR_SERVER_CORELOG_FILEPATH, &tstat);
     if (code) {
         DIR *logdir;
         struct dirent *file;
-        char *p;
-        size_t length;
         unsigned long pid;
+       const char *coredir = AFSDIR_LOGS_DIR;
 
-        logdir = opendir(AFSDIR_LOGS_DIR);
+       if (DoCore)
+         coredir = DoCore;
+
+       logdir = opendir(coredir);
         if (logdir == NULL)
             return;
         while ((file = readdir(logdir)) != NULL) {
@@ -125,19 +126,18 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc
                 continue;
             pid = atol(file->d_name + 5);
             if (pid == aproc->pid) {
-                length = strlen(AFSDIR_LOGS_DIR) + strlen(file->d_name) + 2;
-                corefile = malloc(length);
+                asprintf(&corefile, "%s/%s", coredir, file->d_name);
                 if (corefile == NULL) {
                     closedir(logdir);
                     return;
                 }
-                snprintf(corefile, length, "%s/%s", AFSDIR_LOGS_DIR,
-                         file->d_name);
                 code = 0;
                 break;
             }
         }
         closedir(logdir);
+    } else {
+       corefile = strdup(tbuffer);
     }
     if (code)
        return;
@@ -151,42 +151,38 @@ SaveCore(register struct bnode *abnode, register struct bnode_proc
            TimeFields->tm_hour, TimeFields->tm_min, TimeFields->tm_sec);
     strcpy(tbuffer, FileName);
 #endif
-    if (corefile == NULL)
-        code = renamefile(AFSDIR_SERVER_CORELOG_FILEPATH, tbuffer);
-    else {
-        code = renamefile(corefile, tbuffer);
-        free(corefile);
-    }
+    rk_rename(corefile, tbuffer);
+    free(corefile);
 }
 
 int
-bnode_GetString(register struct bnode *abnode, register char *abuffer,
-               register afs_int32 alen)
+bnode_GetString(struct bnode *abnode, char *abuffer,
+               afs_int32 alen)
 {
     return BOP_GETSTRING(abnode, abuffer, alen);
 }
 
 int
-bnode_GetParm(register struct bnode *abnode, register afs_int32 aindex,
-             register char *abuffer, afs_int32 alen)
+bnode_GetParm(struct bnode *abnode, afs_int32 aindex,
+             char *abuffer, afs_int32 alen)
 {
     return BOP_GETPARM(abnode, aindex, abuffer, alen);
 }
 
 int
-bnode_GetStat(register struct bnode *abnode, register afs_int32 * astatus)
+bnode_GetStat(struct bnode *abnode, afs_int32 * astatus)
 {
     return BOP_GETSTAT(abnode, astatus);
 }
 
 int
-bnode_RestartP(register struct bnode *abnode)
+bnode_RestartP(struct bnode *abnode)
 {
     return BOP_RESTARTP(abnode);
 }
 
 static int
-bnode_Check(register struct bnode *abnode)
+bnode_Check(struct bnode *abnode)
 {
     if (abnode->flags & BNODE_WAIT) {
        abnode->flags &= ~BNODE_WAIT;
@@ -197,21 +193,23 @@ bnode_Check(register struct bnode *abnode)
 
 /* tell if an instance has a core file */
 int
-bnode_HasCore(register struct bnode *abnode)
+bnode_HasCore(struct bnode *abnode)
 {
     return BOP_HASCORE(abnode);
 }
 
 /* wait for all bnodes to stabilize */
 int
-bnode_WaitAll()
+bnode_WaitAll(void)
 {
-    register struct bnode *tb;
-    register afs_int32 code;
+    struct opr_queue *cursor;
+    afs_int32 code;
     afs_int32 stat;
 
   retry:
-    for (tb = allBnodes; tb; tb = tb->next) {
+    for (opr_queue_Scan(&allBnodes, cursor)) {
+       struct bnode *tb = opr_queue_Entry(cursor, struct bnode, q);
+
        bnode_Hold(tb);
        code = BOP_GETSTAT(tb, &stat);
        if (code) {
@@ -231,9 +229,9 @@ bnode_WaitAll()
 
 /* wait until bnode status is correct */
 int
-bnode_WaitStatus(register struct bnode *abnode, int astatus)
+bnode_WaitStatus(struct bnode *abnode, int astatus)
 {
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 stat;
 
     bnode_Hold(abnode);
@@ -259,7 +257,15 @@ bnode_WaitStatus(register struct bnode *abnode, int astatus)
 }
 
 int
-bnode_SetStat(register struct bnode *abnode, register int agoal)
+bnode_ResetErrorCount(struct bnode *abnode)
+{
+    abnode->errorStopCount = 0;
+    abnode->errorStopDelay = 0;
+    return 0;
+}
+
+int
+bnode_SetStat(struct bnode *abnode, int agoal)
 {
     abnode->goal = agoal;
     bnode_Check(abnode);
@@ -269,7 +275,7 @@ bnode_SetStat(register struct bnode *abnode, register int agoal)
 }
 
 int
-bnode_SetGoal(register struct bnode *abnode, register int agoal)
+bnode_SetGoal(struct bnode *abnode, int agoal)
 {
     abnode->goal = agoal;
     bnode_Check(abnode);
@@ -277,7 +283,7 @@ bnode_SetGoal(register struct bnode *abnode, register int agoal)
 }
 
 int
-bnode_SetFileGoal(register struct bnode *abnode, register int agoal)
+bnode_SetFileGoal(struct bnode *abnode, int agoal)
 {
     if (abnode->fileGoal == agoal)
        return 0;               /* already done */
@@ -288,13 +294,13 @@ bnode_SetFileGoal(register struct bnode *abnode, register int agoal)
 
 /* apply a function to all bnodes in the system */
 int
-bnode_ApplyInstance(int (*aproc) (), char *arock)
+bnode_ApplyInstance(int (*aproc) (struct bnode *tb, void *), void *arock)
 {
-    register struct bnode *tb, *nb;
-    register afs_int32 code;
+    struct opr_queue *cursor, *store;
+    afs_int32 code;
 
-    for (tb = allBnodes; tb; tb = nb) {
-       nb = tb->next;
+    for (opr_queue_ScanSafe(&allBnodes, cursor, store)) {
+       struct bnode *tb = opr_queue_Entry(cursor, struct bnode, q);
        code = (*aproc) (tb, arock);
        if (code)
            return code;
@@ -303,11 +309,13 @@ bnode_ApplyInstance(int (*aproc) (), char *arock)
 }
 
 struct bnode *
-bnode_FindInstance(register char *aname)
+bnode_FindInstance(char *aname)
 {
-    register struct bnode *tb;
+    struct opr_queue *cursor;
+
+    for (opr_queue_Scan(&allBnodes, cursor)) {
+       struct bnode *tb = opr_queue_Entry(cursor, struct bnode, q);
 
-    for (tb = allBnodes; tb; tb = tb->next) {
        if (!strcmp(tb->name, aname))
            return tb;
     }
@@ -315,31 +323,34 @@ bnode_FindInstance(register char *aname)
 }
 
 static struct bnode_type *
-FindType(register char *aname)
+FindType(char *aname)
 {
-    register struct bnode_type *tt;
+    struct opr_queue *cursor;
+
+    for (opr_queue_Scan(&allTypes, cursor)) {
+       struct bnode_type *tt = opr_queue_Entry(cursor, struct bnode_type, q);
 
-    for (tt = allTypes; tt; tt = tt->next) {
        if (!strcmp(tt->name, aname))
            return tt;
     }
-    return (struct bnode_type *)0;
+    return NULL;
 }
 
 int
 bnode_Register(char *atype, struct bnode_ops *aprocs, int anparms)
 {
-    register struct bnode_type *tt;
+    struct opr_queue *cursor;
+    struct bnode_type *tt = NULL;
 
-    for (tt = allTypes; tt; tt = tt->next) {
+    for (opr_queue_Scan(&allTypes, cursor), tt = NULL) {
+       tt = opr_queue_Entry(cursor, struct bnode_type, q);
        if (!strcmp(tt->name, atype))
            break;
     }
     if (!tt) {
-       tt = (struct bnode_type *)malloc(sizeof(struct bnode_type));
-       memset(tt, 0, sizeof(struct bnode_type));
-       tt->next = allTypes;
-       allTypes = tt;
+       tt = calloc(1, sizeof(struct bnode_type));
+        opr_queue_Init(&tt->q);
+       opr_queue_Prepend(&allTypes, &tt->q);
        tt->name = atype;
     }
     tt->ops = aprocs;
@@ -386,7 +397,7 @@ bnode_Create(char *atype, char *ainstance, struct bnode ** abp, char *ap1,
     *abp = tb;
     tb->type = type;
 
-    /* The fs_create above calls bnode_InitBnode() which always sets the 
+    /* The fs_create above calls bnode_InitBnode() which always sets the
      ** fileGoal to BSTAT_NORMAL .... overwrite it with whatever is passed into
      ** this function as a parameter... */
     tb->fileGoal = fileGoal;
@@ -402,7 +413,7 @@ bnode_Create(char *atype, char *ainstance, struct bnode ** abp, char *ap1,
 int
 bnode_DeleteName(char *ainstance)
 {
-    register struct bnode *tb;
+    struct bnode *tb;
 
     tb = bnode_FindInstance(ainstance);
     if (!tb)
@@ -412,14 +423,14 @@ bnode_DeleteName(char *ainstance)
 }
 
 int
-bnode_Hold(register struct bnode *abnode)
+bnode_Hold(struct bnode *abnode)
 {
     abnode->refCount++;
     return 0;
 }
 
 int
-bnode_Release(register struct bnode *abnode)
+bnode_Release(struct bnode *abnode)
 {
     abnode->refCount--;
     if (abnode->refCount == 0 && abnode->flags & BNODE_DELETE) {
@@ -430,10 +441,9 @@ bnode_Release(register struct bnode *abnode)
 }
 
 int
-bnode_Delete(register struct bnode *abnode)
+bnode_Delete(struct bnode *abnode)
 {
-    register afs_int32 code;
-    register struct bnode **lb, *ub;
+    afs_int32 code;
     afs_int32 temp;
 
     if (abnode->refCount != 0) {
@@ -451,13 +461,7 @@ bnode_Delete(register struct bnode *abnode)
        return BZBUSY;
 
     /* all clear to zap */
-    for (lb = &allBnodes, ub = *lb; ub; lb = &ub->next, ub = *lb) {
-       if (ub == abnode) {
-           /* unthread it from the list */
-           *lb = ub->next;
-           break;
-       }
-    }
+    opr_queue_Remove(&abnode->q);
     free(abnode->name);                /* do this first, since bnode fields may be bad after BOP_DELETE */
     code = BOP_DELETE(abnode); /* don't play games like holding over this one */
     WriteBozoFile(0);
@@ -466,14 +470,14 @@ bnode_Delete(register struct bnode *abnode)
 
 /* function to tell if there's a timeout coming up */
 int
-bnode_PendingTimeout(register struct bnode *abnode)
+bnode_PendingTimeout(struct bnode *abnode)
 {
     return (abnode->flags & BNODE_NEEDTIMEOUT);
 }
 
 /* function called to set / clear periodic bnode wakeup times */
 int
-bnode_SetTimeout(register struct bnode *abnode, afs_int32 atimeout)
+bnode_SetTimeout(struct bnode *abnode, afs_int32 atimeout)
 {
     if (atimeout != 0) {
        abnode->nextTimeout = FT_ApproxTime() + atimeout;
@@ -488,55 +492,35 @@ bnode_SetTimeout(register struct bnode *abnode, afs_int32 atimeout)
 
 /* used by new bnode creation code to format bnode header */
 int
-bnode_InitBnode(register struct bnode *abnode, struct bnode_ops *abnodeops,
+bnode_InitBnode(struct bnode *abnode, struct bnode_ops *abnodeops,
                char *aname)
 {
-    struct bnode **lb, *nb;
-
     /* format the bnode properly */
     memset(abnode, 0, sizeof(struct bnode));
+    opr_queue_Init(&abnode->q);
     abnode->ops = abnodeops;
-    abnode->name = (char *)malloc(strlen(aname) + 1);
+    abnode->name = strdup(aname);
     if (!abnode->name)
        return ENOMEM;
-    strcpy(abnode->name, aname);
     abnode->flags = BNODE_ACTIVE;
     abnode->fileGoal = BSTAT_NORMAL;
     abnode->goal = BSTAT_SHUTDOWN;
 
     /* put the bnode at the end of the list so we write bnode file in same order */
-    for (lb = &allBnodes, nb = *lb; nb; lb = &nb->next, nb = *lb);
-    *lb = abnode;
+    opr_queue_Append(&allBnodes, &abnode->q);
 
     return 0;
 }
 
-static int
-DeleteProc(register struct bnode_proc *abproc)
-{
-    register struct bnode_proc **pb, *tb;
-    struct bnode_proc *nb;
-
-    for (pb = &allProcs, tb = *pb; tb; pb = &tb->next, tb = nb) {
-       nb = tb->next;
-       if (tb == abproc) {
-           *pb = nb;
-           free(tb);
-           return 0;
-       }
-    }
-    return BZNOENT;
-}
-
 /* bnode lwp executes this code repeatedly */
 static void *
 bproc(void *unused)
 {
-    register afs_int32 code;
-    register struct bnode *tb;
-    register afs_int32 temp;
-    register struct bnode_proc *tp;
-    struct bnode *nb;
+    afs_int32 code;
+    struct bnode *tb;
+    afs_int32 temp;
+    struct opr_queue *cursor, *store;
+    struct bnode_proc *tp;
     int options;               /* must not be register */
     struct timeval tv;
     int setAny;
@@ -546,7 +530,8 @@ bproc(void *unused)
        /* first figure out how long to sleep for */
        temp = 0x7fffffff;      /* afs_int32 time; maxint doesn't work in select */
        setAny = 0;
-       for (tb = allBnodes; tb; tb = tb->next) {
+       for (opr_queue_Scan(&allBnodes, cursor)) {
+           tb = opr_queue_Entry(cursor, struct bnode, q);
            if (tb->flags & BNODE_NEEDTIMEOUT) {
                if (tb->nextTimeout < temp) {
                    setAny = 1;
@@ -573,7 +558,8 @@ bproc(void *unused)
        temp = tv.tv_sec;
 
        /* check all bnodes to see which ones need timeout events */
-       for (tb = allBnodes; tb; tb = nb) {
+       for (opr_queue_ScanSafe(&allBnodes, cursor, store)) {
+           tb = opr_queue_Entry(cursor, struct bnode, q);
            if ((tb->flags & BNODE_NEEDTIMEOUT) && temp > tb->nextTimeout) {
                bnode_Hold(tb);
                BOP_TIMEOUT(tb);
@@ -581,37 +567,37 @@ bproc(void *unused)
                if (tb->flags & BNODE_NEEDTIMEOUT) {    /* check again, BOP_TIMEOUT could change */
                    tb->nextTimeout = FT_ApproxTime() + tb->period;
                }
-               nb = tb->next;
                bnode_Release(tb);      /* delete may occur here */
-           } else
-               nb = tb->next;
+           }
        }
 
        if (code < 0) {
            /* signalled, probably by incoming signal */
            while (1) {
                options = WNOHANG;
-               bnode_waiting = options | 0x800000;
                code = waitpid((pid_t) - 1, &status, options);
-               bnode_waiting = 0;
                if (code == 0 || code == -1)
                    break;      /* all done */
                /* otherwise code has a process id, which we now search for */
-               for (tp = allProcs; tp; tp = tp->next)
+               for (tp = NULL, opr_queue_Scan(&allProcs, cursor), tp = NULL) {
+                   tp = opr_queue_Entry(cursor, struct bnode_proc, q);
+
                    if (tp->pid == code)
                        break;
+               }
                if (tp) {
                    /* found the pid */
                    tb = tp->bnode;
                    bnode_Hold(tb);
 
-                   /* count restarts in last 10 seconds */
+                   /* count restarts in last 30 seconds */
                    if (temp > tb->rsTime + 30) {
-                       /* it's been 10 seconds we've been counting */
+                       /* it's been 30 seconds we've been counting */
                        tb->rsTime = temp;
                        tb->rsCount = 0;
                    }
 
+
                    if (WIFSIGNALED(status) == 0) {
                        /* exited, not signalled */
                        tp->lastExit = WEXITSTATUS(status);
@@ -661,19 +647,33 @@ bproc(void *unused)
                                 tb->notifier);
                        hdl_notifier(tp);
                    }
-                   BOP_PROCEXIT(tb, tp);
 
-                   bnode_Check(tb);
-                   if (tb->rsCount++ > 10) {
-                       /* 10 in 10 seconds */
+                   if (tb->goal && tb->rsCount++ > 10) {
+                       /* 10 in 30 seconds */
+                       if (tb->errorStopCount >= BNODE_ERROR_COUNT_MAX) {
+                           tb->errorStopDelay = 0;     /* max reached, give up. */
+                       } else {
+                           tb->errorStopCount++;
+                           if (!tb->errorStopDelay) {
+                               tb->errorStopDelay = 1;   /* wait a second, then retry */
+                           } else {
+                               tb->errorStopDelay *= 2;  /* ramp up the retry delays */
+                           }
+                           if (tb->errorStopDelay > BNODE_ERROR_DELAY_MAX) {
+                               tb->errorStopDelay = BNODE_ERROR_DELAY_MAX; /* cap the delay */
+                           }
+                       }
                        tb->flags |= BNODE_ERRORSTOP;
                        bnode_SetGoal(tb, BSTAT_SHUTDOWN);
                        bozo_Log
                            ("BNODE '%s' repeatedly failed to start, perhaps missing executable.\n",
                             tb->name);
                    }
+                   BOP_PROCEXIT(tb, tp);
+                   bnode_Check(tb);
                    bnode_Release(tb);  /* bnode delete can happen here */
-                   DeleteProc(tp);
+                   opr_queue_Remove(&tp->q);
+                   free(tp);
                } else
                    bnode_stats.weirdPids++;
            }
@@ -683,11 +683,11 @@ bproc(void *unused)
 }
 
 static afs_int32
-SendNotifierData(register int fd, register struct bnode_proc *tp)
+SendNotifierData(int fd, struct bnode_proc *tp)
 {
-    register struct bnode *tb = tp->bnode;
+    struct bnode *tb = tp->bnode;
     char buffer[1000], *bufp = buffer, *buf1;
-    register int len;
+    int len;
 
     /*
      * First sent out the bnode_proc struct
@@ -700,15 +700,15 @@ SendNotifierData(register int fd, register struct bnode_proc *tp)
        buf1 = "(null)";
     (void)sprintf(bufp, "coreName: %s\n", buf1);
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "pid: %ld\n", tp->pid);
+    (void)sprintf(bufp, "pid: %ld\n", afs_printable_int32_ld(tp->pid));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "lastExit: %ld\n", tp->lastExit);
+    (void)sprintf(bufp, "lastExit: %ld\n", afs_printable_int32_ld(tp->lastExit));
     bufp += strlen(bufp);
 #ifdef notdef
-    (void)sprintf(bufp, "lastSignal: %ld\n", tp->lastSignal);
+    (void)sprintf(bufp, "lastSignal: %ld\n", afs_printable_int32_ld(tp->lastSignal));
     bufp += strlen(bufp);
 #endif
-    (void)sprintf(bufp, "flags: %ld\n", tp->flags);
+    (void)sprintf(bufp, "flags: %ld\n", afs_printable_int32_ld(tp->flags));
     bufp += strlen(bufp);
     (void)sprintf(bufp, "END bnode_proc\n");
     bufp += strlen(bufp);
@@ -725,21 +725,21 @@ SendNotifierData(register int fd, register struct bnode_proc *tp)
     bufp += strlen(bufp);
     (void)sprintf(bufp, "name: %s\n", tb->name);
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "rsTime: %ld\n", tb->rsTime);
+    (void)sprintf(bufp, "rsTime: %ld\n", afs_printable_int32_ld(tb->rsTime));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "rsCount: %ld\n", tb->rsCount);
+    (void)sprintf(bufp, "rsCount: %ld\n", afs_printable_int32_ld(tb->rsCount));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "procStartTime: %ld\n", tb->procStartTime);
+    (void)sprintf(bufp, "procStartTime: %ld\n", afs_printable_int32_ld(tb->procStartTime));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "procStarts: %ld\n", tb->procStarts);
+    (void)sprintf(bufp, "procStarts: %ld\n", afs_printable_int32_ld(tb->procStarts));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "lastAnyExit: %ld\n", tb->lastAnyExit);
+    (void)sprintf(bufp, "lastAnyExit: %ld\n", afs_printable_int32_ld(tb->lastAnyExit));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "lastErrorExit: %ld\n", tb->lastErrorExit);
+    (void)sprintf(bufp, "lastErrorExit: %ld\n", afs_printable_int32_ld(tb->lastErrorExit));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "errorCode: %ld\n", tb->errorCode);
+    (void)sprintf(bufp, "errorCode: %ld\n", afs_printable_int32_ld(tb->errorCode));
     bufp += strlen(bufp);
-    (void)sprintf(bufp, "errorSignal: %ld\n", tb->errorSignal);
+    (void)sprintf(bufp, "errorSignal: %ld\n", afs_printable_int32_ld(tb->errorSignal));
     bufp += strlen(bufp);
 /*
     (void) sprintf(bufp, "lastErrorName: %s\n", tb->lastErrorName);
@@ -753,13 +753,14 @@ SendNotifierData(register int fd, register struct bnode_proc *tp)
     if (write(fd, buffer, len) < 0) {
        return -1;
     }
+    return 0;
 }
 
 int
 hdl_notifier(struct bnode_proc *tp)
 {
 #ifndef AFS_NT40_ENV           /* NT notifier callout not yet implemented */
-    int code, pid, status;
+    int pid;
     struct stat tstat;
 
     if (stat(tp->bnode->notifier, &tstat)) {
@@ -770,16 +771,15 @@ hdl_notifier(struct bnode_proc *tp)
     if ((pid = fork()) == 0) {
        FILE *fout;
        struct bnode *tb = tp->bnode;
-       int ec;
 
 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI51_ENV)
-       ec = setsid();
+       setsid();
 #elif defined(AFS_DARWIN90_ENV)
-       ec = setpgid(0, 0);
-#elif defined(AFS_LINUX20_ENV) || defined(AFS_AIX_ENV)  
-       ec = setpgrp();
+       setpgid(0, 0);
+#elif defined(AFS_LINUX20_ENV) || defined(AFS_AIX_ENV)
+       setpgrp();
 #else
-       ec = setpgrp(0, 0);
+       setpgrp(0, 0);
 #endif
        fout = popen(tb->notifier, "w");
        if (fout == NULL) {
@@ -788,7 +788,7 @@ hdl_notifier(struct bnode_proc *tp)
            perror(tb->notifier);
            exit(1);
        }
-       code = SendNotifierData(fileno(fout), tp);
+       SendNotifierData(fileno(fout), tp);
        pclose(fout);
        exit(0);
     } else if (pid < 0) {
@@ -808,7 +808,7 @@ bnode_SoftInt(void *param)
     /* int asignal = (int) param; */
 
     IOMGR_Cancel(bproc_pid);
-    return 0;
+    return NULL;
 }
 
 /* Called at signal interrupt level; queues function to be called
@@ -817,26 +817,29 @@ bnode_SoftInt(void *param)
 void
 bnode_Int(int asignal)
 {
-    if (asignal == SIGQUIT) {
-       IOMGR_SoftSig(bozo_ShutdownAndExit, (void *) asignal);
+    if (asignal == SIGQUIT || asignal == SIGTERM) {
+       IOMGR_SoftSig(bozo_ShutdownAndExit, (void *)(intptr_t)asignal);
     } else {
-       IOMGR_SoftSig(bnode_SoftInt, (void *) asignal);
+       IOMGR_SoftSig(bnode_SoftInt, (void *)(intptr_t)asignal);
     }
 }
 
 
 /* intialize the whole system */
 int
-bnode_Init()
+bnode_Init(void)
 {
     PROCESS junk;
-    register afs_int32 code;
+    afs_int32 code;
     struct sigaction newaction;
-    static initDone = 0;
+    static int initDone = 0;
 
     if (initDone)
        return 0;
     initDone = 1;
+    opr_queue_Init(&allTypes);
+    opr_queue_Init(&allProcs);
+    opr_queue_Init(&allBnodes);
     memset(&bnode_stats, 0, sizeof(bnode_stats));
     LWP_InitializeProcessSupport(1, &junk);    /* just in case */
     IOMGR_Initialize();
@@ -845,7 +848,7 @@ bnode_Init()
                             "bnode-manager", &bproc_pid);
     if (code)
        return code;
-    memset((char *)&newaction, 0, sizeof(newaction));
+    memset(&newaction, 0, sizeof(newaction));
     newaction.sa_handler = bnode_Int;
     code = sigaction(SIGCHLD, &newaction, NULL);
     if (code)
@@ -853,14 +856,17 @@ bnode_Init()
     code = sigaction(SIGQUIT, &newaction, NULL);
     if (code)
        return errno;
+    code = sigaction(SIGTERM, &newaction, NULL);
+    if (code)
+       return errno;
     return code;
 }
 
 /* free token list returned by parseLine */
 int
-bnode_FreeTokens(register struct bnode_token *alist)
+bnode_FreeTokens(struct bnode_token *alist)
 {
-    register struct bnode_token *nlist;
+    struct bnode_token *nlist;
     for (; alist; alist = nlist) {
        nlist = alist->next;
        free(alist->key);
@@ -882,11 +888,11 @@ int
 bnode_ParseLine(char *aline, struct bnode_token **alist)
 {
     char tbuffer[256];
-    register char *tptr;
+    char *tptr = NULL;
     int inToken;
     struct bnode_token *first, *last;
-    register struct bnode_token *ttok;
-    register int tc;
+    struct bnode_token *ttok;
+    int tc;
 
     inToken = 0;               /* not copying token chars at start */
     first = (struct bnode_token *)0;
@@ -897,11 +903,9 @@ bnode_ParseLine(char *aline, struct bnode_token **alist)
            if (inToken) {
                inToken = 0;    /* end of this token */
                *tptr++ = 0;
-               ttok =
-                   (struct bnode_token *)malloc(sizeof(struct bnode_token));
+               ttok = malloc(sizeof(struct bnode_token));
                ttok->next = (struct bnode_token *)0;
-               ttok->key = (char *)malloc(strlen(tbuffer) + 1);
-               strcpy(ttok->key, tbuffer);
+               ttok->key = strdup(tbuffer);
                if (last) {
                    last->next = ttok;
                    last = ttok;
@@ -945,9 +949,8 @@ bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName,
     code = bnode_ParseLine(aexecString, &tlist);       /* try parsing first */
     if (code)
        return code;
-    tp = (struct bnode_proc *)malloc(sizeof(struct bnode_proc));
-    memset(tp, 0, sizeof(struct bnode_proc));
-    tp->next = allProcs;
+    tp = calloc(1, sizeof(struct bnode_proc));
+    opr_queue_Init(&tp->q);
     tp->bnode = abnode;
     tp->comLine = aexecString;
     tp->coreName = coreName;   /* may be null */
@@ -969,21 +972,23 @@ bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName,
        free(tp);
        return errno;
     }
+    bozo_Log("%s started pid %ld: %s\n", abnode->name, cpid, aexecString);
 
     bnode_FreeTokens(tlist);
-    allProcs = tp;
+    opr_queue_Prepend(&allProcs, &tp->q);
     *aproc = tp;
     tp->pid = cpid;
     tp->flags = BPROC_STARTED;
     tp->flags &= ~BPROC_EXITED;
+    BOP_PROCSTARTED(abnode, tp);
     bnode_Check(abnode);
     return 0;
 }
 
 int
-bnode_StopProc(register struct bnode_proc *aproc, int asignal)
+bnode_StopProc(struct bnode_proc *aproc, int asignal)
 {
-    register int code;
+    int code;
     if (!(aproc->flags & BPROC_STARTED) || (aproc->flags & BPROC_EXITED))
        return BZNOTACTIVE;
 
@@ -994,21 +999,3 @@ bnode_StopProc(register struct bnode_proc *aproc, int asignal)
     bnode_Check(aproc->bnode);
     return code;
 }
-
-int
-bnode_Deactivate(register struct bnode *abnode)
-{
-    register struct bnode **pb, *tb;
-    struct bnode *nb;
-    if (!(abnode->flags & BNODE_ACTIVE))
-       return BZNOTACTIVE;
-    for (pb = &allBnodes, tb = *pb; tb; tb = nb) {
-       nb = tb->next;
-       if (tb == abnode) {
-           *pb = nb;
-           tb->flags &= ~BNODE_ACTIVE;
-           return 0;
-       }
-    }
-    return BZNOENT;
-}