} bnode_stats;
extern const char *DoCore;
+extern const char *DoPidFiles;
#ifndef AFS_NT40_ENV
extern char **environ; /* env structure */
#endif
tp->pid = cpid;
tp->flags = BPROC_STARTED;
tp->flags &= ~BPROC_EXITED;
+ BOP_PROCSTARTED(abnode, tp);
bnode_Check(abnode);
return 0;
}
#define BOP_GETPARM(bnode, n, b, l) ((*(bnode)->ops->getparm)((bnode),(n),(b),(l)))
#define BOP_RESTARTP(bnode) ((*(bnode)->ops->restartp)((bnode)))
#define BOP_HASCORE(bnode) ((*(bnode)->ops->hascore)((bnode)))
+#define BOP_PROCSTARTED(bnode,p) ((*(bnode)->ops->procstarted)((bnode),(p)))
struct bnode_proc;
afs_int32 alen);
int (*restartp) ( struct bnode *);
int (*hascore) ( struct bnode *);
+ int (*procstarted) ( struct bnode *, struct bnode_proc * );
};
struct bnode_type {
extern struct bnode *bnode_FindInstance(char *aname);
extern int bnode_WaitStatus(struct bnode *abnode, int astatus);
extern int bnode_SetStat(struct bnode *abnode, int agoal);
+extern int bnode_CreatePidFile(struct bnode *abnode, struct bnode_proc *aproc, char *name);
+extern int bnode_DestroyPidFile(struct bnode *abnode, struct bnode_proc *aproc);
void bozo_Log(char *format, ... );
int bozo_ReBozo(void);
int WriteBozoFile(char *aname);
+int bozo_CreatePidFile(char *ainst, char *aname, pid_t apid);
+int bozo_DeletePidFile(char *ainst, char *aname);
/* bosoprocs.c */
int GetRequiredDirPerm(const char *path);
const char *DoCore;
int DoLogging = 0;
int DoSyslog = 0;
+const char *DoPidFiles = NULL;
#ifndef AFS_NT40_ENV
int DoSyslogFacility = LOG_DAEMON;
#endif
#endif /* ! AFS_NT40_ENV */
#endif
+static char *
+make_pid_filename(char *ainst, char *aname)
+{
+ char *buffer = NULL;
+ int length;
+
+ length = strlen(DoPidFiles) + strlen(ainst) + 6;
+ if (aname && *aname) {
+ length += strlen(aname) + 1;
+ }
+ buffer = malloc(length * sizeof(char));
+ if (!buffer) {
+ if (aname) {
+ bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
+ ainst, aname);
+ } else {
+ bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
+ }
+ } else {
+ if (aname && *aname) {
+ snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
+ aname);
+ } else {
+ snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
+ }
+ }
+ return buffer;
+}
+
+/**
+ * Write a file containing the pid of the named process.
+ *
+ * @param ainst instance name
+ * @param aname sub-process name of the instance, may be null
+ * @param apid process id of the newly started process
+ *
+ * @returns status
+ */
+int
+bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
+{
+ int code = 0;
+ char *pidfile = NULL;
+ FILE *fp;
+
+ pidfile = make_pid_filename(ainst, aname);
+ if (!pidfile) {
+ return ENOMEM;
+ }
+ if ((fp = fopen(pidfile, "w")) == NULL) {
+ bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
+ free(pidfile);
+ return errno;
+ }
+ if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
+ code = errno;
+ }
+ if (fclose(fp) != 0) {
+ code = errno;
+ }
+ free(pidfile);
+ return code;
+}
+
+/**
+ * Clean a pid file for a process which just exited.
+ *
+ * @param ainst instance name
+ * @param aname sub-process name of the instance, may be null
+ *
+ * @returns status
+ */
+int
+bozo_DeletePidFile(char *ainst, char *aname)
+{
+ char *pidfile = NULL;
+ pidfile = make_pid_filename(ainst, aname);
+ if (pidfile) {
+ unlink(pidfile);
+ free(pidfile);
+ }
+ return 0;
+}
+
/* start a process and monitor it */
#include "AFS_component_version_number.c"
printf("Invalid audit interface '%s'\n", interface);
exit(1);
}
+ } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
+ DoPidFiles = (argv[code]+10);
+ } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
+ DoPidFiles = AFSDIR_BOSCONFIG_DIR;
}
else {
"[-syslog[=FACILITY]] "
"[-enable_peer_stats] [-enable_process_stats] "
"[-cores=<none|path>] \n"
+ "[-pidfiles[=path]] "
"[-nofork] " "[-help]\n");
#else
printf("Usage: bosserver [-noauth] [-log] "
"[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
"[-enable_peer_stats] [-enable_process_stats] "
"[-cores=<none|path>] \n"
+ "[-pidfiles[=path]] "
"[-help]\n");
#endif
fflush(stdout);
afsconf_SetNoAuthFlag(tdir, noAuth);
afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
+ if (DoPidFiles) {
+ bozo_CreatePidFile("bosserver", NULL, getpid());
+ }
+
/* Disable jumbograms */
rx_SetNoJumbo();
static int cron_timeout(struct bnode *bnode);
static int cron_getstat(struct bnode *bnode, afs_int32 *status);
static int cron_setstat(struct bnode *bnode, afs_int32 status);
+static int cron_procstarted(struct bnode *bnode, struct bnode_proc *proc);
static int cron_procexit(struct bnode *bnode, struct bnode_proc *proc);
static int cron_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
static int cron_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
cron_getparm,
cron_restartp,
cron_hascore,
+ cron_procstarted,
};
struct cronbnode {
}
static int
+cron_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+ return 0; /* no op */
+}
+
+static int
cron_procexit(struct bnode *bn, struct bnode_proc *aproc)
{
struct cronbnode *abnode = (struct cronbnode *) bn;
#include "bnode.h"
#include "bosprototypes.h"
+extern char *DoPidFiles;
struct bnode *ez_create(char *, char *, char *, char *, char *, char *);
static int ez_hascore(struct bnode *bnode);
static int ez_procexit(struct bnode *bnode, struct bnode_proc *proc);
static int ez_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
static int ez_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
+static int ez_procstarted(struct bnode *bnode, struct bnode_proc *proc);
#define SDTIME 60 /* time in seconds given to a process to evaporate */
ez_getparm,
ez_restartp,
ez_hascore,
+ ez_procstarted
};
static int
}
static int
+ez_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+ int code = 0;
+
+ if (DoPidFiles) {
+ code = bozo_CreatePidFile(bn->name, NULL, aproc->pid);
+ }
+ return code;;
+}
+
+static int
ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
{
struct ezbnode *abnode = (struct ezbnode *)bn;
/* process has exited */
afs_int32 code;
+ if (DoPidFiles) {
+ bozo_DeletePidFile(bn->name, NULL);
+ }
+
abnode->waitingForShutdown = 0;
abnode->running = 0;
abnode->killSent = 0;
#include "bnode.h"
#include "bosprototypes.h"
+extern char *DoPidFiles;
static int emergency = 0;
/* if this file exists, then we have to salvage the file system */
static int fs_timeout(struct bnode *abnode);
static int fs_getstat(struct bnode *abnode, afs_int32 * astatus);
static int fs_setstat(struct bnode *abnode, afs_int32 astatus);
+static int fs_procstarted(struct bnode *abnode, struct bnode_proc *aproc);
static int fs_procexit(struct bnode *abnode, struct bnode_proc *aproc);
static int fs_getstring(struct bnode *abnode, char *abuffer, afs_int32 alen);
static int fs_getparm(struct bnode *abnode, afs_int32 aindex,
fs_getparm,
fs_restartp,
fs_hascore,
+ fs_procstarted,
};
/* demand attach fs bnode ops */
dafs_getparm,
fs_restartp,
fs_hascore,
+ fs_procstarted,
};
/* Quick inline function to safely convert a fsbnode to a bnode without
}
static int
+fs_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+ int code = 0;
+
+ if (DoPidFiles) {
+ code = bozo_CreatePidFile(bn->name, aproc->coreName, aproc->pid);
+ }
+ return code;
+}
+
+static int
fs_procexit(struct bnode *bn, struct bnode_proc *aproc)
{
struct fsbnode *abnode = (struct fsbnode *)bn;
/* process has exited */
+ if (DoPidFiles) {
+ bozo_DeletePidFile(bn->name, aproc->coreName);
+ }
+
if (aproc == abnode->volProc) {
abnode->volProc = 0;
abnode->volRunning = 0;