nmsg  0.9.0
dlmod.c
1 /*
2  * Copyright (c) 2008, 2009, 2012, 2013 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 <dlfcn.h>
20 
21 #include "private.h"
22 
23 /* Internal functions. */
24 
25 struct nmsg_dlmod *
26 _nmsg_dlmod_init(const char *path) {
27  struct nmsg_dlmod *dlmod;
28 
29  dlmod = calloc(1, sizeof(*dlmod));
30  assert(dlmod != NULL);
31  ISC_LINK_INIT(dlmod, link);
32  dlmod->path = strdup(path);
33  assert(dlmod->path != NULL);
34 
35  dlmod->handle = dlopen(path, RTLD_LAZY);
36  if (dlmod->handle == NULL) {
37  _nmsg_dprintf(1, "%s: %s\n", __func__, dlerror());
38  free(dlmod);
39  return (NULL);
40  }
41  return (dlmod);
42 }
43 
44 void
45 _nmsg_dlmod_destroy(struct nmsg_dlmod **dlmod) {
46  if (dlclose((*dlmod)->handle) != 0)
47  _nmsg_dprintf(1, "%s: %s\n", __func__, dlerror());
48  free((*dlmod)->path);
49  free(*dlmod);
50  *dlmod = NULL;
51 }
an nmsg_message MUST always have a non-NULL ->np member.
Definition: private.h:365