Author: aconway
Date: Fri Jun 13 19:08:05 2014
New Revision: 1602492
URL: http://svn.apache.org/r1602492
Log:
DISPATCH-16: Error handling in router main - exit early on error during
start-up.
Modified:
qpid/dispatch/trunk/include/qpid/dispatch/dispatch.h
qpid/dispatch/trunk/include/qpid/dispatch/error.h
qpid/dispatch/trunk/router/src/main.c
qpid/dispatch/trunk/src/config.c
qpid/dispatch/trunk/src/config_private.h
qpid/dispatch/trunk/src/dispatch.c
qpid/dispatch/trunk/src/error.c
Modified: qpid/dispatch/trunk/include/qpid/dispatch/dispatch.h
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/include/qpid/dispatch/dispatch.h?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/include/qpid/dispatch/dispatch.h (original)
+++ qpid/dispatch/trunk/include/qpid/dispatch/dispatch.h Fri Jun 13 19:08:05
2014
@@ -8,9 +8,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,6 +19,7 @@
* under the License.
*/
+#include <qpid/dispatch/error.h>
/**
* @defgroup dispatch
*
@@ -59,7 +60,7 @@ void qd_dispatch_extend_config_schema(qd
* @param dispatch The dispatch handle returned by qd_dispatch
* @param config_path The path to the configuration file.
*/
-void qd_dispatch_load_config(qd_dispatch_t *dispatch, const char *config_path);
+qd_error_t qd_dispatch_load_config(qd_dispatch_t *dispatch, const char
*config_path);
/**
* Configure the AMQP container from the parsed configuration file.
Modified: qpid/dispatch/trunk/include/qpid/dispatch/error.h
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/include/qpid/dispatch/error.h?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/include/qpid/dispatch/error.h (original)
+++ qpid/dispatch/trunk/include/qpid/dispatch/error.h Fri Jun 13 19:08:05 2014
@@ -41,6 +41,7 @@ typedef enum {
QD_ERROR_ALLOC,
QD_ERROR_MESSAGE, ///< Error parsing a message.
QD_ERROR_PYTHON, ///< Error from python code.
+ QD_ERROR_CONFIG, ///< Error in configuration
QD_ERROR_COUNT ///< Not an error, marks the end of the enum
} qd_error_t;
@@ -83,4 +84,5 @@ extern const int QD_ERROR_MAX;
* @return QD_ERROR_PYTHON or QD_ERROR_NONE.
*/
qd_error_t qd_error_py();
+
#endif
Modified: qpid/dispatch/trunk/router/src/main.c
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/router/src/main.c?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/router/src/main.c (original)
+++ qpid/dispatch/trunk/router/src/main.c Fri Jun 13 19:08:05 2014
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -26,7 +26,8 @@
#include "config.h"
static int exit_with_sigint = 0;
-static qd_dispatch_t *dispatch;
+static qd_dispatch_t *dispatch = 0;
+static qd_log_source_t *log_source = 0;
static const char *app_config =
"from qpid_dispatch_internal.config.schema import config_schema\n"
@@ -89,6 +90,12 @@ static void server_signal_handler(void*
qd_server_resume(dispatch);
}
+static void check() {
+ if (qd_error_code()) {
+ qd_log(log_source, QD_LOG_CRITICAL, "Router start-up failed: %s",
qd_error_message());
+ exit(1);
+ }
+}
int main(int argc, char **argv)
{
@@ -132,14 +139,23 @@ int main(int argc, char **argv)
}
+ qd_error_clear();
dispatch = qd_dispatch(python_pkgdir);
qd_dispatch_extend_config_schema(dispatch, app_config);
+ log_source = qd_log_source("MAIN"); /* Logging is initialized by
qd_dispatch. */
+ check();
qd_dispatch_load_config(dispatch, config_path);
+ check();
qd_log_configure(dispatch);
+ check();
qd_dispatch_configure_container(dispatch);
+ check();
qd_dispatch_configure_router(dispatch);
+ check();
qd_dispatch_prepare(dispatch);
+ check();
qd_dispatch_post_configure_connections(dispatch);
+ check();
qd_server_set_signal_handler(dispatch, server_signal_handler, 0);
qd_server_set_start_handler(dispatch, thread_start_handler, 0);
@@ -159,4 +175,3 @@ int main(int argc, char **argv)
return 0;
}
-
Modified: qpid/dispatch/trunk/src/config.c
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/config.c?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/config.c (original)
+++ qpid/dispatch/trunk/src/config.c Fri Jun 13 19:08:05 2014
@@ -93,23 +93,22 @@ qd_config_t *qd_config(void)
}
-void qd_config_read(qd_config_t *config, const char *filepath)
+qd_error_t qd_config_read(qd_config_t *config, const char *filepath)
{
+ qd_error_clear();
PyObject *pMethod;
PyObject *pPath;
PyObject *pArgs;
PyObject *pResult;
if (!config)
- return;
+ return qd_error(QD_ERROR_CONFIG, "No configuration object");
pMethod = PyObject_GetAttrString(config->pObject, "read_file");
if (!pMethod || !PyCallable_Check(pMethod)) {
- qd_log(log_source, QD_LOG_ERROR, "Problem with configuration module:
No callable 'read_file'");
- if (pMethod) {
- Py_DECREF(pMethod);
- }
- return;
+ Py_XDECREF(pMethod);
+ qd_error_py();
+ return qd_error(QD_ERROR_CONFIG, "No callable 'read_file'");
}
pArgs = PyTuple_New(1);
@@ -120,11 +119,10 @@ void qd_config_read(qd_config_t *config,
if (pResult) {
Py_DECREF(pResult);
} else {
- qd_error_py();
- qd_log(log_source, QD_LOG_CRITICAL, "Configuration Failed, Exiting");
- exit(1);
+ return qd_error_py();
}
Py_DECREF(pMethod);
+ return QD_ERROR_NONE;
}
Modified: qpid/dispatch/trunk/src/config_private.h
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/config_private.h?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/config_private.h (original)
+++ qpid/dispatch/trunk/src/config_private.h Fri Jun 13 19:08:05 2014
@@ -20,12 +20,13 @@
*/
#include <qpid/dispatch/config.h>
+#include <qpid/dispatch/error.h>
#include "dispatch_private.h"
void qd_config_initialize(void);
void qd_config_finalize(void);
qd_config_t *qd_config(void);
-void qd_config_read(qd_config_t *config, const char *filename);
+qd_error_t qd_config_read(qd_config_t *config, const char *filename);
void qd_config_extend(qd_config_t *config, const char *text);
void qd_config_free(qd_config_t *config);
Modified: qpid/dispatch/trunk/src/dispatch.c
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/dispatch.c?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/dispatch.c (original)
+++ qpid/dispatch/trunk/src/dispatch.c Fri Jun 13 19:08:05 2014
@@ -54,7 +54,7 @@ qd_dispatch_t *qd_dispatch(const char *p
memset(qd, 0, sizeof(qd_dispatch_t));
- // alloc and log has to be initialized before any module.
+ // alloc, log and error have to be initialized before any module.
qd_alloc_initialize();
qd_log_initialize();
qd_error_initialize();
@@ -78,9 +78,9 @@ void qd_dispatch_extend_config_schema(qd
}
-void qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path)
+qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path)
{
- qd_config_read(qd->config, config_path);
+ return qd_config_read(qd->config, config_path);
}
Modified: qpid/dispatch/trunk/src/error.c
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/error.c?rev=1602492&r1=1602491&r2=1602492&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/error.c (original)
+++ qpid/dispatch/trunk/src/error.c Fri Jun 13 19:08:05 2014
@@ -31,15 +31,21 @@ static const char *error_names[] = {
"Already exists",
"Allocation",
"Invalid message",
- "Python"
+ "Python",
+ "Configuration"
};
STATIC_ASSERT(sizeof(error_names)/sizeof(error_names[0]) == QD_ERROR_COUNT,
error_names_wrong_size);
#define ERROR_MAX QD_LOG_TEXT_MAX
const int QD_ERROR_MAX = ERROR_MAX;
-static __thread char error_message[ERROR_MAX];
-static __thread qd_error_t error_code = 0;
+
+/* Thread local data. */
+static __thread struct {
+ char error_message[ERROR_MAX];
+ qd_error_t error_code;
+} ts = {{0}, 0};
+
static qd_log_source_t* log_source = 0;
void qd_error_initialize() {
@@ -47,16 +53,16 @@ void qd_error_initialize() {
}
qd_error_t qd_error(qd_error_t code, const char *fmt, ...) {
- error_code = code;
+ ts.error_code = code;
if (code) {
int i = 0;
if (code < QD_ERROR_COUNT)
- i = snprintf(error_message, ERROR_MAX,"%s: ", error_names[code]);
+ i = snprintf(ts.error_message, ERROR_MAX,"%s: ", error_names[code]);
else
- i = snprintf(error_message, ERROR_MAX, "%d: ", code);
+ i = snprintf(ts.error_message, ERROR_MAX, "%d: ", code);
va_list arglist;
va_start(arglist, fmt);
- vsnprintf(error_message+i, ERROR_MAX-i, fmt, arglist);
+ vsnprintf(ts.error_message+i, ERROR_MAX-i, fmt, arglist);
va_end(arglist);
qd_log(log_source, QD_LOG_ERROR, "%s", qd_error_message());
return code;
@@ -67,16 +73,16 @@ qd_error_t qd_error(qd_error_t code, con
}
void qd_error_clear() {
- error_code = 0;
- error_message[0] = '\0';
+ ts.error_code = 0;
+ snprintf(ts.error_message, ERROR_MAX, "No Error");
}
const char* qd_error_message() {
- return error_message;
+ return ts.error_message;
}
qd_error_t qd_error_code() {
- return error_code;
+ return ts.error_code;
}
static void py_set_item(PyObject *dict, const char* name, PyObject *value) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]