1
/* plugin.c -- generic plugin routines for vlock,
2
* the VT locking program for linux
4
* This program is copyright (C) 2007 Frank Benkstein, and is free
5
* software which is freely distributable under the terms of the
6
* GNU General Public License version 2, included as the file COPYING in this
7
* distribution. It is NOT public domain software, and any
8
* redistribution not permitted by the GNU General Public License is
9
* expressly forbidden without prior written permission from
23
/* Allocate a new plugin struct. */
24
struct plugin *new_plugin(const char *name, struct plugin_type *type)
26
struct plugin *p = malloc(sizeof *p);
32
/* For security plugin names must not contain a slash. */
33
last_slash = strrchr(name, '/');
35
if (last_slash != NULL)
38
p->name = strdup(name);
40
if (p->name == NULL) {
46
p->save_disabled = false;
48
for (size_t i = 0; i < nr_dependencies; i++)
49
p->dependencies[i] = list_new();
53
if (p->type->init(p)) {
61
/* Destroy the given plugin. */
62
void destroy_plugin(struct plugin *p)
64
/* Call destroy method. */
67
/* Destroy dependency lists. */
68
for (size_t i = 0; i < nr_dependencies; i++) {
69
list_delete_for_each(p->dependencies[i], dependency_item)
70
free(dependency_item->data);
72
list_free(p->dependencies[i]);
79
bool call_hook(struct plugin *p, const char *hook_name)
81
return p->type->call_hook(p, hook_name);