#include <afsconfig.h>
#include <afs/param.h>
-RCSID
- ("$Header$");
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
+#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
#ifdef AFS_NT40_ENV
#include <io.h>
#else
#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 "bnode.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)
int weirdPids;
} bnode_stats;
+extern const char *DoCore;
#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)
int
bnode_CoreName(register struct bnode *abnode, char *acoreName, char *abuffer)
{
- strcpy(abuffer, AFSDIR_SERVER_CORELOG_FILEPATH);
+ 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, ".");
{
char tbuffer[256];
struct stat tstat;
- register afs_int32 code;
+ register afs_int32 code = 0;
+ char *corefile = NULL;
#ifdef BOZO_SAVE_CORES
struct timeval Start;
struct tm *TimeFields;
char FileName[256];
#endif
- code = stat(AFSDIR_SERVER_CORELOG_FILEPATH, &tstat);
+ /* 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. */
+ 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;
+ size_t length;
+ unsigned long pid;
+ const char *coredir = AFSDIR_LOGS_DIR;
+
+ if (DoCore)
+ coredir = DoCore;
+
+ logdir = opendir(coredir);
+ if (logdir == NULL)
+ return;
+ while ((file = readdir(logdir)) != NULL) {
+ if (strncmp(file->d_name, "core.", 5) != 0)
+ continue;
+ pid = atol(file->d_name + 5);
+ if (pid == aproc->pid) {
+ length = strlen(coredir) + strlen(file->d_name) + 2;
+ corefile = malloc(length);
+ if (corefile == NULL) {
+ closedir(logdir);
+ return;
+ }
+ snprintf(corefile, length, "%s/%s", coredir, file->d_name);
+ code = 0;
+ break;
+ }
+ }
+ closedir(logdir);
+ } else {
+ corefile = strdup(tbuffer);
+ }
if (code)
return;
bnode_CoreName(abnode, aproc->coreName, tbuffer);
#ifdef BOZO_SAVE_CORES
- TM_GetTimeOfDay(&Start, 0);
+ FT_GetTimeOfDay(&Start, 0);
TimeFields = localtime(&Start.tv_sec);
sprintf(FileName, "%s.%d%02d%02d%02d%02d%02d", tbuffer,
- TimeFields->tm_year, TimeFields->tm_mon + 1, TimeFields->tm_mday,
+ TimeFields->tm_year + 1900, TimeFields->tm_mon + 1, TimeFields->tm_mday,
TimeFields->tm_hour, TimeFields->tm_min, TimeFields->tm_sec);
strcpy(tbuffer, FileName);
#endif
- code = renamefile(AFSDIR_SERVER_CORELOG_FILEPATH, tbuffer);
+ code = renamefile(corefile, tbuffer);
+ free(corefile);
}
int
/* wait for all bnodes to stabilize */
int
-bnode_WaitAll()
+bnode_WaitAll(void)
{
register struct bnode *tb;
register afs_int32 code;
/* 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;
}
/* bnode lwp executes this code repeatedly */
-static int
-bproc()
+static void *
+bproc(void *unused)
{
register afs_int32 code;
register struct bnode *tb;
}
}
}
+ return NULL;
}
static afs_int32
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);
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);
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 code, pid;
struct stat tstat;
if (stat(tp->bnode->notifier, &tstat)) {
/* Called by IOMGR at low priority on IOMGR's stack shortly after a SIGCHLD
* occurs. Wakes up bproc do redo things */
-int
-bnode_SoftInt(int asignal)
+void *
+bnode_SoftInt(void *param)
{
+ /* int asignal = (int) param; */
+
IOMGR_Cancel(bproc_pid);
return 0;
}
void
bnode_Int(int asignal)
{
- extern void bozo_ShutdownAndExit();
-
- if (asignal == SIGQUIT) {
- IOMGR_SoftSig(bozo_ShutdownAndExit, (char *)asignal);
+ if (asignal == SIGQUIT || asignal == SIGTERM) {
+ IOMGR_SoftSig(bozo_ShutdownAndExit, (void *)(intptr_t)asignal);
} else {
- IOMGR_SoftSig(bnode_SoftInt, (char *)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;
struct sigaction newaction;
- static initDone = 0;
+ static int initDone = 0;
if (initDone)
return 0;
"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)
code = sigaction(SIGQUIT, &newaction, NULL);
if (code)
return errno;
+ code = sigaction(SIGTERM, &newaction, NULL);
+ if (code)
+ return errno;
return code;
}
bnode_ParseLine(char *aline, struct bnode_token **alist)
{
char tbuffer[256];
- register char *tptr;
+ register char *tptr = NULL;
int inToken;
struct bnode_token *first, *last;
register struct bnode_token *ttok;
return 0;
}
}
+ return 0;
}
#define MAXVARGS 128