1 /* $NetBSD: master.h,v 1.1.1.4 2013/09/25 19:06:32 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 #define MASTER_FLAG_LISTEN (1<<5) /* monitor this port */ 70 71 #define MASTER_THROTTLED(f) ((f)->flags & MASTER_FLAG_THROTTLE) 72 #define MASTER_MARKED_FOR_DELETION(f) ((f)->flags & MASTER_FLAG_MARK) 73 #define MASTER_LISTENING(f) ((f)->flags & MASTER_FLAG_LISTEN) 74 75 #define MASTER_LIMIT_OK(limit, count) ((limit) == 0 || ((count) < (limit))) 76 77 /* 78 * Service types. 79 */ 80 #define MASTER_SERV_TYPE_UNIX 1 /* AF_UNIX domain socket */ 81 #define MASTER_SERV_TYPE_INET 2 /* AF_INET domain socket */ 82 #define MASTER_SERV_TYPE_FIFO 3 /* fifo (named pipe) */ 83 #define MASTER_SERV_TYPE_PASS 4 /* AF_UNIX domain socket */ 84 85 /* 86 * Default process management policy values. This is only the bare minimum. 87 * Most policy management is delegated to child processes. The process 88 * manager runs at high privilege level and has to be kept simple. 89 */ 90 #define MASTER_DEF_MIN_IDLE 1 /* preferred # of idle processes */ 91 92 /* 93 * Structure of child process. 94 */ 95 typedef int MASTER_PID; /* pid is key into binhash table */ 96 97 typedef struct MASTER_PROC { 98 MASTER_PID pid; /* child process id */ 99 unsigned gen; /* child generation number */ 100 int avail; /* availability */ 101 MASTER_SERV *serv; /* parent linkage */ 102 int use_count; /* number of service requests */ 103 } MASTER_PROC; 104 105 /* 106 * Other manifest constants. 107 */ 108 #define MASTER_BUF_LEN 2048 /* logical config line length */ 109 110 /* 111 * master.c 112 */ 113 extern int master_detach; 114 115 /* 116 * master_ent.c 117 */ 118 extern void fset_master_ent(char *); 119 extern void set_master_ent(void); 120 extern void end_master_ent(void); 121 extern void print_master_ent(MASTER_SERV *); 122 extern MASTER_SERV *get_master_ent(void); 123 extern void free_master_ent(MASTER_SERV *); 124 125 /* 126 * master_conf.c 127 */ 128 extern void master_config(void); 129 extern void master_refresh(void); 130 131 /* 132 * master_vars.c 133 */ 134 extern void master_vars_init(void); 135 136 /* 137 * master_service.c 138 */ 139 extern MASTER_SERV *master_head; 140 extern void master_start_service(MASTER_SERV *); 141 extern void master_stop_service(MASTER_SERV *); 142 extern void master_restart_service(MASTER_SERV *, int); 143 144 #define DO_CONF_RELOAD 1 /* config files were reloaded */ 145 #define NO_CONF_RELOAD 0 /* no config file was reloaded */ 146 147 /* 148 * master_events.c 149 */ 150 extern int master_gotsighup; 151 extern int master_gotsigchld; 152 extern void master_sigsetup(void); 153 154 /* 155 * master_status.c 156 */ 157 extern void master_status_init(MASTER_SERV *); 158 extern void master_status_cleanup(MASTER_SERV *); 159 160 /* 161 * master_wakeup.c 162 */ 163 extern void master_wakeup_init(MASTER_SERV *); 164 extern void master_wakeup_cleanup(MASTER_SERV *); 165 166 167 /* 168 * master_listen.c 169 */ 170 extern void master_listen_init(MASTER_SERV *); 171 extern void master_listen_cleanup(MASTER_SERV *); 172 173 /* 174 * master_avail.c 175 */ 176 extern void master_avail_listen(MASTER_SERV *); 177 extern void master_avail_cleanup(MASTER_SERV *); 178 extern void master_avail_more(MASTER_SERV *, MASTER_PROC *); 179 extern void master_avail_less(MASTER_SERV *, MASTER_PROC *); 180 181 /* 182 * master_spawn.c 183 */ 184 extern struct BINHASH *master_child_table; 185 extern void master_spawn(MASTER_SERV *); 186 extern void master_reap_child(void); 187 extern void master_delete_children(MASTER_SERV *); 188 189 /* 190 * master_flow.c 191 */ 192 extern void master_flow_init(void); 193 extern int master_flow_pipe[2]; 194 195 /* 196 * master_watch.c 197 * 198 * Support to warn about main.cf parameters that can only be initialized but 199 * not updated, and to initialize or update data structures that derive 200 * values from main.cf parameters. 201 */ 202 typedef struct { 203 const char *name; /* parameter name */ 204 char **value; /* current main.cf value */ 205 char **backup; /* actual value that is being used */ 206 int flags; /* see below */ 207 void (*notify) (void); /* init or update data structure */ 208 } MASTER_STR_WATCH; 209 210 typedef struct { 211 const char *name; /* parameter name */ 212 int *value; /* current main.cf value */ 213 int backup; /* actual value that is being used */ 214 int flags; /* see below */ 215 void (*notify) (void); /* init or update data structure */ 216 } MASTER_INT_WATCH; 217 218 #define MASTER_WATCH_FLAG_UPDATABLE (1<<0) /* support update after init */ 219 #define MASTER_WATCH_FLAG_ISSET (1<<1) /* backup is initialized */ 220 221 extern void master_str_watch(const MASTER_STR_WATCH *); 222 extern void master_int_watch(MASTER_INT_WATCH *); 223 224 /* 225 * master_monitor.c 226 */ 227 extern int master_monitor(int); 228 229 /* DIAGNOSTICS 230 /* BUGS 231 /* SEE ALSO 232 /* LICENSE 233 /* .ad 234 /* .fi 235 /* The Secure Mailer license must be distributed with this software. 236 /* AUTHOR(S) 237 /* Wietse Venema 238 /* IBM T.J. Watson Research 239 /* P.O. Box 704 240 /* Yorktown Heights, NY 10598, USA 241 /*--*/ 242