diff --git a/README b/README index b0745d4b8..23f66eeb3 100644 --- a/README +++ b/README @@ -52,5 +52,9 @@ modules it will search using a predescribed search path. The rules are: 3. Look in /usr/local/skysql/gateway/modules +Configuration is read by default from the file $GATEWAY_HOME/etc/gateway.cnf, +/etc/gateway.cnf, an example file is included in the root of the source tree. The +default location can be overriden by use of the -c flag on the command line. This +should be immediately followed by the path to the configuration file. */ diff --git a/core/config.c b/core/config.c index eab55eccf..b5d2b414c 100644 --- a/core/config.c +++ b/core/config.c @@ -163,7 +163,7 @@ CONFIG_CONTEXT *obj; CONFIG_CONTEXT *obj1 = context; while (obj1) { - if (strcmp(s, obj1->object) == 0) + if (strcmp(s, obj1->object) == 0 && obj->element && obj1->element) serviceAddBackend(obj->element, obj1->element); obj1 = obj1->next; } @@ -181,7 +181,7 @@ CONFIG_CONTEXT *obj; CONFIG_CONTEXT *ptr = context; while (ptr && strcmp(ptr->object, service) != 0) ptr = ptr->next; - if (ptr) + if (ptr && ptr->element) serviceAddProtocol(ptr->element, protocol, atoi(port)); } } diff --git a/core/gateway.c b/core/gateway.c index ee6d38317..3a8316309 100644 --- a/core/gateway.c +++ b/core/gateway.c @@ -35,6 +35,7 @@ */ #include +#include #include #include #include @@ -170,7 +171,17 @@ main(int argc, char **argv) int daemon_mode = 1; sigset_t sigset; int n; -char *cnf_file = "/etc/gateway.cnf"; +char buf[1024], *home, *cnf_file = NULL; + + if ((home = getenv("GATEWAY_HOME")) != NULL) + { + sprintf(buf, "%s/etc/gateway.cnf", home); + if (access(buf, R_OK) == 0) + cnf_file = buf; + } + if (cnf_file == NULL && access("/etc/gateway.cnf", R_OK) == 0) + cnf_file = "/etc/gateway.cnf"; + for (n = 0; n < argc; n++) @@ -186,6 +197,13 @@ char *cnf_file = "/etc/gateway.cnf"; } } + if (cnf_file == NULL) + { + fprintf(stderr, "Unable to find a gateway configuration file, either install one in\n"); + fprintf(stderr, "/etc/gateway.cnf, $GATEWAY_HOME/etc/gateway.cnf or use the -c option.\n"); + exit(1); + } + if (!load_config(cnf_file)) { fprintf(stderr, "Failed to load gateway configuration file %s\n", cnf_file);