---
src/cmake/modules/FindQPID.cmake | 5 +++--
src/include/matahari/mh_agent.h | 9 +++++++++
src/include/matahari/utilities.h | 4 ++++
src/lib/CMakeLists.txt | 2 +-
src/lib/mh_agent.cpp | 30 ++++++++++++++++++++----------
src/lib/mh_agent_config.c | 5 +++--
src/lib/services_windows.c | 28 ++++++++--------------------
src/lib/utilities.c | 15 +++++++++++++++
8 files changed, 63 insertions(+), 35 deletions(-)
diff --git a/src/cmake/modules/FindQPID.cmake b/src/cmake/modules/FindQPID.cmake
index 5fd6f10..9179dc6 100644
--- a/src/cmake/modules/FindQPID.cmake
+++ b/src/cmake/modules/FindQPID.cmake
@@ -6,11 +6,12 @@ if(MSVC)
find_library(QMFCONSOLE_LIBRARY qmfconsole.lib "${QPID_PATH}")
find_library(QPIDCLIENT_LIBRARY qpidclient.lib "${QPID_PATH}")
find_library(QPIDCOMMON_LIBRARY qpidcommon.lib "${QPID_PATH}")
- find_library(QPIDCOMMON_LIBRARY qpidtypes.lib "${QPID_PATH}")
+ find_library(QPIDTYPES_LIBRARY qpidtypes.lib "${QPID_PATH}")
+ find_library(QPIDMESSAGING_LIBRARY qpidmessaging.lib "${QPID_PATH}")
# Figure out some way to do this automatically on windows
# Perhaps with the strings command
- set(QPID_VERSION_LONG "qpidd (qpidc) version 0.6")
+ set(QPID_VERSION_LONG "qpidd (qpidc) version 0.10")
else(MSVC)
find_library(QMF_LIBRARY qmf)
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 7cc902d..5b6c8a3 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -37,6 +37,12 @@
extern "C" {
#include "matahari/mainloop.h"
+#ifdef WIN32
+int no_argument = 0;
+int required_argument = 1;
+#else
+# include <getopt.h>
+#endif
}
#define MH_NOT_IMPLEMENTED "Not implemented"
@@ -61,6 +67,9 @@ extern int mh_add_option(
int code, int has_arg, const char *name, const char *description,
void *userdata, int(*callback)(int code, const char *name, const char *arg, void
*userdata));
+extern string mh_parse_options(
+ const char *proc_name, int argc, char **argv, qpid::types::Variant::Map
&options);
+
extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
gpointer userdata),
diff --git a/src/include/matahari/utilities.h b/src/include/matahari/utilities.h
index 60c5856..127f298 100644
--- a/src/include/matahari/utilities.h
+++ b/src/include/matahari/utilities.h
@@ -36,6 +36,10 @@ extern const char *mh_hostname(void);
extern void mh_abort(const char *file, const char *function, int line,
const char *assert_condition, int do_core, int do_fork);
+#ifdef WIN32
+extern wchar_t *char2wide(const char *str);
+#endif
+
#ifndef HAVE_ASPRINTF
/**
* Custom implementation of asprintf()
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 9c8369c..9854b19 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -40,7 +40,7 @@ endif(WIN32)
if(WITH-QMF)
add_library (mcommon_qmf SHARED mh_agent.cpp)
- target_link_libraries(mcommon_qmf ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY}
${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ target_link_libraries(mcommon_qmf mcommon ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY}
${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY} ${QPIDTYPES_LIBRARY})
set_target_properties(mcommon_qmf PROPERTIES SOVERSION 1.0.0)
if(WIN32)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index b842f86..90b40d5 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -20,7 +20,6 @@
#include <windows.h>
int use_stderr = 1;
#else
-#include <getopt.h>
int use_stderr = 0;
#endif
@@ -50,6 +49,8 @@ using namespace qpid::management;
using namespace qpid::client;
using namespace std;
+int print_help(int code, const char *name, const char *arg, void *userdata);
+
void
shutdown(int /*signal*/)
{
@@ -151,7 +152,7 @@ connection_option(int code, const char *name, const char *arg, void
*userdata)
return 0;
}
-static int print_help(int code, const char *name, const char *arg, void *userdata)
+int print_help(int code, const char *name, const char *arg, void *userdata)
{
int lpc = 0;
printf("Usage:\tmatahari-%sd <options>\n", (char *)userdata);
@@ -181,12 +182,11 @@ static int print_help(int code, const char *name, const char *arg,
void *userdat
}
string
-mh_parse_connection_options(const char *proc_name, int argc, char **argv,
qpid::types::Variant::Map &options)
+mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Variant::Map
&options)
{
std::stringstream url;
int arg;
- int idx = 0;
int serverport = MATAHARI_PORT;
char *servername = NULL;
@@ -194,6 +194,7 @@ mh_parse_connection_options(const char *proc_name, int argc, char
**argv, qpid::
const char *ssl_cert_db = NULL;
const char *ssl_cert_name = NULL;
const char *ssl_cert_password_file = NULL;
+ int lpc = 0;
options["reconnect"] = true;
@@ -232,17 +233,20 @@ mh_parse_connection_options(const char *proc_name, int argc, char
**argv, qpid::
for (lpc = 0; lpc < MAX_CHAR; lpc++) {
if (matahari_options[lpc].callback) {
+ wchar_t *name_ws = char2wide(matahari_options[lpc].long_name);
if (RegistryRead (HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- matahari_options[arg].long_name, &value) == 0) {
- matahari_options[arg].callback(
- matahari_options[arg].code, matahari_options[arg].long_name,
+ name_ws, &value) == 0) {
+ matahari_options[lpc].callback(
+ matahari_options[lpc].code, matahari_options[lpc].long_name,
value, matahari_options[lpc].userdata);
+ }
+ free(name_ws);
}
}
#else
- int lpc = 0;
+ int idx = 0;
int num_options = 0;
int opt_string_len = 0;
char opt_string[2*MAX_CHAR];
@@ -362,6 +366,10 @@ mh_add_option(int code, int has_arg, const char *name, const char
*description,
void *userdata, int(*callback)(int code, const char *name, const char *arg, void
*userdata))
{
if(code > 0 && code < MAX_CHAR) {
+ if(matahari_options[code].code != 0) {
+ mh_err("Replacing '-%c|--%s' with '-%c|--%s'",
+ matahari_options[code].code, matahari_options[code].long_name, code, name);
+ }
matahari_options[code].code = code;
matahari_options[code].has_arg = has_arg;
matahari_options[code].long_name = name;
@@ -375,10 +383,12 @@ mh_add_option(int code, int has_arg, const char *name, const char
*description,
static int should_daemonize(int code, const char *name, const char *arg, void *userdata)
{
+#ifndef WIN32
if (daemon(0, 0) < 0) {
fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
exit(1);
}
+#endif
return 0;
}
@@ -389,10 +399,10 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
int res = 0;
/* Set up basic logging */
- mh_log_init(proc_name, LOG_TRACE, TRUE);
+ mh_log_init(proc_name, LOG_INFO, TRUE);
mh_add_option('d', no_argument, "daemon", "run as a
daemon", NULL, should_daemonize);
- string url = mh_parse_connection_options(proc_name, argc, argv, options);
+ string url = mh_parse_options(proc_name, argc, argv, options);
cout << options << endl;
diff --git a/src/lib/mh_agent_config.c b/src/lib/mh_agent_config.c
index 9a73707..7102f61 100644
--- a/src/lib/mh_agent_config.c
+++ b/src/lib/mh_agent_config.c
@@ -18,14 +18,15 @@
#ifndef WIN32
#include "config.h"
+#include <stddef.h>
#endif
#include <stdint.h>
#include <stdio.h>
-#include <stddef.h>
#include <glib.h>
-#include "matahari/mh_agent_config.h"
#include "matahari/logging.h"
+#include "matahari/mh_agent_config.h"
+
MH_TRACE_INIT_DATA(mh_config);
diff --git a/src/lib/services_windows.c b/src/lib/services_windows.c
index b3f43e5..80b9a39 100644
--- a/src/lib/services_windows.c
+++ b/src/lib/services_windows.c
@@ -27,18 +27,6 @@
/* Some code adapted from
http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
*/
-static wchar_t *
-char2wide(const char *str)
-{
- wchar_t *result = NULL;
- if (str != NULL) {
- size_t str_size = strlen(str) + 1;
- result = malloc(str_size * sizeof(wchar_t));
- mbstowcs(result, str, str_size);
- }
- return result;
-}
-
static void
create_service_key(const wchar_t *template, wchar_t *buffer, int size,
char *name)
@@ -121,7 +109,7 @@ static int
extract_service_status(const char *unmutable, int max)
{
int lpc = 0, last = 0;
- int rc = LSB_STATUS_UNKNOWN_ERROR;
+ int rc = LSB_STATUS_OTHER_ERROR;
if (unmutable == NULL || max < 10) {
return rc;
@@ -255,7 +243,7 @@ services_os_action_execute(svc_action_t *op, gboolean synchronous)
}
if (status == STILL_ACTIVE) {
- op->rc = LSB_UNKNOWN_ERROR;
+ op->rc = LSB_OTHER_ERROR;
op->status = LRM_OP_TIMEOUT;
TerminateProcess(piProcInfo.hProcess, 1);
mh_err("Operation for %s timeout out after %dms", op->id,
op->timeout);
@@ -276,7 +264,7 @@ services_os_action_execute(svc_action_t *op, gboolean synchronous)
} else {
op->status = LRM_OP_ERROR;
- op->rc = LSB_UNKNOWN_ERROR;
+ op->rc = LSB_OTHER_ERROR;
mh_info("Result of '%ls' for '%s' was %d", exec_w,
op->id, (int)status);
}
@@ -307,17 +295,17 @@ services_os_action_execute(svc_action_t *op, gboolean synchronous)
CloseHandle(piProcInfo.hThread);
CloseHandle(child_pipe_rd);
- if (is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
- op->rc = LSB_STATUS_UNKNOWN_ERROR;
+ if (is_status_op && op->rc == LSB_OTHER_ERROR) {
+ op->rc = LSB_STATUS_OTHER_ERROR;
}
return TRUE;
fail:
op->status = LRM_OP_ERROR;
- op->rc = LSB_UNKNOWN_ERROR;
- if (is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
- op->rc = LSB_STATUS_UNKNOWN_ERROR;
+ op->rc = LSB_OTHER_ERROR;
+ if (is_status_op && op->rc == LSB_OTHER_ERROR) {
+ op->rc = LSB_STATUS_OTHER_ERROR;
}
return FALSE;
}
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index 57929a2..66a649b 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -405,6 +405,21 @@ mh_uuid(void)
return uuid;
}
+#ifdef WIN32
+wchar_t *
+char2wide(const char *str)
+{
+ wchar_t *result = NULL;
+ if (str != NULL) {
+ size_t str_size = strlen(str) + 1;
+ result = malloc(str_size * sizeof(wchar_t));
+ mbstowcs(result, str, str_size);
+ }
+ return result;
+}
+#endif
+
+
#ifndef HAVE_ASPRINTF
int
asprintf(char **ret, const char *fmt, ...)
--
1.7.5.1