summaryrefslogtreecommitdiff
path: root/src/plugins/plugin_manager.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 12:43:51 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 12:43:51 +0000
commite77725b55190b8ec6dcab46aa137c32652ea004b (patch)
treea80e237f1f65873f908f5819488c1c32683aff74 /src/plugins/plugin_manager.c
parent2e1aa3d8853f3b49e93b1d50b1b6e60e8238d79c (diff)
Support for 'alias' + test. Improved formatting and '.gitignore'.
Diffstat (limited to 'src/plugins/plugin_manager.c')
-rw-r--r--src/plugins/plugin_manager.c135
1 files changed, 76 insertions, 59 deletions
diff --git a/src/plugins/plugin_manager.c b/src/plugins/plugin_manager.c
index aab98c8..afca55e 100644
--- a/src/plugins/plugin_manager.c
+++ b/src/plugins/plugin_manager.c
@@ -6,82 +6,99 @@
#include <string.h>
// Linked list node for plugins.
-typedef struct PluginNode {
- ZPlugin *plugin;
- void *handle; // dlopen handle (NULL for built-ins).
- struct PluginNode *next;
+typedef struct PluginNode
+{
+ ZPlugin *plugin;
+ void *handle; // dlopen handle (NULL for built-ins).
+ struct PluginNode *next;
} PluginNode;
static PluginNode *head = NULL;
-void zptr_plugin_mgr_init(void) { head = NULL; }
+void zptr_plugin_mgr_init(void)
+{
+ head = NULL;
+}
-void zptr_register_plugin(ZPlugin *plugin) {
- if (!plugin) {
- return;
- }
+void zptr_register_plugin(ZPlugin *plugin)
+{
+ if (!plugin)
+ {
+ return;
+ }
- if (zptr_find_plugin(plugin->name)) {
- return;
- }
+ if (zptr_find_plugin(plugin->name))
+ {
+ return;
+ }
- PluginNode *node = malloc(sizeof(PluginNode));
- node->plugin = plugin;
- node->handle = NULL;
- node->next = head;
- head = node;
+ PluginNode *node = malloc(sizeof(PluginNode));
+ node->plugin = plugin;
+ node->handle = NULL;
+ node->next = head;
+ head = node;
}
-ZPlugin *zptr_load_plugin(const char *path) {
- void *handle = dlopen(path, RTLD_LAZY);
- if (!handle) {
- return NULL;
- }
+ZPlugin *zptr_load_plugin(const char *path)
+{
+ void *handle = dlopen(path, RTLD_LAZY);
+ if (!handle)
+ {
+ return NULL;
+ }
- ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init");
- if (!init_fn) {
- fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path);
- dlclose(handle);
- return NULL;
- }
+ ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init");
+ if (!init_fn)
+ {
+ fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path);
+ dlclose(handle);
+ return NULL;
+ }
- ZPlugin *plugin = init_fn();
- if (!plugin) {
- fprintf(stderr, "Plugin '%s' init returned NULL\n", path);
- dlclose(handle);
- return NULL;
- }
+ ZPlugin *plugin = init_fn();
+ if (!plugin)
+ {
+ fprintf(stderr, "Plugin '%s' init returned NULL\n", path);
+ dlclose(handle);
+ return NULL;
+ }
- // Register
- PluginNode *node = malloc(sizeof(PluginNode));
- node->plugin = plugin;
- node->handle = handle;
- node->next = head;
- head = node;
+ // Register
+ PluginNode *node = malloc(sizeof(PluginNode));
+ node->plugin = plugin;
+ node->handle = handle;
+ node->next = head;
+ head = node;
- return plugin;
+ return plugin;
}
-ZPlugin *zptr_find_plugin(const char *name) {
- PluginNode *curr = head;
- while (curr) {
- if (strcmp(curr->plugin->name, name) == 0) {
- return curr->plugin;
+ZPlugin *zptr_find_plugin(const char *name)
+{
+ PluginNode *curr = head;
+ while (curr)
+ {
+ if (strcmp(curr->plugin->name, name) == 0)
+ {
+ return curr->plugin;
+ }
+ curr = curr->next;
}
- curr = curr->next;
- }
- return NULL;
+ return NULL;
}
-void zptr_plugin_mgr_cleanup(void) {
- PluginNode *curr = head;
- while (curr) {
- PluginNode *next = curr->next;
- if (curr->handle) {
- dlclose(curr->handle);
+void zptr_plugin_mgr_cleanup(void)
+{
+ PluginNode *curr = head;
+ while (curr)
+ {
+ PluginNode *next = curr->next;
+ if (curr->handle)
+ {
+ dlclose(curr->handle);
+ }
+ free(curr);
+ curr = next;
}
- free(curr);
- curr = next;
- }
- head = NULL;
+ head = NULL;
}