]> git.itanic.dy.fi Git - rrdd/commitdiff
plugins: Add version checking
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 20 Nov 2012 19:16:01 +0000 (21:16 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 20 Nov 2012 20:07:08 +0000 (22:07 +0200)
Ensure that plugin is always built from the same version as the main
rrdd executable. If the version numbers don't match, don't load the
plugin.

This will ensure there are no strange bugs that appear when plugin
code is not built against the same source as the main executable.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
.gitignore
onewire_parser.c
plugin.h
plugin_manager.c

index 6add1260dae2648bd0f469987fcb80d2c094ec6d..a16043e4f279786f3dcfc4afa5eab6349b4e3d12 100644 (file)
@@ -10,3 +10,6 @@ database.h
 *.conf
 *.rrd
 *.so
+
+version.h
+.*
index 287fec147c67278c4c822df33f27316e631ba36a..e440810743d3704471537f71b7a942a8f580b8a2 100644 (file)
@@ -6,6 +6,7 @@
 #include "string.h"
 #include "utils.h"
 #include "plugin.h"
+#include "version.h"
 
 static int parse_opts(const char *str, char *ow_path, size_t pathlen, double *offset)
 {
@@ -140,4 +141,5 @@ static int init_onewire_parser(void)
 struct plugin_info plugin_info = {
        .name = "onewire_parser",
        .init = init_onewire_parser,
+       .version = RRDD_VERSION,
 };
index da22b4d09d107b5338aab92e2eca059958b34fb4..44920577791ea64a5e25a33c840879d08b34d0bf 100644 (file)
--- a/plugin.h
+++ b/plugin.h
@@ -4,6 +4,9 @@
 typedef int (plugin_init_fn_t)(void);
 
 struct plugin_info {
+       /* Plugin version, must match with main executable version */
+       const char *version;
+
        /* Name of the plugin, used in debug prints */
        const char *name;
 
index 1c33951d10860f6d93e969ebc9c35fd29b0cf458..6ddac4cda4bf3ff3130a21bccd24e333af54ed3b 100644 (file)
@@ -6,6 +6,7 @@
 #include "plugin_manager.h"
 #include "plugin.h"
 #include "debug.h"
+#include "version.h"
 
 static char *exec_path;
 
@@ -36,6 +37,19 @@ int load_plugin(const char *path)
                goto out;
        }
 
+       if (!info->version) {
+               pr_err("Plugin %s version info missing\n", path);
+               ret = -1;
+               goto out;
+       }
+
+       if (strcmp(RRDD_VERSION, info->version)) {
+               pr_err("Plugin %s version mismatch, expected %s, got %s\n",
+                       path, RRDD_VERSION, info->version);
+               ret = -1;
+               goto out;
+       }
+
        if (!info->init) {
                pr_err("Plugin info structure has NULL .init callback\n");
                goto out;