Skip to content

Commit

Permalink
use dlfcn.h dynamic loading function only if libdl is available
Browse files Browse the repository at this point in the history
  • Loading branch information
merge committed May 12, 2017
1 parent bb4b23e commit ff8c7d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/ts_close.c
Expand Up @@ -14,7 +14,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_LIBDL
#include <dlfcn.h>
#endif

#include "tslib-private.h"

Expand All @@ -35,9 +37,10 @@ int ts_close(struct tsdev *ts)
info->ops->fini(info);
else
free(info);

#ifdef HAVE_LIBDL
if (handle)
dlclose(handle);
#endif

info = next;
}
Expand Down
8 changes: 7 additions & 1 deletion src/ts_config.c
Expand Up @@ -13,10 +13,15 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_LIBDL
#include <dlfcn.h>
#endif

#include <errno.h>

#if !defined(HAVE_STRSEP)
Expand Down Expand Up @@ -164,9 +169,10 @@ int ts_reconfig(struct tsdev *ts)

if (info->ops->fini)
info->ops->fini(info);

#ifdef HAVE_LIBDL
if (handle)
dlclose(handle);
#endif

info = next;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ts_load_module.c
Expand Up @@ -14,10 +14,14 @@
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef HAVE_LIBDL
#include <dlfcn.h>
#endif

#include "tslib-private.h"

Expand Down Expand Up @@ -138,6 +142,7 @@ static struct tslib_module_info *__ts_load_module_static(struct tsdev *ts,

#define PLUGIN_DIR_LEN 1024

#ifdef HAVE_LIBDL
static struct tslib_module_info *__ts_load_module_shared(struct tsdev *ts,
const char *module,
const char *params)
Expand Down Expand Up @@ -190,6 +195,7 @@ static struct tslib_module_info *__ts_load_module_shared(struct tsdev *ts,

return info;
}
#endif /* HAVE_LIBDL */

static int __ts_load_module(struct tsdev *ts, const char *module,
const char *params, int raw)
Expand All @@ -206,8 +212,10 @@ static int __ts_load_module(struct tsdev *ts, const char *module,
#endif

info = __ts_load_module_static(ts, module, params);
#ifdef HAVE_LIBDL
if (!info)
info = __ts_load_module_shared(ts, module, params);
#endif
if (!info)
return -1;

Expand All @@ -225,8 +233,10 @@ static int __ts_load_module(struct tsdev *ts, const char *module,
if (info->ops->fini)
info->ops->fini(info);

#ifdef HAVE_LIBDL
if (handle)
dlclose(handle);
#endif
}

return ret;
Expand Down

0 comments on commit ff8c7d9

Please sign in to comment.