Note that the delaytime for update has changed betweek w2k3 and w2k8.
[Samba/gbeck.git] / source4 / smbd / service_task.c
blobc4fd3d4e982c51145d79d770c2087112fef5184c
1 /*
2 Unix SMB/CIFS implementation.
4 helper functions for task based servers (nbtd, winbind etc)
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "process_model.h"
24 #include "smbd/service.h"
25 #include "smbd/service_task.h"
26 #include "lib/messaging/irpc.h"
27 #include "param/param.h"
30 terminate a task service
32 void task_server_terminate(struct task_server *task, const char *reason)
34 struct tevent_context *event_ctx = task->event_ctx;
35 const struct model_ops *model_ops = task->model_ops;
36 DEBUG(0,("task_server_terminate: [%s]\n", reason));
37 model_ops->terminate(event_ctx, task->lp_ctx, reason);
39 /* don't free this above, it might contain the 'reason' being printed */
40 talloc_free(task);
43 /* used for the callback from the process model code */
44 struct task_state {
45 void (*task_init)(struct task_server *);
46 const struct model_ops *model_ops;
51 called by the process model code when the new task starts up. This then calls
52 the server specific startup code
54 static void task_server_callback(struct tevent_context *event_ctx,
55 struct loadparm_context *lp_ctx,
56 struct server_id server_id, void *private_data)
58 struct task_state *state = talloc_get_type(private_data, struct task_state);
59 struct task_server *task;
61 task = talloc(event_ctx, struct task_server);
62 if (task == NULL) return;
64 task->event_ctx = event_ctx;
65 task->model_ops = state->model_ops;
66 task->server_id = server_id;
67 task->lp_ctx = lp_ctx;
69 task->msg_ctx = messaging_init(task,
70 lp_messaging_path(task, task->lp_ctx),
71 task->server_id,
72 lp_iconv_convenience(task->lp_ctx),
73 task->event_ctx);
74 if (!task->msg_ctx) {
75 task_server_terminate(task, "messaging_init() failed");
76 return;
79 state->task_init(task);
83 startup a task based server
85 NTSTATUS task_server_startup(struct tevent_context *event_ctx,
86 struct loadparm_context *lp_ctx,
87 const char *service_name,
88 const struct model_ops *model_ops,
89 void (*task_init)(struct task_server *))
91 struct task_state *state;
93 state = talloc(event_ctx, struct task_state);
94 NT_STATUS_HAVE_NO_MEMORY(state);
96 state->task_init = task_init;
97 state->model_ops = model_ops;
99 model_ops->new_task(event_ctx, lp_ctx, service_name, task_server_callback, state);
101 return NT_STATUS_OK;
105 setup a task title
107 void task_server_set_title(struct task_server *task, const char *title)
109 task->model_ops->set_title(task->event_ctx, title);