108
107
/* This is now the child code. We need a completely new event_context to work with */
109
ev2 = s4_event_context_init(NULL);
111
/* the service has given us a private pointer that
112
encapsulates the context it needs for this new connection -
113
everything else will be freed */
114
talloc_steal(ev2, private_data);
115
talloc_steal(private_data, sock2);
109
if (tevent_re_initialise(ev) != 0) {
110
smb_panic("Failed to re-initialise tevent after fork");
117
113
/* this will free all the listening sockets and all state that
118
114
is not associated with this new connection */
119
115
talloc_free(sock);
122
117
/* we don't care if the dup fails, as its only a select()
123
118
speed optimisation */
124
119
socket_dup(sock2);
126
121
/* tdb needs special fork handling */
127
if (tdb_reopen_all(1) == -1) {
128
DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
122
ldb_wrap_fork_hook();
131
tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
124
tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
132
125
standard_pipe_handler, NULL);
133
126
close(child_pipe[1]);
136
129
set_need_random_reseed();
138
131
/* setup the process title */
139
c = socket_get_peer_addr(sock2, ev2);
140
s = socket_get_my_addr(sock2, ev2);
132
c = socket_get_peer_addr(sock2, ev);
133
s = socket_get_my_addr(sock2, ev);
142
135
setproctitle("conn c[%s:%u] s[%s:%u] server_id[%d]",
143
c->addr, c->port, s->addr, s->port, pid);
136
c->addr, c->port, s->addr, s->port, (int)pid);
148
141
/* setup this new connection. Cluster ID is PID based for this process modal */
149
new_conn(ev2, lp_ctx, sock2, cluster_id(pid, 0), private_data);
142
new_conn(ev, lp_ctx, sock2, cluster_id(pid, 0), private_data);
151
144
/* we can't return to the top level here, as that event context is gone,
152
145
so we now process events in the new event context until there are no
153
146
more to process */
154
event_loop_wait(ev2);
163
156
static void standard_new_task(struct tevent_context *ev,
164
157
struct loadparm_context *lp_ctx,
165
158
const char *service_name,
166
void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *),
159
void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *),
167
160
void *private_data)
170
struct tevent_context *ev2;
181
/* This is now the child code. We need a completely new event_context to work with */
182
ev2 = s4_event_context_init(NULL);
184
/* the service has given us a private pointer that
185
encapsulates the context it needs for this new connection -
186
everything else will be freed */
187
talloc_steal(ev2, private_data);
189
173
/* this will free all the listening sockets and all state that
190
174
is not associated with this new connection */
193
/* tdb needs special fork handling */
194
if (tdb_reopen_all(1) == -1) {
195
DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
175
if (tevent_re_initialise(ev) != 0) {
176
smb_panic("Failed to re-initialise tevent after fork");
198
tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
179
/* ldb/tdb need special fork handling */
180
ldb_wrap_fork_hook();
182
tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
199
183
standard_pipe_handler, NULL);
200
184
close(child_pipe[1]);
202
186
/* Ensure that the forked children do not expose identical random streams */
203
187
set_need_random_reseed();
205
setproctitle("task %s server_id[%d]", service_name, pid);
189
setproctitle("task %s server_id[%d]", service_name, (int)pid);
207
191
/* setup this new task. Cluster ID is PID based for this process modal */
208
new_task(ev2, lp_ctx, cluster_id(pid, 0), private_data);
192
new_task(ev, lp_ctx, cluster_id(pid, 0), private_data);
210
194
/* we can't return to the top level here, as that event context is gone,
211
195
so we now process events in the new event context until there are no
212
196
more to process */
213
event_loop_wait(ev2);
220
204
/* called when a task goes down */
221
_NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx,
205
_NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx,
222
206
const char *reason)
224
208
DEBUG(2,("standard_terminate: reason[%s]\n",reason));
226
212
/* this reload_charcnv() has the effect of freeing the iconv context memory,
227
213
which makes leak checking easier */
228
214
reload_charcnv(lp_ctx);
232
216
/* terminate this process */