Add basic support for dynamically loadable plugins

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2012-09-21 00:33:46 +02:00
parent a0fa877520
commit 239772d667
6 changed files with 300 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
# Plugin based services architecture for finit -*-Makefile-*-
CFLAGS = -fPIC -g -Os -I..
CPPFLAGS = -W -Wall
LDFLAGS = -shared
PLUGINS = foo.so
DEPS = $(addprefix .,$(PLUGINS:.so=.d))
include ../common.mk
all: $(PLUGINS)
clean:
$(RM) $(PLUGINS) *.o
distclean: clean
$(RM) $(JUNK) $(DEPS)
install: all
@for plugin in $(PLUGINS); do \
echo " INSTALL $(PLUGIN_DIR)/$$plugin"; \
cp $$plugin $(PLUGIN_DIR); \
done
uninstall:
@for plugin in $(PLUGINS); do \
echo " RM $(PLUGIN_DIR)/$$plugin"; \
rm $(PLUGIN_DIR)/$$plugin; \
done
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
+54
View File
@@ -0,0 +1,54 @@
/* Test of plugin to dynamic-linking daemon.
*
* Copyright (c) 2012 Joachim Nilsson <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include "plugin.h"
#define PLUGIN_NAME "foo"
static void service(void *arg __unused)
{
printf("Service %s\n", PLUGIN_NAME);
}
static plugin_t plugin = {
.name = PLUGIN_NAME,
.svc = {
.cb = service,
},
};
static void init_plugin(void)
{
plugin_register(&plugin);
}
static void exit_plugin(void)
{
plugin_unregister(&plugin);
}
PLUGIN_INIT(init_plugin)
PLUGIN_EXIT(exit_plugin)
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/