void RelaxTimer::RelaxDelay() { switch (m_nStatus) { case STATUS_SHORT_RELAX: ShortRelax2Work(); DecSRT(); break; case STATUS_LONG_RELAX: LongRelax2Work(); DecSRT(); break; default: break; } SetLS((GetWD() >= RELAX_DELAY_SECOND) ? GetWD() - RELAX_DELAY_SECOND : 0); // 更新统计变量 m_statRelax.nDelayedTimes++; }
/* * Locate the executable for the logger (for Windows) */ INTERNAL int find_logger(void) { char cwd[PATHLEN]; char logcmd[100]; char *path; /* Construct the command name */ sprintf(logcmd, "%s%s", LOGGEREXEC, LOGGEREXT); /* Check directory of this executable */ if (Logdir[0]) { make_path(Logger, Logdir, logcmd); if (access(Logger, X_OK) == SYS_OK) return(1); if (Debug) printf("path \"%s\" access is %d\n", Logger, access(Logger, X_OK)); } /* Get the current working directory */ if (!GetWD(cwd, sizeof(cwd))) return(0); make_path(Logger, cwd, logcmd); if (access(Logger, X_OK) == SYS_OK) return(1); if (Debug) printf("path \"%s\" access is %d\n", Logger, access(Logger, X_OK)); /* Get the path environment variable */ path = getenv("PATH"); if (!path) return(0); /* Look for the logger in the users execution path dirs */ while (*path) { char *s = path; while (*s && *s != ':') ++s; *s++ = '\0'; if (path[0] == '.' && (path[1] == '/' || !path[0])) { char tmp[PATHLEN]; make_path(tmp, SelfWD, path+1); make_path(Logger, tmp, logcmd); } else make_path(Logger, path, logcmd); if (access(Logger, X_OK) == SYS_OK) return(1); if (Debug) printf("path \"%s\" access is %d\n", Logger, access(Logger, X_OK)); path = s; } return(0); }
main(int argc, char *argv[]) { char *pgm, *s; int ok, help; char *server; int id, nc; int i; char me[256]; char logstr[200]; pgm = argv[0]; /* Get and save our original working directory */ if (!GetWD(SelfWD, sizeof(SelfWD))) { fprintf(stderr, "%s: couldn't get working directory\n", pgm); perror(pgm); exit(4); } /* Get our own name and any path prefix */ if (pgm = strrchr(argv[0], '/')) { *pgm++ = '\0'; if (*argv[0] == '/') strcpy(Logdir, argv[0]); else make_path(Logdir, SelfWD, argv[0]); if (Verbose) printf("Logdir search is \"%s\"\n", Logdir); } else { strcpy(Logdir, SelfWD); pgm = argv[0]; } ++argv; --argc; /* See if we are running as the LOGGER */ sprintf(logstr, "{%s,%s%s}", LOGGEREXEC, LOGGEREXEC, LOGGEREXT); if (strmatch(logstr, pgm)) logger(pgm, argc, argv); /* Default options */ ok = 1; help = 0; /* Parse out command line options */ while (argc && *argv[0] == '-') { char *opt; opt = argv[0] + 1; ++argv; --argc; if (substr(opt, "help")) ++help; else if (substr(opt, "debug")) ++Debug; else if (substr(opt, "nodebug")) Debug = 0; else if (substr(opt, "verbose")) Verbose = 1; else if (substr(opt, "quiet")) Verbose = 0; else if (streq(opt, "bin") || streq(opt, "dir")) { if (argc < 1) { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; break; } RootPath = argv[0]; ++argv; --argc; } else if (streq(opt, "wd") || streq(opt, "cd")) { if (argc < 1) { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; break; } WorkDir = argv[0]; ++argv; --argc; } else if (substr(opt, "logger")) { if (argc < 1) { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; break; } if (argv[0][0] == '/') strcpy(Logger, argv[0]); else { int len; char *name; /* Copy the current working directory */ strcpy(Logger, SelfWD); len = strlen(Logger); if (Logger[len-1] != '/') Logger[len++] = '/'; name = argv[0]; if (substr("./", name)) name += 2; strcpy(Logger+len, name); } ++argv; --argc; } else { fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt); help = 1; ok = 0; } } if (!ok || argc == 0) { usage(pgm, help); exit(!help); } server = argv[0]; ++argv; --argc; /* Allow directory to be specified as last command line arg */ if (argc) { if (RootPath) { if (!streq(RootPath, argv[0])) { fprintf(stderr, "%s: can't use -dir (%s) and specify path (%s)\n", pgm, RootPath, argv[0]); exit(4); } } else { RootPath = argv[0]; ++argv; --argc; } } /* Check for any extraneous args */ if (argc) { fprintf(stderr, "%s: too many arguments starting with \"%s\"\n", pgm, argv[0]); usage(pgm, help); exit(!help); } /* Now change to our root directory */ if (RootPath) { if (chdir(RootPath) != SYS_OK) { fprintf(stderr, "%s: couldn't chdir to \"%s\"\n", pgm, RootPath); exit(4); } } else fprintf(stderr, "%s: WARNING! no root directory specified - using .\n", pgm); /* Set up path to working directory for lauched agents */ if (WorkDir) if (*WorkDir == '/') strcpy(WorkPath, WorkDir); else make_path(WorkPath, SelfWD, WorkDir); /* Open the executable directory to process queries */ if (!GetWD(ExecPath, sizeof(ExecPath))) { fprintf(stderr, "%s: couldn't get working directory\n", pgm); perror(pgm); exit(4); } ExecDir = opendir(ExecPath); if (!ExecDir) { fprintf(stderr, "%s: couldn't open working directory \"%s\"\n", pgm, ExecPath); perror(pgm); exit(4); } #ifdef win32 /* * On windows we need to run the logger as a separate helper app * since the cygwin implementation of fork is not quite right. * Look for it in standard places as well as looking as users $PATH */ if (!Logger[0] && !find_logger()) { fprintf(stderr, "%s: couldn't find initiator \"%s\"\n", pgm, LOGGEREXEC); exit(4); } if (Verbose) printf("Logger exec is \"%s\"\n", Logger); #endif /* Make sure we found the file and it is executable */ if (Logger[0] && access(Logger, X_OK) != SYS_OK) { fprintf(stderr, "%s: initiator \"%s\" not %s\n", pgm, Logger, access(Logger, F_OK)?"found":"executable"); exit(4); } /* Deal with signals */ siginit(); /* local initialization */ event_verbose(Verbose); event_tunnel_enable(0); agentd_init(); /* Connect to our event server */ id = event_join(server, &nc); if (!id) { fprintf(stderr, "%s: couldn't join server \"%s\"\n", pgm, server); exit(4); } if (Verbose) printf("%s: joined %s as client id %d (%d clients)\n", pgm, server, id, nc); /* Register */ cuserid(me); event_register(AGENTDCLASS, AGENTDSPEC, me); /* Subscribe to only AGENTD type events */ event_select_type(0, ET_MIN, ET_MAX); event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX); /* Initialize agent control structures */ for (i = 0; i < MAX_AGENT; ++i) { Agent[i].pid = 0; Agent[i].status = AGENTD_AGENT_FREE; } mp_init(); /*(not strcitly necessary, since done in event land)*/ /* Allocate our locks and semaphores */ AgentLock = mp_alloclock(); Exitlock = mp_alloclock(); Exitwait = mp_allocsema(); ReadInit = mp_allocsema(); AgentInit = mp_allocsema(); /* * Loop forever processing agentd requests */ FOREVER { EVENT e; /* Wait for an event and then dispatch it */ event_wait(); if (!event_receive(&e)) continue; switch (e.ev_head.type) { case ET_AGENTD_REQ: agent_request((EVENT_AGENTD_REQ *)&e); break; default: if (Verbose) printf("Ignoring event \'%s\'(%d) from %d\n", event_lookup_name(e.ev_head.type), e.ev_head.type, e.ev_head.from); } } }