From 59c2d73e786a3c6eb6446fa395b6697afc6ab783 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Voc=C5=AF?= Date: Mon, 8 Feb 2010 20:25:09 +0000 Subject: [PATCH] added configuration file option --- org.glite.lb.logger/src/activemq_cpp_plugin.cpp | 4 +-- org.glite.lb.logger/src/interlogd.c | 48 ++++++++++++++++++++++++- org.glite.lb.logger/src/interlogd.h | 4 +-- org.glite.lb.logger/src/plugin_mgr.c | 6 ++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/org.glite.lb.logger/src/activemq_cpp_plugin.cpp b/org.glite.lb.logger/src/activemq_cpp_plugin.cpp index 5d887c3..104dd50 100644 --- a/org.glite.lb.logger/src/activemq_cpp_plugin.cpp +++ b/org.glite.lb.logger/src/activemq_cpp_plugin.cpp @@ -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:"; diff --git a/org.glite.lb.logger/src/interlogd.c b/org.glite.lb.logger/src/interlogd.c index 7fa0509..ff4e981 100644 --- a/org.glite.lb.logger/src/interlogd.c +++ b/org.glite.lb.logger/src/interlogd.c @@ -60,13 +60,14 @@ static void usage (int status) " -k, --key location of server private key\n" " -C, --CAdir 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 specify address of log server\n" " -s, --socket non-default path of local socket\n" " -L, --lazy [] be lazy when closing connections to servers (default, timeout==0 means turn lazy off)\n" " -p, --parallel [] use parallel streams to the same server\n" " -q, --queue-low queue length that enables another insertions\n" " -Q, --queue-high max queue length\n" + " -F, --conf 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) { diff --git a/org.glite.lb.logger/src/interlogd.h b/org.glite.lb.logger/src/interlogd.h index 2dfa621..e35f727 100644 --- a/org.glite.lb.logger/src/interlogd.h +++ b/org.glite.lb.logger/src/interlogd.h @@ -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 */ diff --git a/org.glite.lb.logger/src/plugin_mgr.c b/org.glite.lb.logger/src/plugin_mgr.c index 0826dcc..05661e1 100644 --- a/org.glite.lb.logger/src/plugin_mgr.c +++ b/org.glite.lb.logger/src/plugin_mgr.c @@ -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); } -- 1.8.2.3