]> git.neil.brown.name Git - metad.git/blob - metad.h
Assorted reformating
[metad.git] / metad.h
1
2 #include        <sys/types.h>
3 #include        <unistd.h>
4 #include        <stdlib.h>
5 #include        <sys/wait.h>
6 #include        <string.h>
7 #include        <syslog.h>
8 #include        <ctype.h>
9 #include        <signal.h>
10 #include        <time.h>
11 /* hold config file info */
12
13
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 */
19
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 */
27         int     start_cnt;
28         char    *program;               /* program to run */
29         char    **args;                 /* arguments */
30
31         int     pending;                /* set before reprocessing config file, cleared when found in file */
32
33         void *proc_list;                /* skiplist of currently active processes */
34         time_t next_hold;               /* hold time for next crashing processes */
35 } *service_t;
36
37 typedef struct proc {
38         pid_t           pid;            /* pid of process */
39         service_t       service;
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 */
49 } *proc_t;
50
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 */
64 } *class_t;
65
66
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       */
70
71         time_t  last_restart;           /* last time a periodic restart was attempted */
72 } *daemon_info_t;
73
74
75 typedef struct commands {
76         char *  name;
77         void    (*proc)();
78 } *commands_t;
79
80 class_t find_class(char *name);
81 void loadstate(int fd);
82 int do_command(char **args, char *host, void *con);
83 int tcp_port();
84 int udp_port();
85 int control_init(void);
86 void check_control(void);
87 #ifndef IN_CONTROL
88 int set_reply(void *con, char *reply, int len);
89 int return_error(void *con, char *fmt, ...);
90 #endif
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);
96 void main_loop(void);
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);
109 int get_byte(void);
110 void send_int(int i);
111 int get_int(void);
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);
117 void restart(void);
118 void init_recv(char*);
119 char *prtime(time_t);
120 int udp_port(void);
121 int tcp_port(void);
122 void nodelay(int socket);
123
124 int send_cmd(char *cmd, int udp, char *host, int verbose);
125
126 char *get_str();
127 char *get_return();
128
129 #ifndef IN_ERROR
130 void error(char *mesg,...);
131 void logmsg(int, char*, ...);
132 #endif
133 #define ERROR_STDERR    0
134 #define ERROR_SYSLOG    1
135 #define ERROR_STRING    2
136 int errors_to(int where, char **place);
137
138 char **strlistdup(char **l);
139 void strlistfree(char **l);
140 char **strsplit(char *line, char *sep);
141
142 void dolog(service_t, proc_t, char *);
143
144 extern void *services;
145 extern void *allprocs;
146
147 extern int is_saved_pid(pid_t pid);
148 extern char version[];