/* * Shared between the supervisor (init.c) and the control * filesystem (fs.c). */ enum { /* states */ Sstopped, Swaiting, /* wants to run; a needs= is not up yet */ Sstarting, /* started; not yet ready */ Srunning, Sfailed, Sdone, /* ready=exit service that finished cleanly */ /* kinds, from ready= */ Kexec, /* up as soon as started; watch the process */ Ksrv, /* up when /srv/x appears; watch that file */ Kdial, /* up when a dial succeeds; watch the process */ Kexit, /* oneshot; done when it exits cleanly */ Maxargs = 64, Maxneeds = 32, Maxrestarts = 5, /* within Restartwindow seconds */ Restartwindow = 60, Restartwait = 1, /* seconds between restarts */ Readywait = 30, /* seconds to become ready */ Stopwait = 5, /* seconds before killing */ Tickms = 250, /* poll interval */ }; typedef struct Svc Svc; struct Svc { char *name; char *exec; char *argv[Maxargs]; int argc; char *env[Maxargs]; int envc; char *restart; int enable; int kind; char *readyarg; char *needs[Maxneeds]; int nneeds; int wanted; /* should it be running? */ int stopping; /* we asked it to go; not a crash */ int pid; int state; long tstart; long tstop; /* when we asked it to stop */ long tretry; /* earliest time to start again */ int restarts; long rtimes[Maxrestarts]; int rnext; char *exits; int mark; /* cycle detection */ Svc *next; }; extern Svc *svcs; extern char *statename[]; extern char *svcdir; extern char *logdir; extern int verbose; extern QLock statelock; /* covers svcs and the command queue */ /* init.c */ Svc* findname(char*); void startsvc(Svc*); void stopsvc(Svc*); char* statusline(Svc*); /* malloc'd ndb line, with newline */ char* allstatus(void); /* malloc'd, every service */ /* command queue: the filesystem asks, the supervisor acts */ char* queuecmd(char *verb, char *name); /* nil ok, else error */ void draincmds(void); int cmdspending(void); /* fs.c */ void startfs(char *srvname, char *mtpt);