summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2013-06-24 22:04:47 +0000
committerTed Ross <tross@apache.org>2013-06-24 22:04:47 +0000
commit26bdc7ad1e151c3c0775bcc30e4b7d23edeef0bc (patch)
tree51d197a9e84f44057dc066145368454b8761720d
parent3991e5679d0d79f4da174f05adc3093150a3635d (diff)
downloadqpid-python-26bdc7ad1e151c3c0775bcc30e4b7d23edeef0bc.tar.gz
QPID-4913 - Added configuration file option in command line parser.
Also added a cmake option to specify the default path to the configuration file. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1496233 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/extras/dispatch/router/CMakeLists.txt7
-rw-r--r--qpid/extras/dispatch/router/src/main.c35
2 files changed, 41 insertions, 1 deletions
diff --git a/qpid/extras/dispatch/router/CMakeLists.txt b/qpid/extras/dispatch/router/CMakeLists.txt
index efb424ee13..ee6d1934cf 100644
--- a/qpid/extras/dispatch/router/CMakeLists.txt
+++ b/qpid/extras/dispatch/router/CMakeLists.txt
@@ -17,6 +17,13 @@
## under the License.
##
+
+set(DEFAULT_CONFIG_PATH "/etc/qpid-dispatch.conf" CACHE string "Default Config File Path")
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
##
## Build the router application
##
diff --git a/qpid/extras/dispatch/router/src/main.c b/qpid/extras/dispatch/router/src/main.c
index 20c821d04f..e94bafce75 100644
--- a/qpid/extras/dispatch/router/src/main.c
+++ b/qpid/extras/dispatch/router/src/main.c
@@ -22,10 +22,13 @@
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
+#include <getopt.h>
+#include "config.h"
static int exit_with_sigint = 0;
static dx_dispatch_t *dispatch;
+
/**
* The thread_start_handler is invoked once for each server thread at thread startup.
*/
@@ -84,9 +87,39 @@ static void startup(void *context)
int main(int argc, char **argv)
{
+ const char *config_path = DEFAULT_CONFIG_PATH;
+
+ static struct option long_options[] = {
+ {"config", required_argument, 0, 'c'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ while (1) {
+ int c = getopt_long(argc, argv, "c:h", long_options, 0);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'c' :
+ config_path = optarg;
+ break;
+
+ case 'h' :
+ printf("Usage: %s [OPTION]\n\n", argv[0]);
+ printf(" -c, --config=PATH (%s)\n", DEFAULT_CONFIG_PATH);
+ printf(" Load configuration from file at PATH\n");
+ printf(" -h, --help Print this help\n");
+ exit(0);
+
+ case '?' :
+ exit(1);
+ }
+ }
+
dx_log_set_mask(LOG_INFO | LOG_TRACE | LOG_ERROR);
- dispatch = dx_dispatch("../etc/qpid-dispatch.conf");
+ dispatch = dx_dispatch(config_path);
dx_server_set_signal_handler(dispatch, server_signal_handler, 0);
dx_server_set_start_handler(dispatch, thread_start_handler, 0);