modernize-bozo-20020821
[openafs.git] / src / bozo / bnode.c
index fcc5e81..2b52241 100644 (file)
@@ -7,8 +7,8 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
-#include <afs/param.h>
 #include <afsconfig.h>
+#include <afs/param.h>
 
 RCSID("$Header$");
 
@@ -27,6 +27,15 @@ RCSID("$Header$");
 #include <time.h>
 #endif
 #include <sys/stat.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
 #include <afs/procmgmt.h>  /* signal(), kill(), wait(), etc. */
 #include <lwp.h>
 #include <afs/audit.h>
@@ -34,6 +43,11 @@ RCSID("$Header$");
 #include <afs/fileutil.h>
 #include "bnode.h"
 
+#ifdef AFS_AIX_ENV
+/* All known versions of AIX lack WCOREDUMP but this works */
+#define WCOREDUMP(x) ((x) & 0x80)
+#endif
+
 #define BNODE_LWP_STACKSIZE    (16 * 1024)
 
 int bnode_waiting = 0;
@@ -54,14 +68,14 @@ extern char **environ;                      /* env structure */
 #endif
 
 /* Remember the name of the process, if any, that failed last */
-static void RememberProcName(ap)
-register struct bnode_proc *ap; {
+static void RememberProcName(register struct bnode_proc *ap)
+{
     register struct bnode *tbnodep;
 
     tbnodep = ap->bnode;
     if (tbnodep->lastErrorName) {
        free(tbnodep->lastErrorName);
-       tbnodep->lastErrorName = (char *) 0;
+       tbnodep->lastErrorName = NULL;
     }
     if (ap->coreName) {
        tbnodep->lastErrorName = (char *) malloc(strlen(ap->coreName)+1);
@@ -72,10 +86,9 @@ register struct bnode_proc *ap; {
 /* utility for use by BOP_HASCORE functions to determine where a core file might
  * be stored.
  */
-bnode_CoreName(abnode, acoreName, abuffer)
-register struct bnode *abnode;
-char *acoreName;
-char *abuffer; {
+int bnode_CoreName(register struct bnode *abnode, char *acoreName, 
+                  char *abuffer)
+{
     strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH);
     if (acoreName) {
        strcat(abuffer, acoreName);
@@ -86,9 +99,9 @@ char *abuffer; {
 }
 
 /* save core file, if any */
-static void SaveCore(abnode, aproc)
-register struct bnode_proc *aproc;
-register struct bnode *abnode; {
+static void SaveCore(register struct bnode *abnode, register struct bnode_proc
+                    *aproc)
+{
     char tbuffer[256];
     struct stat tstat;
     register afs_int32 code;
@@ -114,34 +127,30 @@ register struct bnode *abnode; {
     code = renamefile(AFSDIR_SERVER_CORELOG_FILEPATH, tbuffer);
 }
 
-bnode_GetString(abnode, abuffer, alen)
-register struct bnode *abnode;
-register char *abuffer;
-register afs_int32 alen;{
+int bnode_GetString(register struct bnode *abnode, register char *abuffer,
+register afs_int32 alen)
+{
     return BOP_GETSTRING(abnode, abuffer, alen);
 }
 
-bnode_GetParm(abnode, aindex, abuffer, alen)
-register struct bnode *abnode;
-register afs_int32 aindex;
-register char *abuffer;
-afs_int32 alen; {
+int bnode_GetParm(register struct bnode *abnode, register afs_int32 aindex, 
+                 register char *abuffer, afs_int32 alen)
+{
     return BOP_GETPARM(abnode, aindex, abuffer, alen);
 }
 
-bnode_GetStat(abnode, astatus)
-register struct bnode *abnode;
-register afs_int32 *astatus; {
+int bnode_GetStat(register struct bnode *abnode, register afs_int32 *astatus)
+{
     return BOP_GETSTAT(abnode, astatus);
 }
 
-bnode_RestartP(abnode)
-register struct bnode *abnode; {
+int bnode_RestartP(register struct bnode *abnode)
+{
     return BOP_RESTARTP(abnode);
 }
 
-static bnode_Check(abnode)
-register struct bnode *abnode; {
+static int bnode_Check(register struct bnode *abnode)
+{
     if (abnode->flags & BNODE_WAIT) {
        abnode->flags &= ~BNODE_WAIT;
        LWP_NoYieldSignal(abnode);
@@ -150,13 +159,13 @@ register struct bnode *abnode; {
 }
 
 /* tell if an instance has a core file */
-bnode_HasCore(abnode)
-register struct bnode *abnode; {
+int bnode_HasCore(register struct bnode *abnode)
+{
     return BOP_HASCORE(abnode);
 }
 
 /* wait for all bnodes to stabilize */
-bnode_WaitAll() {
+int bnode_WaitAll() {
     register struct bnode *tb;
     register afs_int32 code;
     afs_int32 stat;
@@ -181,9 +190,8 @@ bnode_WaitAll() {
 }
 
 /* wait until bnode status is correct */
-bnode_WaitStatus(abnode, astatus)
-int astatus;
-register struct bnode *abnode; {
+int bnode_WaitStatus(register struct bnode *abnode, int astatus)
+{
     register afs_int32 code;
     afs_int32 stat;
 
@@ -208,9 +216,8 @@ register struct bnode *abnode; {
     }
 }
 
-bnode_SetStat(abnode, agoal)
-register struct bnode *abnode;
-register int agoal; {
+int bnode_SetStat(register struct bnode *abnode, register int agoal)
+{
     abnode->goal = agoal;
     bnode_Check(abnode);
     BOP_SETSTAT(abnode, agoal);
@@ -218,17 +225,15 @@ register int agoal; {
     return 0;
 }
 
-bnode_SetGoal(abnode, agoal)
-register struct bnode *abnode;
-register int agoal; {
+int bnode_SetGoal(register struct bnode *abnode, register int agoal)
+{
     abnode->goal = agoal;
     bnode_Check(abnode);
     return 0;
 }
 
-bnode_SetFileGoal(abnode, agoal)
-register struct bnode *abnode;
-register int agoal; {
+int bnode_SetFileGoal(register struct bnode *abnode, register int agoal)
+{
     if (abnode->fileGoal == agoal) return 0;   /* already done */
     abnode->fileGoal = agoal;
     WriteBozoFile(0);
@@ -236,9 +241,8 @@ register int agoal; {
 }
 
 /* apply a function to all bnodes in the system */
-int bnode_ApplyInstance(aproc, arock)
-int (*aproc)();
-char *arock; {
+int bnode_ApplyInstance(int (*aproc)(), char *arock)
+{
     register struct bnode *tb, *nb;
     register afs_int32 code;
 
@@ -250,18 +254,18 @@ char *arock; {
     return 0;
 }
 
-struct bnode *bnode_FindInstance (aname)
-register char *aname; {
+struct bnode *bnode_FindInstance(register char *aname)
+{
     register struct bnode *tb;
     
     for(tb=allBnodes;tb;tb=tb->next) {
        if (!strcmp(tb->name, aname)) return tb;
     }
-    return (struct bnode *) 0;
+    return NULL;
 }
 
-static struct bnode_type *FindType(aname)
-register char *aname; {
+static struct bnode_type *FindType(register char *aname)
+{
     register struct bnode_type *tt;
     
     for(tt=allTypes;tt;tt=tt->next) {
@@ -270,10 +274,8 @@ register char *aname; {
     return (struct bnode_type *) 0;
 }
 
-bnode_Register(atype, aprocs, anparms)
-char *atype;
-int anparms;       /* number of parms to create */
-struct bnode_ops *aprocs; {
+int bnode_Register(char *atype, struct bnode_ops *aprocs, int anparms)
+{
     register struct bnode_type *tt;
 
     for(tt=allTypes;tt;tt=tt->next) {
@@ -281,7 +283,7 @@ struct bnode_ops *aprocs; {
     }
     if (!tt) {
        tt = (struct bnode_type *) malloc(sizeof(struct bnode_type));
-       bzero(tt, sizeof(struct bnode_type));
+       memset(tt, 0, sizeof(struct bnode_type));
        tt->next = allTypes;
        allTypes = tt;
        tt->name = atype;
@@ -290,12 +292,10 @@ struct bnode_ops *aprocs; {
     return 0;
 }
 
-afs_int32 bnode_Create(atype, ainstance, abp, ap1, ap2, ap3, ap4, ap5, notifier,fileGoal)
-char *atype;
-char *ainstance;
-struct bnode **abp;
-char *ap1, *ap2, *ap3, *ap4, *ap5, *notifier; 
-int fileGoal;{
+afs_int32 bnode_Create(char *atype, char *ainstance, struct bnode **abp, 
+                      char *ap1, char *ap2, char *ap3, char *ap4, 
+                      char *ap5, char *notifier, int fileGoal)
+{
     struct bnode_type *type;
     struct bnode *tb;
     char *notifierpath = NULL;
@@ -337,8 +337,8 @@ int fileGoal;{
     return 0;
 }
 
-int bnode_DeleteName(ainstance)
-char *ainstance; {
+int bnode_DeleteName(char *ainstance)
+{
     register struct bnode *tb;
 
     tb = bnode_FindInstance(ainstance);
@@ -347,14 +347,14 @@ char *ainstance; {
     return bnode_Delete(tb);
 }
 
-bnode_Hold(abnode)
-register struct bnode *abnode; {
+int bnode_Hold(register struct bnode *abnode)
+{
     abnode->refCount++;
     return 0;
 }
 
-bnode_Release(abnode)
-register struct bnode *abnode; {
+int bnode_Release(register struct bnode *abnode)
+{
     abnode->refCount--;
     if (abnode->refCount == 0 && abnode->flags & BNODE_DELETE) {
        abnode->flags &= ~BNODE_DELETE; /* we're going for it */
@@ -363,8 +363,8 @@ register struct bnode *abnode; {
     return 0;
 }
 
-int bnode_Delete(abnode)
-register struct bnode *abnode; {
+int bnode_Delete(register struct bnode *abnode)
+{
     register afs_int32 code;
     register struct bnode **lb, *ub;
     afs_int32 temp;
@@ -396,15 +396,14 @@ register struct bnode *abnode; {
 }
 
 /* function to tell if there's a timeout coming up */
-int bnode_PendingTimeout(abnode)
-register struct bnode *abnode; {
+int bnode_PendingTimeout(register struct bnode *abnode)
+{
     return (abnode->flags & BNODE_NEEDTIMEOUT);
 }
 
 /* function called to set / clear periodic bnode wakeup times */
-int bnode_SetTimeout(abnode, atimeout)
-register struct bnode *abnode;
-afs_int32 atimeout; {
+int bnode_SetTimeout(register struct bnode *abnode, afs_int32 atimeout)
+{
     if (atimeout != 0) {
        abnode->nextTimeout = FT_ApproxTime() + atimeout;
        abnode->flags |= BNODE_NEEDTIMEOUT;
@@ -418,16 +417,17 @@ afs_int32 atimeout; {
 }
 
 /* used by new bnode creation code to format bnode header */
-int bnode_InitBnode (abnode, abnodeops, aname)
-register struct bnode *abnode;
-char *aname;
-struct bnode_ops *abnodeops; {
+int bnode_InitBnode (register struct bnode *abnode, 
+                    struct bnode_ops *abnodeops, char *aname) 
+{
     struct bnode **lb, *nb;
 
     /* format the bnode properly */
-    bzero(abnode, sizeof(struct bnode));
+    memset(abnode, 0, sizeof(struct bnode));
     abnode->ops = abnodeops;
     abnode->name = (char *) malloc(strlen(aname)+1);
+    if (!abnode->name)
+       return ENOMEM;
     strcpy(abnode->name, aname);
     abnode->flags = BNODE_ACTIVE;
     abnode->fileGoal = BSTAT_NORMAL;
@@ -528,6 +528,12 @@ static int bproc() {
                            RememberProcName(tp);
                            tb->errorSignal = 0;
                        }
+                       if (tp->coreName)
+                           bozo_Log("%s:%s exited with code %d\n",
+                               tb->name, tp->coreName, tp->lastExit);
+                       else
+                           bozo_Log("%s exited with code %d\n",
+                               tb->name, tp->lastExit);
                    }
                    else {
                        /* Signal occurred, perhaps spurious due to shutdown request.
@@ -542,6 +548,14 @@ static int bproc() {
                            tb->lastErrorExit = FT_ApproxTime();
                            RememberProcName(tp);
                        }
+                       if (tp->coreName)
+                           bozo_Log("%s:%s exited on signal %d%s\n",
+                               tb->name, tp->coreName, tp->lastSignal,
+                               WCOREDUMP(status) ? " (core dumped)" : "");
+                       else
+                           bozo_Log("%s exited on signal %d%s\n",
+                               tb->name, tp->lastSignal,
+                               WCOREDUMP(status) ? " (core dumped)" : "");
                        SaveCore(tb, tp);
                    }
                    tb->lastAnyExit = FT_ApproxTime();
@@ -570,19 +584,7 @@ static int bproc() {
 }
 
 
-#ifdef notdef
-sigcatch()
-{
-    signal(SIGPIPE, SIG_IGN);
-    bozo_Log("Notifier aborted prematurely");
-    exit(0);
-}
-#endif
-
-
-
-hdl_notifier(tp) 
-    struct bnode_proc *tp;
+int hdl_notifier(struct bnode_proc *tp)
 {
 #ifndef AFS_NT40_ENV  /* NT notifier callout not yet implemented */
     int code, pid, status;
@@ -624,9 +626,8 @@ hdl_notifier(tp)
 }
 
 
-static afs_int32 SendNotifierData(fd, tp)
-    register int fd;
-    register struct bnode_proc *tp;
+static afs_int32 SendNotifierData(register int fd, 
+                                 register struct bnode_proc *tp)
 {
     register struct bnode *tb = tp->bnode;
     char buffer[1000], *bufp = buffer, *buf1;
@@ -702,7 +703,7 @@ static afs_int32 SendNotifierData(fd, tp)
     
 /* Called by IOMGR at low priority on IOMGR's stack shortly after a SIGCHLD
  * occurs.  Wakes up bproc do redo things */
-bnode_SoftInt(int asignal)
+int bnode_SoftInt(int asignal)
 {
     IOMGR_Cancel(bproc_pid);
     return 0;
@@ -711,8 +712,7 @@ bnode_SoftInt(int asignal)
 /* Called at signal interrupt level; queues function to be called
  * when IOMGR runs again.
  */
-void
-bnode_Int(int asignal)
+void bnode_Int(int asignal)
 {
     extern void bozo_ShutdownAndExit();
 
@@ -733,13 +733,13 @@ int bnode_Init() {
 
     if (initDone) return 0;
     initDone = 1;
-    bzero(&bnode_stats, sizeof(bnode_stats));
+    memset(&bnode_stats, 0, sizeof(bnode_stats));
     LWP_InitializeProcessSupport(1, &junk); /* just in case */
     IOMGR_Initialize();
     code = LWP_CreateProcess(bproc, BNODE_LWP_STACKSIZE,
                             /* priority */ 1, /* parm */0, "bnode-manager", &bproc_pid);
     if (code) return code;
-    bzero((char *)&newaction, sizeof(newaction));
+    memset((char *)&newaction, 0, sizeof(newaction));
     newaction.sa_handler = bnode_Int;
     code = sigaction(SIGCHLD, &newaction, NULL);
     if (code) return errno;
@@ -749,8 +749,8 @@ int bnode_Init() {
 }
     
 /* free token list returned by parseLine */
-bnode_FreeTokens(alist)
-    register struct bnode_token *alist; {
+int bnode_FreeTokens(register struct bnode_token *alist)
+{
     register struct bnode_token *nlist;
     for(; alist; alist = nlist) {
        nlist = alist->next;
@@ -760,15 +760,14 @@ bnode_FreeTokens(alist)
     return 0;
 }
 
-static space(x)
-int x; {
+static int space(int x)
+{
     if (x == 0 || x == ' ' || x == '\t' || x== '\n') return 1;
     else return 0;
 }
 
-bnode_ParseLine(aline, alist)
-    char *aline;
-    struct bnode_token **alist; {
+int bnode_ParseLine(char *aline, struct bnode_token **alist)
+{
     char tbuffer[256];
     register char *tptr;
     int inToken;
@@ -816,11 +815,9 @@ bnode_ParseLine(aline, alist)
 }
 
 #define        MAXVARGS            128
-int bnode_NewProc(abnode, aexecString, coreName, aproc)
-struct bnode_proc **aproc;
-char *coreName;
-struct bnode *abnode;
-char *aexecString; {
+int bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName, 
+                 struct bnode_proc **aproc)
+{
     struct bnode_token *tlist, *tt;
     afs_int32 code;
     struct bnode_proc *tp;
@@ -831,7 +828,7 @@ char *aexecString; {
     code = bnode_ParseLine(aexecString, &tlist);  /* try parsing first */
     if (code) return code;
     tp = (struct bnode_proc *) malloc(sizeof(struct bnode_proc));
-    bzero(tp, sizeof(struct bnode_proc));
+    memset(tp, 0, sizeof(struct bnode_proc));
     tp->next = allProcs;
     allProcs = tp;
     *aproc = tp;
@@ -845,7 +842,7 @@ char *aexecString; {
     for (tt = tlist, i = 0; i < (MAXVARGS - 1) && tt; tt = tt->next, i++) {
        argv[i] = tt->key;
     }
-    argv[i] = (char *) 0;   /* null-terminated */
+    argv[i] = NULL;   /* null-terminated */
 
     cpid = spawnprocve(argv[0], argv, environ, -1);
     osi_audit(BOSSpawnProcEvent, 0, AUD_STR, aexecString, AUD_END );
@@ -865,22 +862,21 @@ char *aexecString; {
     return 0;
 }
 
-int bnode_StopProc(aproc, asignal)
-register struct bnode_proc *aproc;
-int asignal; {
+int bnode_StopProc(register struct bnode_proc *aproc, int asignal)
+{
     register int code;
     if (!(aproc->flags & BPROC_STARTED) || (aproc->flags & BPROC_EXITED))
        return BZNOTACTIVE;
 
-    osi_audit( BOSStopProcEvent, 0, AUD_STR, (aproc ? aproc->comLine : (char *)0), AUD_END );
+    osi_audit( BOSStopProcEvent, 0, AUD_STR, (aproc ? aproc->comLine : NULL), AUD_END );
 
     code = kill(aproc->pid, asignal);
     bnode_Check(aproc->bnode);
     return code;
 }
 
-int bnode_Deactivate(abnode)
-register struct bnode *abnode; {
+int bnode_Deactivate(register struct bnode *abnode)
+{
     register struct bnode **pb, *tb;
     struct bnode *nb;
     if (!(abnode->flags & BNODE_ACTIVE)) return BZNOTACTIVE;
@@ -895,8 +891,8 @@ register struct bnode *abnode; {
     return BZNOENT;
 }
 
-static int DeleteProc(abproc)
-register struct bnode_proc *abproc; {
+static int DeleteProc(register struct bnode_proc *abproc)
+{
     register struct bnode_proc **pb, *tb;
     struct bnode_proc *nb;