static int ez_setstat(struct bnode *bn, afs_int32 astatus) { struct ezbnode *abnode = (struct ezbnode *)bn; struct bnode_proc *tp; afs_int32 code; if (abnode->waitingForShutdown) return BZBUSY; if (astatus == BSTAT_NORMAL && !abnode->running) { /* start up */ abnode->lastStart = FT_ApproxTime(); code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp); if (code) return code; abnode->running = 1; abnode->proc = tp; return 0; } else if (astatus == BSTAT_SHUTDOWN && abnode->running) { /* start shutdown */ bnode_StopProc(abnode->proc, SIGTERM); abnode->waitingForShutdown = 1; bnode_SetTimeout((struct bnode *)abnode, SDTIME); return 0; } return 0; }
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; }
/* called to SIGKILL a process if it doesn't terminate normally. In cron, also start up a process if it is time and not already running */ static int cron_timeout(struct bnode *bn) { struct cronbnode *abnode = (struct cronbnode *)bn; register afs_int32 temp; register afs_int32 code; struct bnode_proc *tp; if (!abnode->running) { if (abnode->when == 0) return 0; /* spurious timeout activation */ /* not running, perhaps we should start it */ if (FT_ApproxTime() >= abnode->when) { abnode->lastStart = FT_ApproxTime(); bnode_SetTimeout((struct bnode *)abnode, 0); code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp); if (code) { bozo_Log("cron failed to start bnode %s (code %d)\n", abnode->b.name, code); return code; } abnode->everRun = 1; abnode->running = 1; abnode->proc = tp; } else { /* woke up too early, try again */ temp = abnode->when - FT_ApproxTime(); if (temp < 1) temp = 1; bnode_SetTimeout((struct bnode *)abnode, temp); } } else { if (!abnode->waitingForShutdown) return 0; /* spurious */ /* send kill and turn off timer */ bnode_StopProc(abnode->proc, SIGKILL); abnode->killSent = 1; bnode_SetTimeout((struct bnode *)abnode, 0); } return 0; }
/* called to SIGKILL a process if it doesn't terminate normally * or to retry start after an error stop. */ static int ez_timeout(struct bnode *bn) { struct ezbnode *abnode = (struct ezbnode *)bn; if (abnode->waitingForShutdown) { /* send kill and turn off timer */ bnode_StopProc(abnode->proc, SIGKILL); abnode->killSent = 1; bnode_SetTimeout((struct bnode *)abnode, 0); } else if (!abnode->running && abnode->b.flags & BNODE_ERRORSTOP) { /* was stopped for too many errors, retrying */ /* reset error count after running for a bit */ bnode_SetTimeout(bn, ERROR_RESET_TIME); bnode_SetStat(bn, BSTAT_NORMAL); } else { bnode_SetTimeout(bn, 0); /* one shot timer */ bnode_ResetErrorCount(bn); } return 0; }