1 /* $NetBSD: master.h,v 1.1.1.2 2011/03/02 19:32:20 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* master 3h 6 /* SUMMARY 7 /* Postfix master - data structures and prototypes 8 /* SYNOPSIS 9 /* #include "master.h" 10 /* DESCRIPTION 11 /* .nf 12 13 /* 14 * Server processes that provide the same service share a common "listen" 15 * socket to accept connection requests, and share a common pipe to the 16 * master process to send status reports. Server processes die voluntarily 17 * when idle for a configurable amount of time, or after servicing a 18 * configurable number of requests; the master process spawns new processes 19 * on demand up to a configurable concurrency limit and/or periodically. 20 * 21 * The canonical service name is what we use internally, so that we correctly 22 * handle a request to "reload" after someone changes "smtp" into "25". 23 * 24 * We use the external service name from master.cf when reporting problems, so 25 * that the user can figure out what we are talking about. Of course we also 26 * include the canonical service name so that the UNIX-domain smtp service 27 * can be distinguished from the Internet smtp service. 28 */ 29 typedef struct MASTER_SERV { 30 int flags; /* status, features, etc. */ 31 char *ext_name; /* service endpoint name (master.cf) */ 32 char *name; /* service endpoint name (canonical) */ 33 int type; /* UNIX-domain, INET, etc. */ 34 time_t busy_warn_time; /* limit "all servers busy" warning */ 35 int wakeup_time; /* wakeup interval */ 36 int *listen_fd; /* incoming requests */ 37 int listen_fd_count; /* nr of descriptors */ 38 union { 39 struct { 40 char *port; /* inet listen port */ 41 struct INET_ADDR_LIST *addr;/* inet listen address */ 42 } inet_ep; 43 #define MASTER_INET_ADDRLIST(s) ((s)->endpoint.inet_ep.addr) 44 #define MASTER_INET_PORT(s) ((s)->endpoint.inet_ep.port) 45 } endpoint; 46 int max_proc; /* upper bound on # processes */ 47 char *path; /* command pathname */ 48 struct ARGV *args; /* argument vector */ 49 char *stress_param_val; /* stress value: "yes" or empty */ 50 time_t stress_expire_time; /* stress pulse stretcher */ 51 int avail_proc; /* idle processes */ 52 int total_proc; /* number of processes */ 53 int throttle_delay; /* failure recovery parameter */ 54 int status_fd[2]; /* child status reports */ 55 struct BINHASH *children; /* linkage */ 56 struct MASTER_SERV *next; /* linkage */ 57 } MASTER_SERV; 58 59 /* 60 * Per-service flag bits. We assume trouble when a child process terminates 61 * before completing its first request: either the program is defective, 62 * some configuration is wrong, or the system is out of resources. 63 */ 64 #define MASTER_FLAG_THROTTLE (1<<0) /* we're having trouble */ 65 #define MASTER_FLAG_MARK (1<<1) /* garbage collection support */ 66 #define MASTER_FLAG_CONDWAKE (1<<2) /* wake up if actually used */ 67 #define MASTER_FLAG_INETHOST (1<<3) /* endpoint name specifies host */ 68 #define MASTER_FLAG_LOCAL_ONLY (1<<4) /* no remote clients */ 69 70 #define MASTER_THROTTLED(f) ((f)->flags & MASTER_FLAG_THROTTLE) 71 #define MASTER_MARKED_FOR_DELETION(f) ((f)->flags & MASTER_FLAG_MARK) 72 73 #define MASTER_LIMIT_OK(limit, count) ((limit) == 0 || ((count) < (limit))) 74 75 /* 76 * Service types. 77 */ 78 #define MASTER_SERV_TYPE_UNIX 1 /* AF_UNIX domain socket */ 79 #define MASTER_SERV_TYPE_INET 2 /* AF_INET domain socket */ 80 #define MASTER_SERV_TYPE_FIFO 3 /* fifo (named pipe) */ 81 #define MASTER_SERV_TYPE_PASS 4 /* AF_UNIX domain socket */ 82 83 /* 84 * Default process management policy values. This is only the bare minimum. 85 * Most policy management is delegated to child processes. The process 86 * manager runs at high privilege level and has to be kept simple. 87 */ 88 #define MASTER_DEF_MIN_IDLE 1 /* preferred # of idle processes */ 89 90 /* 91 * Structure of child process. 92 */ 93 typedef int MASTER_PID; /* pid is key into binhash table */ 94 95 typedef struct MASTER_PROC { 96 MASTER_PID pid; /* child process id */ 97 unsigned gen; /* child generation number */ 98 int avail; /* availability */ 99 MASTER_SERV *serv; /* parent linkage */ 100 int use_count; /* number of service requests */ 101 } MASTER_PROC; 102 103 /* 104 * Other manifest constants. 105 */ 106 #define MASTER_BUF_LEN 2048 /* logical config line length */ 107 108 /* 109 * master.c 110 */ 111 extern int master_detach; 112 113 /* 114 * master_ent.c 115 */ 116 extern void fset_master_ent(char *); 117 extern void set_master_ent(void); 118 extern void end_master_ent(void); 119 extern void print_master_ent(MASTER_SERV *); 120 extern MASTER_SERV *get_master_ent(void); 121 extern void free_master_ent(MASTER_SERV *); 122 123 /* 124 * master_conf.c 125 */ 126 extern void master_config(void); 127 extern void master_refresh(void); 128 129 /* 130 * master_vars.c 131 */ 132 extern void master_vars_init(void); 133 134 /* 135 * master_service.c 136 */ 137 extern MASTER_SERV *master_head; 138 extern void master_start_service(MASTER_SERV *); 139 extern void master_stop_service(MASTER_SERV *); 140 extern void master_restart_service(MASTER_SERV *); 141 142 /* 143 * master_events.c 144 */ 145 extern int master_gotsighup; 146 extern int master_gotsigchld; 147 extern void master_sigsetup(void); 148 149 /* 150 * master_status.c 151 */ 152 extern void master_status_init(MASTER_SERV *); 153 extern void master_status_cleanup(MASTER_SERV *); 154 155 /* 156 * master_wakeup.c 157 */ 158 extern void master_wakeup_init(MASTER_SERV *); 159 extern void master_wakeup_cleanup(MASTER_SERV *); 160 161 162 /* 163 * master_listen.c 164 */ 165 extern void master_listen_init(MASTER_SERV *); 166 extern void master_listen_cleanup(MASTER_SERV *); 167 168 /* 169 * master_avail.c 170 */ 171 extern void master_avail_listen(MASTER_SERV *); 172 extern void master_avail_cleanup(MASTER_SERV *); 173 extern void master_avail_more(MASTER_SERV *, MASTER_PROC *); 174 extern void master_avail_less(MASTER_SERV *, MASTER_PROC *); 175 176 /* 177 * master_spawn.c 178 */ 179 extern struct BINHASH *master_child_table; 180 extern void master_spawn(MASTER_SERV *); 181 extern void master_reap_child(void); 182 extern void master_delete_children(MASTER_SERV *); 183 184 /* 185 * master_flow.c 186 */ 187 extern void master_flow_init(void); 188 extern int master_flow_pipe[2]; 189 190 /* 191 * master_watch.c 192 * 193 * Support to warn about main.cf parameters that can only be initialized but 194 * not updated, and to initialize or update data structures that derive 195 * values from main.cf parameters. 196 */ 197 typedef struct { 198 const char *name; /* parameter name */ 199 char **value; /* current main.cf value */ 200 char **backup; /* actual value that is being used */ 201 int flags; /* see below */ 202 void (*notify) (void); /* init or update data structure */ 203 } MASTER_STR_WATCH; 204 205 typedef struct { 206 const char *name; /* parameter name */ 207 int *value; /* current main.cf value */ 208 int backup; /* actual value that is being used */ 209 int flags; /* see below */ 210 void (*notify) (void); /* init or update data structure */ 211 } MASTER_INT_WATCH; 212 213 #define MASTER_WATCH_FLAG_UPDATABLE (1<<0) /* support update after init */ 214 #define MASTER_WATCH_FLAG_ISSET (1<<1) /* backup is initialized */ 215 216 extern void master_str_watch(const MASTER_STR_WATCH *); 217 extern void master_int_watch(MASTER_INT_WATCH *); 218 219 /* DIAGNOSTICS 220 /* BUGS 221 /* SEE ALSO 222 /* LICENSE 223 /* .ad 224 /* .fi 225 /* The Secure Mailer license must be distributed with this software. 226 /* AUTHOR(S) 227 /* Wietse Venema 228 /* IBM T.J. Watson Research 229 /* P.O. Box 704 230 /* Yorktown Heights, NY 10598, USA 231 /*--*/ 232