struct bnode * cron_create(char *ainstance, char *acommand, char *awhen) { struct cronbnode *te; afs_int32 code; char *cmdpath; extern char *copystr(); /* construct local path from canonical (wire-format) path */ if (ConstructLocalBinPath(acommand, &cmdpath)) { bozo_Log("BNODE: command path invalid '%s'\n", acommand); return NULL; } te = (struct cronbnode *)malloc(sizeof(struct cronbnode)); memset(te, 0, sizeof(struct cronbnode)); code = ktime_ParsePeriodic(awhen, &te->whenToRun); if ((code < 0) || (bnode_InitBnode(te, &cronbnode_ops, ainstance) != 0)) { free(te); free(cmdpath); return NULL; } te->when = ktime_next(&te->whenToRun, 0); te->command = cmdpath; te->whenString = copystr(awhen); return (struct bnode *)te; }
static int cron_setstat(register struct cronbnode *abnode, afs_int32 astatus) { if (abnode->waitingForShutdown) return BZBUSY; if (astatus == BSTAT_SHUTDOWN) { if (abnode->running) { /* start shutdown */ bnode_StopProc(abnode->proc, SIGTERM); abnode->waitingForShutdown = 1; bnode_SetTimeout(abnode, SDTIME); /* When shutdown is complete, bproc() calls BOP_PROCEXIT() * [cron_procexit()] which will tell bproc() to no longer * run this cron job. */ } else { /* Tell bproc() to no longer run this cron job */ bnode_SetTimeout(abnode, 0); } } else if (astatus == BSTAT_NORMAL) { /* start the cron job * Figure out when to run next and schedule it */ abnode->when = ktime_next(&abnode->whenToRun, 0); ScheduleCronBnode(abnode); } return 0; }
/* lwp to handle system restarts */ static void * BozoDaemon(void *unused) { afs_int32 now; /* now initialize the values */ bozo_newKTs = 1; while (1) { IOMGR_Sleep(60); now = FT_ApproxTime(); if (bozo_restdisable) { bozo_Log("Restricted mode disabled by signal\n"); bozo_restdisable = 0; } if (bozo_newKTs) { /* need to recompute restart times */ bozo_newKTs = 0; /* done for a while */ nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP); nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP); } /* see if we should do a restart */ if (now > nextRestart) { SBOZO_ReBozo(0); /* doesn't come back */ } /* see if we should restart a server */ if (now > nextDay) { nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP); /* call the bnode restartp function, and restart all that require it */ bnode_ApplyInstance(bdrestart, 0); } } return NULL; }
static int cron_procexit(struct cronbnode *abnode, struct bnode_proc *aproc) { /* process has exited */ /* log interesting errors for folks */ if (aproc->lastSignal) bozo_Log("cron job %s exited due to signal %d\n", abnode->b.name, aproc->lastSignal); else if (aproc->lastExit) bozo_Log("cron job %s exited with non-zero code %d\n", abnode->b.name, aproc->lastExit); abnode->waitingForShutdown = 0; abnode->running = 0; abnode->killSent = 0; abnode->proc = (struct bnode_proc *)0; /* Figure out when to run next and schedule it */ abnode->when = ktime_next(&abnode->whenToRun, 0); ScheduleCronBnode(abnode); return 0; }