Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Global contexts
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 :
22 : #include "replace.h"
23 : #include "global_contexts.h"
24 : #include <tevent.h>
25 : #include "lib/util/fault.h"
26 : #include "lib/util/samba_util.h"
27 : #include "messages.h"
28 :
29 : static struct tevent_context *global_event_ctx = NULL;
30 :
31 675580 : struct tevent_context *global_event_context(void)
32 : {
33 675580 : if (!global_event_ctx) {
34 : /*
35 : * Note we MUST use the NULL context here, not the
36 : * autofree context, to avoid side effects in forked
37 : * children exiting.
38 : */
39 1481 : global_event_ctx = samba_tevent_context_init(NULL);
40 : }
41 675580 : if (!global_event_ctx) {
42 0 : smb_panic("Could not init global event context");
43 : }
44 675580 : return global_event_ctx;
45 : }
46 :
47 5270 : void global_event_context_free(void)
48 : {
49 5270 : TALLOC_FREE(global_event_ctx);
50 5270 : }
51 :
52 : static struct messaging_context *global_msg_ctx = NULL;
53 :
54 13630 : struct messaging_context *global_messaging_context(void)
55 : {
56 13630 : if (global_msg_ctx == NULL) {
57 : /*
58 : * Note we MUST use the NULL context here, not the
59 : * autofree context, to avoid side effects in forked
60 : * children exiting.
61 : */
62 1458 : global_msg_ctx = messaging_init(NULL,
63 : global_event_context());
64 : }
65 13630 : return global_msg_ctx;
66 : }
67 :
68 6255 : void global_messaging_context_free(void)
69 : {
70 6255 : TALLOC_FREE(global_msg_ctx);
71 6255 : }
|