static void operateHost (char *host, int opCode, int confirm) { char msg1[MAXLINELEN]; char msg[MAXLINELEN]; if (opCode == LIM_CMD_REBOOT) sprintf(msg1, I18N(256, "Restart LIM on <%s>"), host); /* catgets 256 */ else sprintf(msg1, I18N(257, "Shut down LIM on <%s>"), host); /* catgets 257 */ if (confirm) { sprintf(msg, "%s ? [y/n] ", msg1); if (!getConfirm(msg)) return; } fprintf(stderr, "%s ...... ", msg1); fflush(stderr); if (ls_limcontrol(host, opCode) == -1) { ls_perror ("ls_limcontrol"); exitrc = -1; } else { char *delay = getenv("LSF_RESTART_DELAY"); int delay_time; if (delay == 0) delay_time = 500; else delay_time = atoi(delay) * 1000; millisleep_(delay_time); fprintf (stderr, "%s\n", I18N_done); } fflush(stderr); }
int nb_write_fix(int s, char *buf, int len) { int cc; int length; struct timeval start, now; struct timezone junk; gettimeofday(&start, &junk); for (length = len; len > 0 ; ) { if ((cc = write(s, buf, len)) > 0) { len -= cc; buf += cc; } else if (cc < 0 && BAD_IO_ERR(errno)) { if (errno == EPIPE) lserrno = LSE_LOSTCON; return (-1); } if (len > 0) { gettimeofday(&now, &junk); if (US_DIFF(now, start) > IO_TIMEOUT * 1000) { errno = ETIMEDOUT; return(-1); } millisleep_(IO_TIMEOUT / 20); } } return (length); }
static FILE * openPIMFile(char *pfile) { static char fname[] = "openPIMFile"; FILE *fp; if ((fp = fopen(pfile, "r")) == NULL) { millisleep_(1000); if ((fp = fopen(pfile, "r")) == NULL) { if (logclass & LC_PIM) ls_syslog(LOG_DEBUG, "%s: fopen(%s) failed: %m", fname, pfile); lserrno = LSE_FILE_SYS; return (NULL); } } return (fp); }
int nb_read_fix (int s, char *buf, int len) { int cc; int length; struct timeval start, now; struct timezone junk; if (logclass & LC_TRACE) ls_syslog (LOG_DEBUG, "nb_read_fix: Entering this routine..."); gettimeofday (&start, &junk); for (length = len; len > 0;) { if ((cc = read (s, buf, len)) > 0) { len -= cc; buf += cc; } else if (cc == 0 || BAD_IO_ERR (errno)) { if (cc == 0) errno = ECONNRESET; return (-1); } if (len > 0) { gettimeofday (&now, &junk); if (US_DIFF (now, start) > IO_TIMEOUT * 1000) { errno = ETIMEDOUT; return (-1); } millisleep_ (IO_TIMEOUT / 20); } } return (length); }
int main(int argc, char **argv) { static char fname[] = "res/main"; int nready; int maxfd; int i; char *sp; char *pathname = NULL; int didSomething = 0; char exbuf; time_t thisPeriodic, lastPeriodic = 0, timeDiff; fd_set rm, wm, em; int sbdPty = FALSE; char *sbdClHost = NULL; ushort sbdClPort = 0; char **sbdArgv = NULL; int selectError = 0; _i18n_init(I18N_CAT_RES); saveDaemonDir_(argv[0]); for (i=1; i<argc; i++) { if (strcmp(argv[i], "-d") == 0 && argv[i+1] != NULL) { pathname = argv[i+1]; putEnv("LSF_ENVDIR",pathname); break; } } if (pathname == NULL) { if ((pathname = getenv("LSF_ENVDIR")) == NULL) pathname = LSETCDIR; } if (argc > 1) { if (!strcmp(argv[1],"-V")) { fputs(_LS_VERSION_, stderr); exit(0); } } if ((ls_readconfenv(resConfParams, NULL) < 0) || (initenv_(resParams, pathname) < 0) ) { if ((sp = getenv("LSF_LOGDIR")) != NULL) resParams[LSF_LOGDIR].paramValue = sp; ls_openlog("res", resParams[LSF_LOGDIR].paramValue, (debug > 1), resParams[LSF_LOG_MASK].paramValue); ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_MM, fname, "initenv_", pathname); ls_syslog(LOG_ERR, I18N_Exiting); exit(-1); } restart_argc = argc; restart_argv = argv; for (i=1; i<argc; i++) { if (strcmp(argv[i], "-d") == 0 && argv[i+1] != NULL) { pathname = argv[i+1]; i++; continue; } if (strcmp(argv[i], "-1") == 0) { debug = 1; continue; } if (strcmp(argv[i], "-2") == 0) { debug = 2; continue; } if (strcmp(argv[i], "-PTY_FIX") == 0) { printf("PTY_FIX"); exit(0); } if ( (strcmp(argv[i], "-j") == 0) && (argv[i+1] != NULL) ) { lsbJobStarter = argv[++i]; continue; } if (strcmp(argv[i], "-P") == 0) { sbdPty = TRUE; continue; } if (strcmp(argv[i], "-i") == 0) { sbdFlags |= SBD_FLAG_STDIN; continue; } if (strcmp(argv[i], "-o") == 0) { sbdFlags |= SBD_FLAG_STDOUT; continue; } if (strcmp(argv[i], "-e") == 0) { sbdFlags |= SBD_FLAG_STDERR; continue; } if (strcmp(argv[i], "-m") == 0 && argv[i+1] != NULL) { sbdClHost = argv[i+1]; i++; sbdMode = TRUE; continue; } if (strcmp(argv[i], "-p") == 0 && argv[i+1] != NULL) { sbdClPort = atoi(argv[i+1]); i++; sbdMode = TRUE; continue; } if (argv[i][0] != '-') { sbdMode = TRUE; sbdArgv = argv + i; break; } usage(argv[0]); } if (sbdMode) { if (sbdClHost == NULL || sbdArgv == NULL) { usage(argv[0]); exit(-1); } if (sbdClPort) { sbdFlags |= SBD_FLAG_TERM; } else { sbdFlags |= SBD_FLAG_STDIN | SBD_FLAG_STDOUT | SBD_FLAG_STDERR; } } else { if (debug < 2) for (i = sysconf(_SC_OPEN_MAX) ; i >= 0 ; i--) close(i); } if (resParams[LSF_SERVERDIR].paramValue == NULL) { ls_openlog("res", resParams[LSF_LOGDIR].paramValue, (debug > 1), resParams[LSF_LOG_MASK].paramValue); ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5001, "LSF_SERVERDIR not defined in %s/lsf.conf: %M; res exiting"), /* catgets 5001 */ pathname); resExit_(-1); } if (! debug && resParams[LSF_RES_DEBUG].paramValue != NULL) { debug = atoi(resParams[LSF_RES_DEBUG].paramValue); if (debug <= 0) debug = 1; } getLogClass_(resParams[LSF_DEBUG_RES].paramValue, resParams[LSF_TIME_RES].paramValue); if (getuid() == 0 && debug) { if (sbdMode) { debug = 0; } else { ls_openlog("res", resParams[LSF_LOGDIR].paramValue, FALSE, resParams[LSF_LOG_MASK].paramValue); ls_syslog(LOG_ERR, I18N(5005,"Root cannot run RES in debug mode ... exiting."));/*catgets 5005 */ exit(-1); } } if (debug > 1) ls_openlog("res", resParams[LSF_LOGDIR].paramValue, TRUE, "LOG_DEBUG"); else { ls_openlog("res", resParams[LSF_LOGDIR].paramValue, FALSE, resParams[LSF_LOG_MASK].paramValue); } if (logclass & (LC_TRACE | LC_HANG)) ls_syslog(LOG_DEBUG, "%s: logclass=%x", fname, logclass); ls_syslog(LOG_DEBUG, "%s: LSF_SERVERDIR=%s", fname, resParams[LSF_SERVERDIR].paramValue); init_res(); initSignals(); periodic(0); if (sbdMode) { lsbJobStart(sbdArgv, sbdClPort, sbdClHost, sbdPty); } maxfd = FD_SETSIZE; for (;;) { struct timeval *timep; struct timeval timeout; loop: didSomething = 0; for (i = 0; i < child_cnt; i++) { if (children[i]->backClnPtr == NULL && !FD_IS_VALID(conn2NIOS.sock.fd) && children[i]->running == 0) { delete_child (children[i]); } } if (logclass & LC_TRACE) { ls_syslog(LOG_DEBUG,"\ %s: %s Res child_res=<%d> child_go=<%d> child_cnt=<%d> client_cnt=<%d>", fname, ((child_res) ? "Application" : "Root") , child_res, child_go, child_cnt, client_cnt); if (child_cnt == 1 && children != NULL && children[0] != NULL) { dumpChild(children[0], 1, "in main()"); } } if (child_res && child_go && child_cnt == 0 && client_cnt == 0) { if (debug > 1) printf (" \n Child <%d> Retired! \n", (int)getpid()); if (logclass & LC_TRACE) { ls_syslog(LOG_DEBUG,"\ %s: Application Res is exiting.....", fname); } millisleep_(5000); if (sbdMode) { close(1); close(2); exit(lastChildExitStatus); } resExit_(EXIT_NO_ERROR); }
void child_handler(int sig) { int pid; LS_WAIT_T status; struct rusage rusage; register float cpuTime; struct lsfRusage lsfRusage; struct jobCard *jobCard; static short lastMbdExitVal = MASTER_NULL; static int sbd_finish_sleep = -1; cleanRusage (&rusage); now = time(0); while ((pid=wait3(&status, WNOHANG, &rusage)) > 0) { if (pid == mbdPid) { int sig = WTERMSIG(status); if (mbdExitCnt > 150) mbdExitCnt = 150; mbdExitVal = WIFSIGNALED(status); if (mbdExitVal) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5600, "mbatchd died with signal <%d> termination"), /* catgets 5600 */ sig); if (WCOREDUMP(status)) ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5601, "mbatchd core dumped")); /* catgets 5601 */ mbdExitVal = sig; if (mbdExitVal == lastMbdExitVal) mbdExitCnt++; else { mbdExitCnt = 0; lastMbdExitVal = mbdExitVal; } continue; } else { mbdExitVal = WEXITSTATUS(status); if (mbdExitVal == lastMbdExitVal) mbdExitCnt++; else { mbdExitCnt = 0; lastMbdExitVal = mbdExitVal; } if (mbdExitVal == MASTER_RECONFIG) { ls_syslog(LOG_NOTICE, _i18n_msg_get(ls_catd , NL_SETN, 5602, "mbatchd resigned for reconfiguration")); /* catgets 5602 */ start_master(); } else ls_syslog(LOG_NOTICE, _i18n_msg_get(ls_catd , NL_SETN, 5603, "mbatchd exited with value <%d>"), /* catgets 5603 */ mbdExitVal); continue; } } ls_ruunix2lsf (&rusage, &lsfRusage); cpuTime = lsfRusage.ru_utime + lsfRusage.ru_stime; for (jobCard = jobQueHead->forw; (jobCard != jobQueHead); jobCard = jobCard->forw) { if (jobCard->exitPid == pid) { jobCard->w_status = LS_STATUS(status); jobCard->exitPid = -1; if (logclass & LC_EXEC) { ls_syslog(LOG_DEBUG, I18N(5604, "child_handler: Job <%s> exitPid <%d> status <%d> exitcode <%d>"),/*catgets 5604*/ lsb_jobid2str(jobCard->jobSpecs.jobId), pid, jobCard->w_status, WEXITSTATUS(status)); } } if (jobCard->jobSpecs.jobPid == pid) { jobCard->collectedChild = TRUE; jobCard->cpuTime = cpuTime; jobCard->w_status = LS_STATUS(status); jobCard->exitPid = -1; memcpy ((char *) &jobCard->lsfRusage, (char *) &lsfRusage, sizeof (struct lsfRusage)); jobCard->notReported++; if (sbd_finish_sleep < 0) { if (daemonParams[LSB_SBD_FINISH_SLEEP].paramValue) { errno = 0; sbd_finish_sleep = atoi(daemonParams[LSB_SBD_FINISH_SLEEP].paramValue); if (errno) sbd_finish_sleep = 0; } else { sbd_finish_sleep=0; } } if (sbd_finish_sleep > 0) { millisleep_(sbd_finish_sleep); } if (logclass & LC_EXEC) { ls_syslog(LOG_DEBUG, I18N(5605, "child_handler: Job <%s> Pid <%d> status <%d> exitcode <%d>"), /*catgets 5605*/ lsb_jobid2str(jobCard->jobSpecs.jobId), pid, jobCard->w_status, WEXITSTATUS(status)); } need_checkfinish = TRUE; break; } } } }