From 07cf1b51b76a9e90f5b35ab707f97f0c452a224c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Tue, 17 Jan 2006 16:35:40 +0000 Subject: [PATCH] basic configuration from command line options - legacy configuration thru env variables also usable --- org.glite.jp.index/src/conf.c | 101 ++++++++++++++++++++++++++++++++++++------ org.glite.jp.index/src/conf.h | 6 +-- 2 files changed, 91 insertions(+), 16 deletions(-) diff --git a/org.glite.jp.index/src/conf.c b/org.glite.jp.index/src/conf.c index 45b1803..f7bcd64 100644 --- a/org.glite.jp.index/src/conf.c +++ b/org.glite.jp.index/src/conf.c @@ -6,33 +6,108 @@ #include #include #include +#include +#include + #include #include #include "conf.h" +#include "db_ops.h" -int glite_jp_get_conf(int argc, char **argv, char *config_file, glite_jp_is_conf **configuration) +static const char *get_opt_string = "dc:k:C:V:nm:p:i:o:"; + +static struct option opts[] = { + {"debug", 0, NULL, 'd'}, +// {"cert", 1, NULL, 'c'}, +// {"key", 1, NULL, 'k'}, +// {"CAdir", 1, NULL, 'C'}, +// {"VOMSdir", 1, NULL, 'V'}, + {"noauth", 0, NULL, 'n'}, + {"mysql", 1, NULL, 'm'}, + {"port", 1, NULL, 'p'}, + {"pidfile", 1, NULL, 'i'}, + {"logfile", 1, NULL, 'o'}, + {NULL, 0, NULL, 0} +}; + + + +static void usage(char *me) { - char *debug; - char *ps = NULL; + fprintf(stderr,"usage: %s [option]\n" + "\t-d, --debug\t don't run as daemon, additional diagnostics\n" +// "\t-k, --key\t private key file\n" +// "\t-c, --cert\t certificate file\n" +// "\t-C, --CAdir\t trusted certificates directory\n" +// "\t-V, --VOMSdir\t trusted VOMS servers certificates directory\n" + "\t-n, --noauth\t don't check user identity with result owner\n" + "\t-m, --mysql\t database connect string\n" + "\t-p, --port\t port to listen\n" + "\t-i, --pidfile\t file to store master pid\n" + "\t-o, --logfile\t file to store logs\n" + "\n" + ,me); +} - // read comman line options and configuration file - // XXX: use EGEE global configure tools in future... +int glite_jp_get_conf(int argc, char **argv, char *config_file, glite_jp_is_conf **configuration) +{ + char *env, *ps = NULL; + int opt; glite_jp_is_conf *conf; conf = calloc(1, sizeof(*conf)); - // configuration from environment - conf->cs = getenv("GLITE_JPIS_DB"); - conf->port = getenv("GLITE_JPIS_PORT"); - debug = getenv("GLITE_JPIS_DEBUG"); - conf->debug = (debug != NULL) && (strcmp(debug, "0") != 0); - conf->no_auth = 0; // check authorization - conf->pidfile = getenv("GLITE_JPIS_PIDFILE"); - conf->logfile = getenv("GLITE_JPIS_LOGFILE"); + + while ((opt = getopt_long(argc,argv,get_opt_string,opts,NULL)) != EOF) switch (opt) { + case 'd': conf->debug = 1; break; +// case 'c': server_cert = optarg; break; +// case 'k': server_key = optarg; break; +// case 'C': cadir = optarg; break; +// case 'V': vomsdir = optarg; break; + case 'n': conf->no_auth = 1; break; + case 'm': conf->cs = optarg; break; + case 'p': conf->port = optarg; break; + case 'i': conf->pidfile = optarg; break; + case 'o': conf->logfile = optarg; break; + default : usage(argv[0]); exit(0); break; + } + + // *** legacy configuration from environment *********************** + // + if (!conf->debug) { + env = getenv("GLITE_JPIS_DEBUG"); + conf->debug = (env != NULL) && (strcmp(env, "0") != 0); + } + + if (!conf->cs) { + if (env = getenv("GLITE_JPIS_DB")) { + conf->cs = env; + } + else { + fprintf(stderr,"DB contact string not specified! "\ + "Using build-in default: %s \n", GLITE_JP_IS_DEFAULTCS); + } + } + if (!conf->port) { + if (env = getenv("GLITE_JPIS_PORT")) { + conf->port = env; + } + else { + fprintf(stderr,"JP IS port not specified! "\ + "Using build-in default: %s \n", GLITE_JPIS_DEFAULT_PORT_STR); + } + } + if (!conf->pidfile) + conf->pidfile = getenv("GLITE_JPIS_PIDFILE"); + if (!conf->logfile) + conf->logfile = getenv("GLITE_JPIS_LOGFILE"); + // + // ***************************************************************** + // prefixes & attributes defined in: // lb.server/build/jp_job_attrs.h (created when build plugin) diff --git a/org.glite.jp.index/src/conf.h b/org.glite.jp.index/src/conf.h index 5a4afe0..058fd06 100644 --- a/org.glite.jp.index/src/conf.h +++ b/org.glite.jp.index/src/conf.h @@ -3,7 +3,6 @@ #ifndef _CONF_H #define _CONF_H - #include #define GLITE_JPIS_DEFAULT_PORT_STR "8902" @@ -11,14 +10,15 @@ //#define lprintf #define lprintf(args...) glite_jp_lprintf(__FUNCTION__, ##args) + + typedef struct _glite_jp_is_feed { char *PS_URL; //URLs of Primary Storage servers - glite_jp_query_rec_t **query; // query to Primary Server (aka filter) + glite_jp_query_rec_t **query; // query to Primary Server (aka filter) int history, // type of query continuous; } glite_jp_is_feed; - typedef struct _glite_jp_is_conf { // all I need to get from comman line options and configuration file -- 1.8.2.3