summaryrefslogtreecommitdiffstats
path: root/sayhello.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2017-04-19 11:29:39 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2017-04-19 11:29:39 +0200
commit41a79081b0037c6fef2325478255df5397ad0a5a (patch)
tree510a3652e8fa9818ffb72b01fa40327f69608645 /sayhello.c
downloadsayhello-41a79081b0037c6fef2325478255df5397ad0a5a.tar.bz2
sayhello-41a79081b0037c6fef2325478255df5397ad0a5a.tar.xz
initial commit
Diffstat (limited to 'sayhello.c')
-rw-r--r--sayhello.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sayhello.c b/sayhello.c
new file mode 100644
index 0000000..1f132df
--- /dev/null
+++ b/sayhello.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <err.h>
+#include <dlfcn.h>
+
+int main(int argc, const char *argv[]) {
+ int i;
+ if (argc < 2)
+ errx(1, "usage: sayhello PLUGIN...");
+
+ for (i=1; i<argc; i++) {
+ const char *plugin = argv[i];
+ void (*sayhello)(void);
+ void *handle = dlopen(plugin, RTLD_NOW | RTLD_LOCAL);
+
+ if (handle == NULL) {
+ warn("%s", plugin);
+ continue;
+ }
+ dlerror(); /* clear existing error */
+
+ /* get the "sayhello" function from plugin */
+ sayhello = (void (*)(void)) dlsym(handle, "sayhello");
+ sayhello();
+
+ dlclose(handle);
+ }
+
+ return 0;
+}