mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
Skip . and .. in plugin loader and trigger error on failed plugin load.
Fix from field testing. Need to skip "." and ".." directory entries when loading plugins from /lib/finit/plugins. Also, trigger an error when a required plugin fails to load. We need to print to console since syslogd has not started yet. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
cbb50937cd
commit
40c7a44d4f
1 file changed
+7
-2
@@ -265,17 +265,19 @@ static int load_one(char *path, char *name)
|
|||||||
char plugin[256];
|
char plugin[256];
|
||||||
void *handle;
|
void *handle;
|
||||||
|
|
||||||
if (!path || !fisdir(path)) {
|
if (!path || !fisdir(path) || !name) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compose full path, with optional .so extension, to plugin */
|
||||||
noext = strcmp(name + strlen(name) - 3, ".so");
|
noext = strcmp(name + strlen(name) - 3, ".so");
|
||||||
snprintf(plugin, sizeof(plugin), "%s/%s%s", path, name, noext ? ".so" : "");
|
snprintf(plugin, sizeof(plugin), "%s/%s%s", path, name, noext ? ".so" : "");
|
||||||
|
|
||||||
_d("Loading plugin %s ...", basename(plugin));
|
_d("Loading plugin %s ...", basename(plugin));
|
||||||
handle = dlopen(plugin, RTLD_LAZY | RTLD_GLOBAL);
|
handle = dlopen(plugin, RTLD_LAZY | RTLD_GLOBAL);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
_d("Failed loading plugin %s: %s", plugin, dlerror());
|
_e("Failed loading plugin %s: %s", plugin, dlerror());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +323,9 @@ int plugin_load_all(char *path)
|
|||||||
plugpath = path;
|
plugpath = path;
|
||||||
|
|
||||||
while ((entry = readdir(dp))) {
|
while ((entry = readdir(dp))) {
|
||||||
|
if (entry->d_name[0] == '.')
|
||||||
|
continue; /* Skip . and .. directories */
|
||||||
|
|
||||||
// print_desc(" Loading plugin ", basename(plugin));
|
// print_desc(" Loading plugin ", basename(plugin));
|
||||||
if (load_one(path, entry->d_name))
|
if (load_one(path, entry->d_name))
|
||||||
fail++;
|
fail++;
|
||||||
|
|||||||
Reference in new issue
Block a user