11 /* hold config file info */
14 typedef struct service {
15 char *service; /* name of service */
16 struct class *class; /* pointer to class*/
17 void *classinfo; /* class specific options */
18 /* class independant options */
20 int max_proc; /* max number of processes */
21 char *crash_prog; /* prog to call when process crashes */
22 char *home_dir; /* directory to run process in */
23 char *username; /* who to run process as */
24 char *pidfile; /* file to read process id from after child exits */
25 int watch_output; /* if true, attatch a pipe to std{out,err} and what it */
26 int enabled; /* whether to start enabled */
28 char *program; /* program to run */
29 char **args; /* arguments */
31 int pending; /* set before reprocessing config file, cleared when found in file */
33 void *proc_list; /* skiplist of currently active processes */
34 time_t next_hold; /* hold time for next crashing processes */
38 pid_t pid; /* pid of process */
40 int pipefd; /* if a pipe was conencted to stdout/stderr */
41 char pipebuf[300]; /* buffer lines of data from pipefd before syslogging */
42 int bufptr; /* how full buf is */
43 int it_forked; /* true if process fork/exited, and we have pid from pidfile */
44 int is_crash; /* if cleaning up after core dump */
45 time_t start_time; /* when processes started */
46 time_t hold_time; /* time to let go of processes slot - set if process crashes early */
47 time_t exit_time; /* the time that it exited */
48 int status; /* wait status if exit_time > 0 */
51 typedef struct class {
52 char *class; /* name of class */
53 int (*c_process_opt)(service_t sv, char *opt); /* function to processes options */
54 void (*register_service)(service_t sv); /* register the service if necessary */
55 void (*c_check_service)(service_t sv); /* check if anything needs to be done for a service */
56 void (*init_state)(service_t to); /* copy state from old service struct to new */
57 void (*copy_state)(service_t to, service_t from);/* copy state from old service struct to new */
58 void (*free_state)(service_t sv); /* free class dependant state */
59 void (*send_class)(service_t sv); /* send class info */
60 void (*disable_service)(service_t sv); /* unregister service */
61 void (*new_parent)(service_t sv, proc_t p);/* in parent of new child */
62 void (*new_child)(service_t sv); /* in a new child */
63 int (*prefork)(service_t sv); /* just before fork */
67 typedef struct daemon_info { /* class specific info for class "daemon" */
68 int min_proc; /* minimum number of processes to have running */
69 int period; /* period in seconds for restarts */
71 time_t last_restart; /* last time a periodic restart was attempted */
75 typedef struct commands {
80 class_t find_class(char *name);
81 void loadstate(int fd);
82 int do_command(char **args, char *host, void *con);
85 int control_init(void);
86 void check_control(void);
88 int set_reply(void *con, char *reply, int len);
89 int return_error(void *con, char *fmt, ...);
91 void listenon(int socket);
92 int readyon(int socket);
93 void writeon(int socket);
94 int canwrite(int socket);
95 void waituntil(time_t when);
97 int read_config(void *services, char *file);
98 int count_procs(service_t sv);
99 void check_service(service_t sv);
100 int new_proc(service_t sv, char **env);
101 service_t find_service(char *name);
102 service_t new_service(char *name, class_t class);
103 int process_opt(service_t sv, char *opt);
104 void service_init(void);
105 void free_service(service_t sv);
106 void broadcast(char *line);
107 void init_return(void);
108 void send_byte(int b);
110 void send_int(int i);
112 void send_str(char *);
113 void send_service(service_t);
114 void do_send(void *);
115 void control_close(void);
116 void prepare_restart(void);
118 void init_recv(char*);
119 char *prtime(time_t);
122 void nodelay(int socket);
124 int send_cmd(char *cmd, int udp, char *host, int verbose);
130 void error(char *mesg,...);
131 void logmsg(int, char*, ...);
133 #define ERROR_STDERR 0
134 #define ERROR_SYSLOG 1
135 #define ERROR_STRING 2
136 int errors_to(int where, char **place);
138 char **strlistdup(char **l);
139 void strlistfree(char **l);
140 char **strsplit(char *line, char *sep);
142 void dolog(service_t, proc_t, char *);
144 extern void *services;
145 extern void *allprocs;
147 extern int is_saved_pid(pid_t pid);
148 extern char version[];