1*3c275423Schristos /*	$NetBSD: master.h,v 1.2 2020/03/18 19:05:16 christos Exp $	*/
241fbaed0Stron 
341fbaed0Stron /*++
441fbaed0Stron /* NAME
541fbaed0Stron /*	master 3h
641fbaed0Stron /* SUMMARY
741fbaed0Stron /*	Postfix master - data structures and prototypes
841fbaed0Stron /* SYNOPSIS
941fbaed0Stron /*	#include "master.h"
1041fbaed0Stron /* DESCRIPTION
1141fbaed0Stron /* .nf
1241fbaed0Stron 
1341fbaed0Stron  /*
1441fbaed0Stron   * Server processes that provide the same service share a common "listen"
1541fbaed0Stron   * socket to accept connection requests, and share a common pipe to the
1641fbaed0Stron   * master process to send status reports. Server processes die voluntarily
1741fbaed0Stron   * when idle for a configurable amount of time, or after servicing a
1841fbaed0Stron   * configurable number of requests; the master process spawns new processes
1941fbaed0Stron   * on demand up to a configurable concurrency limit and/or periodically.
2041fbaed0Stron   *
2141fbaed0Stron   * The canonical service name is what we use internally, so that we correctly
2241fbaed0Stron   * handle a request to "reload" after someone changes "smtp" into "25".
2341fbaed0Stron   *
2441fbaed0Stron   * We use the external service name from master.cf when reporting problems, so
2541fbaed0Stron   * that the user can figure out what we are talking about. Of course we also
2641fbaed0Stron   * include the canonical service name so that the UNIX-domain smtp service
2741fbaed0Stron   * can be distinguished from the Internet smtp service.
2841fbaed0Stron   */
2941fbaed0Stron typedef struct MASTER_SERV {
3041fbaed0Stron     int     flags;			/* status, features, etc. */
3141fbaed0Stron     char   *ext_name;			/* service endpoint name (master.cf) */
3241fbaed0Stron     char   *name;			/* service endpoint name (canonical) */
3341fbaed0Stron     int     type;			/* UNIX-domain, INET, etc. */
3441fbaed0Stron     time_t  busy_warn_time;		/* limit "all servers busy" warning */
3541fbaed0Stron     int     wakeup_time;		/* wakeup interval */
3641fbaed0Stron     int    *listen_fd;			/* incoming requests */
3741fbaed0Stron     int     listen_fd_count;		/* nr of descriptors */
3841fbaed0Stron     union {
3941fbaed0Stron 	struct {
4041fbaed0Stron 	    char   *port;		/* inet listen port */
4141fbaed0Stron 	    struct INET_ADDR_LIST *addr;/* inet listen address */
4241fbaed0Stron 	}       inet_ep;
4341fbaed0Stron #define MASTER_INET_ADDRLIST(s)	((s)->endpoint.inet_ep.addr)
4441fbaed0Stron #define MASTER_INET_PORT(s)	((s)->endpoint.inet_ep.port)
4541fbaed0Stron     }       endpoint;
4641fbaed0Stron     int     max_proc;			/* upper bound on # processes */
4741fbaed0Stron     char   *path;			/* command pathname */
4841fbaed0Stron     struct ARGV *args;			/* argument vector */
4941fbaed0Stron     char   *stress_param_val;		/* stress value: "yes" or empty */
5041fbaed0Stron     time_t  stress_expire_time;		/* stress pulse stretcher */
5141fbaed0Stron     int     avail_proc;			/* idle processes */
5241fbaed0Stron     int     total_proc;			/* number of processes */
5341fbaed0Stron     int     throttle_delay;		/* failure recovery parameter */
5441fbaed0Stron     int     status_fd[2];		/* child status reports */
5541fbaed0Stron     struct BINHASH *children;		/* linkage */
5641fbaed0Stron     struct MASTER_SERV *next;		/* linkage */
5741fbaed0Stron } MASTER_SERV;
5841fbaed0Stron 
5941fbaed0Stron  /*
6041fbaed0Stron   * Per-service flag bits. We assume trouble when a child process terminates
6141fbaed0Stron   * before completing its first request: either the program is defective,
6241fbaed0Stron   * some configuration is wrong, or the system is out of resources.
6341fbaed0Stron   */
6441fbaed0Stron #define MASTER_FLAG_THROTTLE	(1<<0)	/* we're having trouble */
6541fbaed0Stron #define MASTER_FLAG_MARK	(1<<1)	/* garbage collection support */
6641fbaed0Stron #define MASTER_FLAG_CONDWAKE	(1<<2)	/* wake up if actually used */
6741fbaed0Stron #define MASTER_FLAG_INETHOST	(1<<3)	/* endpoint name specifies host */
6841fbaed0Stron #define MASTER_FLAG_LOCAL_ONLY	(1<<4)	/* no remote clients */
69e694ac3bStron #define MASTER_FLAG_LISTEN	(1<<5)	/* monitor this port */
7041fbaed0Stron 
7141fbaed0Stron #define MASTER_THROTTLED(f)	((f)->flags & MASTER_FLAG_THROTTLE)
72e8314800Stron #define MASTER_MARKED_FOR_DELETION(f) ((f)->flags & MASTER_FLAG_MARK)
73e694ac3bStron #define MASTER_LISTENING(f)	((f)->flags & MASTER_FLAG_LISTEN)
7441fbaed0Stron 
7541fbaed0Stron #define MASTER_LIMIT_OK(limit, count) ((limit) == 0 || ((count) < (limit)))
7641fbaed0Stron 
7741fbaed0Stron  /*
78e09e275dSchristos   * Service types, stream sockets unless indicated otherwise.
7941fbaed0Stron   */
8041fbaed0Stron #define MASTER_SERV_TYPE_UNIX	1	/* AF_UNIX domain socket */
8141fbaed0Stron #define MASTER_SERV_TYPE_INET	2	/* AF_INET domain socket */
8241fbaed0Stron #define MASTER_SERV_TYPE_FIFO	3	/* fifo (named pipe) */
8341fbaed0Stron #define MASTER_SERV_TYPE_PASS	4	/* AF_UNIX domain socket */
84e09e275dSchristos #define MASTER_SERV_TYPE_UXDG	5	/* AF_UNIX domain datagram socket */
8541fbaed0Stron 
8641fbaed0Stron  /*
8741fbaed0Stron   * Default process management policy values. This is only the bare minimum.
8841fbaed0Stron   * Most policy management is delegated to child processes. The process
8941fbaed0Stron   * manager runs at high privilege level and has to be kept simple.
9041fbaed0Stron   */
9141fbaed0Stron #define MASTER_DEF_MIN_IDLE	1	/* preferred # of idle processes */
9241fbaed0Stron 
9341fbaed0Stron  /*
9441fbaed0Stron   * Structure of child process.
9541fbaed0Stron   */
9641fbaed0Stron typedef int MASTER_PID;			/* pid is key into binhash table */
9741fbaed0Stron 
9841fbaed0Stron typedef struct MASTER_PROC {
9941fbaed0Stron     MASTER_PID pid;			/* child process id */
10041fbaed0Stron     unsigned gen;			/* child generation number */
10141fbaed0Stron     int     avail;			/* availability */
10241fbaed0Stron     MASTER_SERV *serv;			/* parent linkage */
10341fbaed0Stron     int     use_count;			/* number of service requests */
10441fbaed0Stron } MASTER_PROC;
10541fbaed0Stron 
10641fbaed0Stron  /*
10741fbaed0Stron   * Other manifest constants.
10841fbaed0Stron   */
10941fbaed0Stron #define MASTER_BUF_LEN	2048		/* logical config line length */
11041fbaed0Stron 
11141fbaed0Stron  /*
11241fbaed0Stron   * master.c
11341fbaed0Stron   */
11441fbaed0Stron extern int master_detach;
115e09e275dSchristos extern int init_mode;
11641fbaed0Stron 
11741fbaed0Stron  /*
11841fbaed0Stron   * master_ent.c
11941fbaed0Stron   */
12041fbaed0Stron extern void fset_master_ent(char *);
12141fbaed0Stron extern void set_master_ent(void);
12241fbaed0Stron extern void end_master_ent(void);
12341fbaed0Stron extern void print_master_ent(MASTER_SERV *);
12441fbaed0Stron extern MASTER_SERV *get_master_ent(void);
12541fbaed0Stron extern void free_master_ent(MASTER_SERV *);
12641fbaed0Stron 
12741fbaed0Stron  /*
12841fbaed0Stron   * master_conf.c
12941fbaed0Stron   */
13041fbaed0Stron extern void master_config(void);
13141fbaed0Stron extern void master_refresh(void);
13241fbaed0Stron 
13341fbaed0Stron  /*
13441fbaed0Stron   * master_vars.c
13541fbaed0Stron   */
13641fbaed0Stron extern void master_vars_init(void);
13741fbaed0Stron 
13841fbaed0Stron  /*
13941fbaed0Stron   * master_service.c
14041fbaed0Stron   */
14141fbaed0Stron extern MASTER_SERV *master_head;
14241fbaed0Stron extern void master_start_service(MASTER_SERV *);
14341fbaed0Stron extern void master_stop_service(MASTER_SERV *);
144e694ac3bStron extern void master_restart_service(MASTER_SERV *, int);
145e694ac3bStron 
146e694ac3bStron #define DO_CONF_RELOAD	1	/* config files were reloaded */
147e694ac3bStron #define NO_CONF_RELOAD	0	/* no config file was reloaded */
14841fbaed0Stron 
14941fbaed0Stron  /*
15041fbaed0Stron   * master_events.c
15141fbaed0Stron   */
15241fbaed0Stron extern int master_gotsighup;
15341fbaed0Stron extern int master_gotsigchld;
15441fbaed0Stron extern void master_sigsetup(void);
15541fbaed0Stron 
15641fbaed0Stron  /*
15741fbaed0Stron   * master_status.c
15841fbaed0Stron   */
15941fbaed0Stron extern void master_status_init(MASTER_SERV *);
16041fbaed0Stron extern void master_status_cleanup(MASTER_SERV *);
16141fbaed0Stron 
16241fbaed0Stron  /*
16341fbaed0Stron   * master_wakeup.c
16441fbaed0Stron   */
16541fbaed0Stron extern void master_wakeup_init(MASTER_SERV *);
16641fbaed0Stron extern void master_wakeup_cleanup(MASTER_SERV *);
16741fbaed0Stron 
16841fbaed0Stron 
16941fbaed0Stron  /*
17041fbaed0Stron   * master_listen.c
17141fbaed0Stron   */
17241fbaed0Stron extern void master_listen_init(MASTER_SERV *);
17341fbaed0Stron extern void master_listen_cleanup(MASTER_SERV *);
17441fbaed0Stron 
17541fbaed0Stron  /*
17641fbaed0Stron   * master_avail.c
17741fbaed0Stron   */
17841fbaed0Stron extern void master_avail_listen(MASTER_SERV *);
17941fbaed0Stron extern void master_avail_cleanup(MASTER_SERV *);
18041fbaed0Stron extern void master_avail_more(MASTER_SERV *, MASTER_PROC *);
18141fbaed0Stron extern void master_avail_less(MASTER_SERV *, MASTER_PROC *);
18241fbaed0Stron 
18341fbaed0Stron  /*
18441fbaed0Stron   * master_spawn.c
18541fbaed0Stron   */
18641fbaed0Stron extern struct BINHASH *master_child_table;
18741fbaed0Stron extern void master_spawn(MASTER_SERV *);
18841fbaed0Stron extern void master_reap_child(void);
18941fbaed0Stron extern void master_delete_children(MASTER_SERV *);
19041fbaed0Stron 
19141fbaed0Stron  /*
19241fbaed0Stron   * master_flow.c
19341fbaed0Stron   */
19441fbaed0Stron extern void master_flow_init(void);
19541fbaed0Stron extern int master_flow_pipe[2];
19641fbaed0Stron 
19741fbaed0Stron  /*
19841fbaed0Stron   * master_watch.c
19941fbaed0Stron   *
20041fbaed0Stron   * Support to warn about main.cf parameters that can only be initialized but
20141fbaed0Stron   * not updated, and to initialize or update data structures that derive
20241fbaed0Stron   * values from main.cf parameters.
20341fbaed0Stron   */
20441fbaed0Stron typedef struct {
20541fbaed0Stron     const char *name;			/* parameter name */
20641fbaed0Stron     char  **value;			/* current main.cf value */
20741fbaed0Stron     char  **backup;			/* actual value that is being used */
20841fbaed0Stron     int     flags;			/* see below */
20941fbaed0Stron     void    (*notify) (void);		/* init or update data structure */
21041fbaed0Stron } MASTER_STR_WATCH;
21141fbaed0Stron 
21241fbaed0Stron typedef struct {
21341fbaed0Stron     const char *name;			/* parameter name */
21441fbaed0Stron     int    *value;			/* current main.cf value */
21541fbaed0Stron     int     backup;			/* actual value that is being used */
21641fbaed0Stron     int     flags;			/* see below */
21741fbaed0Stron     void    (*notify) (void);		/* init or update data structure */
21841fbaed0Stron } MASTER_INT_WATCH;
21941fbaed0Stron 
22041fbaed0Stron #define MASTER_WATCH_FLAG_UPDATABLE (1<<0)	/* support update after init */
22141fbaed0Stron #define MASTER_WATCH_FLAG_ISSET    (1<<1)	/* backup is initialized */
22241fbaed0Stron 
22341fbaed0Stron extern void master_str_watch(const MASTER_STR_WATCH *);
22441fbaed0Stron extern void master_int_watch(MASTER_INT_WATCH *);
22541fbaed0Stron 
226b6432918Stron  /*
227b6432918Stron   * master_monitor.c
228b6432918Stron   */
229b6432918Stron extern int master_monitor(int);
230b6432918Stron 
23141fbaed0Stron /* DIAGNOSTICS
23241fbaed0Stron /* BUGS
23341fbaed0Stron /* SEE ALSO
23441fbaed0Stron /* LICENSE
23541fbaed0Stron /* .ad
23641fbaed0Stron /* .fi
23741fbaed0Stron /*	The Secure Mailer license must be distributed with this software.
23841fbaed0Stron /* AUTHOR(S)
23941fbaed0Stron /*	Wietse Venema
24041fbaed0Stron /*	IBM T.J. Watson Research
24141fbaed0Stron /*	P.O. Box 704
24241fbaed0Stron /*	Yorktown Heights, NY 10598, USA
243e09e275dSchristos /*
244e09e275dSchristos /*	Wietse Venema
245e09e275dSchristos /*	Google, Inc.
246e09e275dSchristos /*	111 8th Avenue
247e09e275dSchristos /*	New York, NY 10011, USA
24841fbaed0Stron /*--*/
249