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