added config file parsing and plugin initialization
authorMichal Voců <michal@ruk.cuni.cz>
Tue, 9 Feb 2010 10:18:18 +0000 (10:18 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Tue, 9 Feb 2010 10:18:18 +0000 (10:18 +0000)
org.glite.lb.logger/src/il_error.h
org.glite.lb.logger/src/interlogd.c
org.glite.lb.logger/src/plugin_mgr.c

index 5fb5b4f..8237f2f 100644 (file)
@@ -12,7 +12,8 @@ enum err_code_maj { /* minor =                   */
   IL_PROTO,         /*     LB_*                  */
   IL_LBAPI,         /*     dgLBErrCode           */
   IL_DGGSS,         /*     EDG_WLL_GSS_*         */
-  IL_HOST           /*     h_errno               */
+  IL_HOST,          /*     h_errno               */
+  IL_DL             /*     dlerror               */
 };
 
 struct error_inf {
index cc2d543..ce63029 100644 (file)
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include "interlogd.h"
 #include "glite/lb/log_proto.h"
@@ -316,7 +317,7 @@ char *load_conf_file(char *filename)
                                "Could not stat config file %s: %s\n", filename, strerror(errno));
                exit(EXIT_FAILURE);
        }
-       s = malloc(fs.st_size);
+       s = malloc(fs.st_size + 1);
        if(s == NULL) {
                glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Not enough memory for config file");
                exit(EXIT_FAILURE);
@@ -327,12 +328,13 @@ char *load_conf_file(char *filename)
                                "Error opening config file %s: %s\n", filename, strerror(errno));
                exit(EXIT_FAILURE);
        }
-       if(fread(s, fs.st_size, 1, cf) != fs.st_size) {
+       if(fread(s, fs.st_size, 1, cf) != 1) {
                glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR,
                                "Error reading config file %s: %s\n", filename, strerror(errno));
                exit(EXIT_FAILURE);
        }
        fclose(cf);
+       s[fs.st_size] = 0;
        return s;
 }
 
@@ -510,6 +512,37 @@ main (int argc, char **argv)
   }
   glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_INFO, "Using certificate %s", cred_handle->creds->name);
 
+  /* parse config, initialize plugins */
+  glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initializing plugins:\n");
+  if(config) {
+         char *s = strstr(config, "[interlogd]");
+         char *p;
+         char name[MAXPATHLEN+1];
+
+         /* next line */
+         s = strchr(s, '\n');
+         if(s) s++;
+         while(s) {
+                 if(*s == 0 || *s == '[')
+                         break;
+                 /* parse line */
+                 p = strchr(s, '\n');
+                 if(p) {
+                         *p = 0;
+                 }
+                 /* XXX possible overflow by long line in config file */
+                 ret = sscanf(s, " plugin =%s", name);
+                 if(p) *p = '\n';
+                 if(ret > 0) {
+                         glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  loading plugin %s\n", name);
+                         if(plugin_init(name, config) < 0) {
+                                 glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Failed to load plugin %s: %s\n", name, error_get_msg());
+                         }
+                 }
+                 s = p;
+         }
+  }
+
 #ifndef PERF_EMPTY
   /* find all unsent events waiting in files */
 #ifdef LB_PERF
index 05661e1..49bb075 100644 (file)
@@ -19,7 +19,7 @@ static struct plugin_list *plugins = NULL;
        var = (type) dlsym(handle, name); \
        if(var == NULL) { \
                snprintf(err, sizeof(err), "plugin_init: error resolving %s: %s", name, dlerror()); \
-               set_error(IL_SYS, errno, err); \
+               set_error(IL_DL, ENOENT, err); \
                return -1; \
        }