2017-06-20 02:35:06 +00:00
|
|
|
/*! \file plugin.c
|
|
|
|
* Routines for loading and managing shared library plug-ins. */
|
|
|
|
/*
|
|
|
|
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
2010-06-30 17:43:11 +00:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
2017-11-12 16:00:26 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*
|
2010-06-30 17:43:11 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-12 19:44:18 +00:00
|
|
|
/*! \addtogroup utils
|
|
|
|
* @{
|
2017-06-20 02:35:06 +00:00
|
|
|
* \file plugin.c */
|
2012-12-06 20:25:27 +00:00
|
|
|
|
2023-01-18 17:54:00 +00:00
|
|
|
#include "config.h"
|
2010-06-30 17:43:11 +00:00
|
|
|
|
|
|
|
#if HAVE_DLFCN_H
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2010-08-31 09:14:04 +00:00
|
|
|
#include <limits.h>
|
2010-06-30 17:43:11 +00:00
|
|
|
|
2011-03-22 15:36:13 +00:00
|
|
|
#include <osmocom/core/plugin.h>
|
2010-06-30 17:43:11 +00:00
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Load all plugins available in given directory
|
2012-12-06 20:25:27 +00:00
|
|
|
* \param[in] directory full path name of directory containing plug-ins
|
|
|
|
* \returns number of plugins loaded in case of success, negative in case of error
|
|
|
|
*/
|
2011-05-07 10:50:08 +00:00
|
|
|
int osmo_plugin_load_all(const char *directory)
|
2010-06-30 17:43:11 +00:00
|
|
|
{
|
|
|
|
unsigned int num = 0;
|
|
|
|
char fname[PATH_MAX];
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
dir = opendir(directory);
|
|
|
|
if (!dir)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
while ((entry = readdir(dir))) {
|
|
|
|
snprintf(fname, sizeof(fname), "%s/%s", directory,
|
|
|
|
entry->d_name);
|
|
|
|
if (dlopen(fname, RTLD_NOW))
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
#else
|
2011-05-07 10:50:08 +00:00
|
|
|
int osmo_plugin_load_all(const char *directory)
|
2010-06-30 17:43:11 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_DLFCN_H */
|
2017-06-12 19:44:18 +00:00
|
|
|
|
|
|
|
/*! @} */
|