]> git.itanic.dy.fi Git - rrdd/commitdiff
parser: Try loading a parser from a plugin in case no parser is found
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 19 Nov 2012 19:59:00 +0000 (21:59 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 19 Nov 2012 20:10:12 +0000 (22:10 +0200)
When a parser is queried and one is not found within the ones that we
have already registered, try loading a plugin with that name. If
parser plugins are available, the parser might be available after the
plugin has been loaded.

The project is now fully compatible with having parsers as plugins.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Makefile
parser.c

index 3a89e912e5378c36b1e22ecef087db64eac77385..677e88e18b8f862d29d955f094bc2576b16bb521 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CC=gcc
 LD=ld
-CFLAGS=-Wall -O2 -g
+CFLAGS=-Wall -O2 -g -fPIC
 
 RRDD_OBJS= main.o process.o rrdtool.o parser.o built_in_parsers.o string.o \
                debug.o config.o onewire_parser.o plugin_manager.o
@@ -24,7 +24,7 @@ rrdd: $(RRDD_OBJS)
        $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS) -lconfig -lownet -ldl -rdynamic
 
 clean:
-       rm -vf rrdd *~ *.o .*.d
+       rm -vf rrdd *~ *.o .*.d *.so
 
 .c.o:
        $(QUIET_CC)$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@
index 4a5e5355d5360483a1aef22c42d0604cdd17ccbb..0437096de547d6665cff20a6ad2ac52b63d468d4 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2,6 +2,7 @@
 
 #include "parser.h"
 #include "debug.h"
+#include "plugin_manager.h"
 
 static struct parser_info *parser_list;
 
@@ -30,7 +31,7 @@ int register_parser(struct parser_info *info)
        return 0;
 }
 
-struct parser_info *str_to_parser(const char *str)
+static struct parser_info *_str_to_parser(const char *str)
 {
        struct parser_info *parser;
 
@@ -41,3 +42,22 @@ struct parser_info *str_to_parser(const char *str)
 
        return NULL;
 }
+
+struct parser_info *str_to_parser(const char *str)
+{
+       struct parser_info *parser;
+       int ret;
+
+       parser = _str_to_parser(str);
+
+       if (parser)
+               return parser;
+
+       /* No parser found? Try loading a plugin */
+       ret = load_parser_plugin(str);
+       if (ret)
+               return NULL;
+
+       /* Try finding the parser again, maybe we got lucky and have it now */
+       return _str_to_parser(str);
+}