5e48b7986d246a943664e1217f0dc661a699dcfd
[abartlet/samba.git/.git] / source3 / lib / server_contexts.c
1 /*
2    Unix SMB/CIFS implementation.
3    Common server globals
4
5    Copyright (C) Simo Sorce <idra@samba.org> 2010
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 "includes.h"
22
23 struct tevent_context *server_event_ctx = NULL;
24
25 struct tevent_context *server_event_context(void)
26 {
27         if (!server_event_ctx) {
28                 /*
29                  * Note we MUST use the NULL context here, not the
30                  * autofree context, to avoid side effects in forked
31                  * children exiting.
32                  */
33                 server_event_ctx = s3_tevent_context_init(NULL);
34         }
35         if (!server_event_ctx) {
36                 smb_panic("Could not init server's event context");
37         }
38         return server_event_ctx;
39 }
40
41 void server_event_context_free(void)
42 {
43         TALLOC_FREE(server_event_ctx);
44 }
45
46 struct messaging_context *server_msg_ctx = NULL;
47
48 struct messaging_context *server_messaging_context(void)
49 {
50         if (server_msg_ctx == NULL) {
51                 /*
52                  * Note we MUST use the NULL context here, not the
53                  * autofree context, to avoid side effects in forked
54                  * children exiting.
55                  */
56                 server_msg_ctx = messaging_init(NULL,
57                                                 procid_self(),
58                                                 server_event_context());
59         }
60         if (server_msg_ctx == NULL) {
61                 DEBUG(0, ("Could not init server's messaging context.\n"));
62         }
63         return server_msg_ctx;
64 }
65
66 void server_messaging_context_free(void)
67 {
68         TALLOC_FREE(server_msg_ctx);
69 }