6df2a4144437b1b9f3606814b5ceb2218895f660
[idra/samba.git] / source3 / lib / server_prefork.h
1 /*
2    Unix SMB/CIFS implementation.
3    Common server globals
4
5    Copyright (C) Simo Sorce <idra@samba.org> 2011
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "system/network.h"
22 #include <tevent.h>
23
24 enum pf_worker_status {
25         PF_WORKER_NONE = 0,
26         PF_WORKER_IDLE,
27         PF_WORKER_ACCEPTING,
28         PF_WORKER_BUSY,
29         PF_WORKER_EXITING
30 };
31
32 enum pf_server_cmds {
33         PF_SRV_MSG_NONE = 0,
34         PF_SRV_MSG_EXIT
35 };
36
37 struct pf_worker_data {
38         pid_t pid;
39         enum pf_worker_status status;
40         time_t started;
41         time_t last_used;
42         int num_clients;
43
44         enum pf_server_cmds cmds;
45         int allowed_clients;
46 };
47
48 typedef int (prefork_main_fn_t)(struct tevent_context *ev,
49                                 struct pf_worker_data *pf,
50                                 int listen_fd_size,
51                                 int *listen_fds,
52                                 int lock_fd,
53                                 void *private_data);
54
55 struct prefork_pool;
56
57
58 /* ==== Functions used by controlling process ==== */
59
60 bool prefork_create_pool(struct tevent_context *ev_ctx, TALLOC_CTX *mem_ctx,
61                          int listen_fd_size, int *listen_fds,
62                          int min_children, int max_children,
63                          prefork_main_fn_t *main_fn, void *private_data,
64                          struct prefork_pool **pf_pool);
65 int prefork_expand_pool(struct prefork_pool *pfp, int new_max);
66
67 int prefork_add_children(struct tevent_context *ev_ctx,
68                          struct prefork_pool *pfp,
69                          int num_children);
70 int prefork_retire_children(struct prefork_pool *pfp,
71                             int num_children, time_t age_limit);
72 int prefork_count_active_children(struct prefork_pool *pfp, int *total);
73 bool prefork_mark_pid_dead(struct prefork_pool *pfp, pid_t pid);
74 void prefork_increase_allowed_clients(struct prefork_pool *pfp, int max);
75 void prefork_reset_allowed_clients(struct prefork_pool *pfp);
76 void prefork_send_signal_to_all(struct prefork_pool *pfp, int signal_num);
77
78 /* ==== Functions used by children ==== */
79
80 struct tevent_req *prefork_listen_send(TALLOC_CTX *mem_ctx,
81                                         struct tevent_context *ev,
82                                         struct pf_worker_data *pf,
83                                         int listen_fd_size,
84                                         int *listen_fds,
85                                         int lock_fd,
86                                         struct sockaddr *addr,
87                                         socklen_t *addrlen);
88 int prefork_listen_recv(struct tevent_req *req, int *fd);