#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"
#ifndef WCOREDUMP
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 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;
if (code) {
DIR *logdir;
struct dirent *file;
- size_t length;
unsigned long pid;
const char *coredir = AFSDIR_LOGS_DIR;
continue;
pid = atol(file->d_name + 5);
if (pid == aproc->pid) {
- length = strlen(coredir) + 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", coredir, file->d_name);
code = 0;
break;
}
TimeFields->tm_hour, TimeFields->tm_min, TimeFields->tm_sec);
strcpy(tbuffer, FileName);
#endif
- code = renamefile(corefile, tbuffer);
+ code = rk_rename(corefile, tbuffer);
free(corefile);
}
static struct bnode_type *
FindType(char *aname)
{
- 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)
{
- 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;
return 0;
}
-static int
-DeleteProc(struct bnode_proc *abproc)
-{
- 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)
afs_int32 code;
struct bnode *tb;
afs_int32 temp;
+ struct opr_queue *cursor;
struct bnode_proc *tp;
struct bnode *nb;
int options; /* must not be register */
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;
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++;
}
if (initDone)
return 0;
initDone = 1;
+ opr_queue_Init(&allTypes);
+ opr_queue_Init(&allProcs);
memset(&bnode_stats, 0, sizeof(bnode_stats));
LWP_InitializeProcessSupport(1, &junk); /* just in case */
IOMGR_Initialize();
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 = strdup(tbuffer);
if (last) {
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 */
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;