/src/samba/source3/lib/global_contexts.c
Line | Count | Source |
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 | | struct tevent_context *global_event_context(void) |
32 | 0 | { |
33 | 0 | 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 | 0 | global_event_ctx = samba_tevent_context_init(NULL); |
40 | 0 | } |
41 | 0 | if (!global_event_ctx) { |
42 | 0 | smb_panic("Could not init global event context"); |
43 | 0 | } |
44 | 0 | return global_event_ctx; |
45 | 0 | } |
46 | | |
47 | | void global_event_context_free(void) |
48 | 0 | { |
49 | 0 | TALLOC_FREE(global_event_ctx); |
50 | 0 | } |
51 | | |
52 | | static struct messaging_context *global_msg_ctx = NULL; |
53 | | |
54 | | struct messaging_context *global_messaging_context(void) |
55 | 0 | { |
56 | 0 | 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 | 0 | global_msg_ctx = messaging_init(NULL, |
63 | 0 | global_event_context()); |
64 | 0 | } |
65 | 0 | return global_msg_ctx; |
66 | 0 | } |
67 | | |
68 | | void global_messaging_context_free(void) |
69 | 0 | { |
70 | | TALLOC_FREE(global_msg_ctx); |
71 | 0 | } |