added configuration file option
authorMichal Voců <michal@ruk.cuni.cz>
Mon, 8 Feb 2010 20:25:09 +0000 (20:25 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Mon, 8 Feb 2010 20:25:09 +0000 (20:25 +0000)
org.glite.lb.logger/src/activemq_cpp_plugin.cpp
org.glite.lb.logger/src/interlogd.c
org.glite.lb.logger/src/interlogd.h
org.glite.lb.logger/src/plugin_mgr.c

index 5d887c3..104dd50 100644 (file)
@@ -311,7 +311,7 @@ event_queue_close(struct event_queue *eq)
 
 extern "C"
 int
-plugin_init(const char *s)
+plugin_init(const char *config)
 {
        std::string brokerURI;
 
@@ -351,4 +351,4 @@ plugin_supports_scheme(const char *scheme)
 
 cms::Connection *OutputPlugin::connection = NULL;
 cms::ConnectionFactory *OutputPlugin::connectionFactory = NULL;
-const char *OutputPlugin::SCHEME = "x-msg://";
+const char *OutputPlugin::SCHEME = "x-msg:";
index 7fa0509..ff4e981 100644 (file)
@@ -60,13 +60,14 @@ static void usage (int status)
               "  -k, --key  <file>          location of server private key\n"
               "  -C, --CAdir <dir>          directory containing CA certificates\n"
               "  -b, --book                 send events to bookkeeping server only\n"
-              "  -i, --pidfile              pid file\n"
+              "  -i, --pidfile                  pid file\n"
               "  -l, --log-server <host>    specify address of log server\n"
               "  -s, --socket <path>        non-default path of local socket\n"
               "  -L, --lazy [<timeout>]     be lazy when closing connections to servers (default, timeout==0 means turn lazy off)\n"
               "  -p, --parallel [<num>]     use <num> parallel streams to the same server\n"
               "  -q, --queue-low <num>      queue length that enables another insertions\n"
               "  -Q, --queue-high <num>     max queue length\n"
+                  "  -F, --conf <file>                  load configuration from config file\n"
 #ifdef LB_PERF
               "  -n, --nosend               PERFTEST: consume events instead of sending\n"
               "  -S, --nosync               PERFTEST: do not check logd files for lost events\n"
@@ -104,6 +105,8 @@ char *key_file  = NULL;
 char *CAcert_dir = NULL;
 char *log_server = NULL;
 char *socket_path = DEFAULT_SOCKET;
+static char *conf_file = NULL;
+static char *config = NULL;
 
 static struct option const long_options[] =
 {
@@ -124,6 +127,7 @@ static struct option const long_options[] =
   {"parallel", optional_argument, 0, 'p'},
   {"queue_size_low", required_argument, 0, 'q'},
   {"queue_size_high", required_argument, 0, 'Q'},
+  {"conf", required_argument, 0, 'F'},
 #ifdef LB_PERF
   {"nosend", no_argument, 0, 'n'},
   {"nosync", no_argument, 0, 'S'},
@@ -163,6 +167,7 @@ decode_switches (int argc, char **argv)
                           "p" /* parallel */
                           "q:"
                           "Q:"
+                          "F:" /* conf file */
 #ifdef LB_PERF
                           "n" /* nosend */
                           "S" /* nosync */
@@ -258,6 +263,10 @@ decode_switches (int argc, char **argv)
                queue_size_high = atoi(optarg);
                break;
 
+       case 'F':
+               conf_file = strdup(optarg);
+               break;
+
 #ifdef LB_PERF
        case 'n':
                nosend = 1;
@@ -295,6 +304,38 @@ decode_switches (int argc, char **argv)
 }
 
 
+char *load_conf_file(char *filename)
+{
+       struct stat fs;
+       FILE *cf;
+       char *s;
+
+       if(stat(filename, &fs) < 0) {
+               glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR,
+                               "Could not stat config file %s: %s\n", filename, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       s = malloc(fs.st_size);
+       if(s == NULL) {
+               glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Not enough memory for config file");
+               exit(EXIT_FAILURE);
+       }
+       cf = fopen(filename, "r");
+       if(cf == NULL) {
+               glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR,
+                               "Error opening config file %s: %s\n", filename, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       if(fread(s, fs.st_size, 1, cf) != fs.st_size) {
+               glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR,
+                               "Error reading config file %s: %s\n", filename, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       fclose(cf);
+       return s;
+}
+
+
 void handle_signal(int num) {
 
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Received signal %d\n", num);
@@ -365,6 +406,11 @@ main (int argc, char **argv)
          exit(EXIT_FAILURE);
   }
 
+  /* parse config file, if any */
+  if(conf_file != NULL) {
+         config = load_conf_file(conf_file);
+  }
+
   /* check for reasonable queue lengths */
   if(queue_size_low == 0 && queue_size_high > 0 ||
      queue_size_low > queue_size_high) {
index 2dfa621..e35f727 100644 (file)
@@ -206,7 +206,7 @@ struct il_output_plugin {
        int     (*event_queue_connect)(struct event_queue *);
        int     (*event_queue_send)(struct event_queue *);
        int     (*event_queue_close)(struct event_queue *);
-       int             (*plugin_init)();
+       int             (*plugin_init)(const char *);
        int             (*plugin_supports_scheme)(const char *);
 };
 
@@ -290,7 +290,7 @@ int receive_http(void *, int (*)(void *, char *, const int), il_http_message_t *
 #endif
 
 /* plugin functions */
-int plugin_init(const char *);
+int plugin_init(const char *, const char *);
 struct il_output_plugin *plugin_get(const char *);
 
 /* master main loop */
index 0826dcc..05661e1 100644 (file)
@@ -23,7 +23,7 @@ static struct plugin_list *plugins = NULL;
                return -1; \
        }
 
-int plugin_init(const char *plugin_name)
+int plugin_init(const char *plugin_name, const char *cfg)
 {
        char err[256];
        void *dl_handle;
@@ -45,13 +45,13 @@ int plugin_init(const char *plugin_name)
        }
 
        plugin->next = plugins;
-       DL_RESOLVESYM(plugin->plugin_def.plugin_init, dl_handle, "plugin_init", int(*)());
+       DL_RESOLVESYM(plugin->plugin_def.plugin_init, dl_handle, "plugin_init", int(*)(char *));
        DL_RESOLVESYM(plugin->plugin_def.plugin_supports_scheme, dl_handle,  "plugin_supports_scheme", int(*)(const char *));
        DL_RESOLVESYM(plugin->plugin_def.event_queue_connect, dl_handle, "event_queue_connect", int (*)(struct event_queue*));
        DL_RESOLVESYM(plugin->plugin_def.event_queue_send, dl_handle, "event_queue_send", int (*)(struct event_queue *));
        DL_RESOLVESYM(plugin->plugin_def.event_queue_close, dl_handle, "event_queue_close", int (*)(struct event_queue *));
 
-       return (*plugin->plugin_def.plugin_init)();
+       return (*plugin->plugin_def.plugin_init)(cfg);
 }