nmsg  0.9.0
nmsg.c
1 /*
2  * Copyright (c) 2009 by Farsight Security, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* Import. */
18 
19 #include "nmsg.h"
20 #include "private.h"
21 
22 /* Globals. */
23 
24 bool _nmsg_global_autoclose = true;
25 int _nmsg_global_debug;
26 struct nmsg_msgmodset * _nmsg_global_msgmodset;
27 
28 /* Statics. */
29 
30 static int _nmsg_initialized = 0;
31 
32 /* Forward. */
33 
34 static void _nmsg_fini(void);
35 
36 /* Export. */
37 
39 nmsg_init(void) {
40  char *msgmod_dir;
41 
42  if (_nmsg_initialized != 0)
43  return (nmsg_res_failure);
44 
45  msgmod_dir = getenv("NMSG_MSGMOD_DIR");
46  if (msgmod_dir == NULL)
47  msgmod_dir = NMSG_LIBDIR;
48 
49  _nmsg_global_msgmodset = _nmsg_msgmodset_init(msgmod_dir);
50  if (_nmsg_global_msgmodset == NULL)
51  return (nmsg_res_failure);
52  atexit(_nmsg_fini);
53 
54  _nmsg_alias_init();
55 
56  _nmsg_initialized = 1;
57  return (nmsg_res_success);
58 }
59 
60 void
61 nmsg_set_autoclose(bool autoclose) {
62  _nmsg_global_autoclose = autoclose;
63 }
64 
65 void
66 nmsg_set_debug(int debug) {
67  _nmsg_global_debug = debug;
68 }
69 
70 int
72  return (_nmsg_global_debug);
73 }
74 
75 /* Private. */
76 
77 void
78 _nmsg_fini(void) {
79  _nmsg_msgmodset_destroy(&_nmsg_global_msgmodset);
80  _nmsg_alias_fini();
81 }
nmsg_res
nmsg result code
Definition: res.h:25
success
Definition: res.h:26
Base nmsg support header.
void nmsg_set_debug(int debug)
Set debug level.
Definition: nmsg.c:66
nmsg_res nmsg_init(void)
Initialize the libnmsg library.
Definition: nmsg.c:39
generic failure
Definition: res.h:27
int nmsg_get_debug(void)
Retrieve the current debug level.
Definition: nmsg.c:71
void nmsg_set_autoclose(bool autoclose)
Configure automatic close() behavior of nmsg inputs and outputs.
Definition: nmsg.c:61