[PATCH 1/5] - Config filter updated - Add additional query to check for _product == Config - Due to the fact we are connecting one agent of type 'Config' we can remove the conditional checks and work with the connecting agent.
by Adam Stokes
From: Adam Stokes <astokes(a)fedoraproject.org>
---
src/config/config-console.cpp | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/config/config-console.cpp b/src/config/config-console.cpp
index 74612ef..188c443 100644
--- a/src/config/config-console.cpp
+++ b/src/config/config-console.cpp
@@ -53,10 +53,10 @@ int main(int argc, char** argv)
connection.open();
ConsoleSession session(connection, sessionOptions);
+ // Only filter connecting agents under matahariproject.org vendor and Config product
+ session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Config']]]");
session.open();
-
- // Only filter connecting agents under matahariproject.org vendor
- session.setAgentFilter("[eq, _vendor, [quote, 'matahariproject.org']]]");
+
Agent agent;
while (true) {
ConsoleEvent event;
@@ -64,14 +64,11 @@ int main(int argc, char** argv)
switch(event.getType()) {
case CONSOLE_AGENT_ADD:
{
- if (session.getAgentCount() == 1) {
- agent = session.getAgent(0);
- DataAddr agent_event_addr("config", agent.getName(), 0);
- cout << "callMethod:configure : " << dataProperties << endl;
- ConsoleEvent result(agent.callMethod("configure",
- dataProperties,
- agent_event_addr));
- }
+ agent = event.getAgent();
+ DataAddr agent_event_addr("config", agent.getName(), 0);
+ ConsoleEvent result(agent.callMethod("configure",
+ dataProperties,
+ agent_event_addr));
}
break;
default: {}
--
1.7.4.4
12 years, 11 months
[PATCH] Build: Add tags target to .PHONY.
by russell@russellbryant.net
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
GNUmakefile | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index 399b2a0..995671e 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -154,4 +154,4 @@ endif
@sed -i -e 's/###MATAHARI_VERSION###/$(VERSION)/' doc/Doxyfile
@doxygen doc/Doxyfile
-.PHONY: check linux.build windows.build clean doxygen
+.PHONY: check linux.build windows.build clean doxygen tags
--
1.7.5.1
12 years, 11 months
[PATCH] - Network/Host api test cases
by Adam Stokes
- Finished up network/host api testing
- Alter makefile to force ctest if test configuration exists during a build
- Remove stale network_unittest file
- Move cxxtest routine into src/tests directory
- Fixed up tab/space indentation on a few routines
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
GNUmakefile | 3 +
src/CMakeLists.txt | 8 ----
src/tests/CMakeLists.txt | 4 +-
src/tests/mh_api_host.h | 70 +++++++++++++++++++++++++++++++---
src/tests/mh_api_network.h | 43 ++++++++++++---------
src/tests/mh_api_network_unittest.h | 47 -----------------------
src/tests/mh_test_utilities.c | 5 +-
src/tests/mh_test_utilities.h | 10 ++++-
9 files changed, 107 insertions(+), 88 deletions(-)
delete mode 100644 src/tests/mh_api_network_unittest.h
diff --git a/GNUmakefile b/GNUmakefile
index 399b2a0..93bcc46 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -41,6 +41,9 @@ linux.build:
mkdir -p $@
cd $@ && eval "`rpm --eval "%{cmake}" | grep -v -e "^%"`" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
@$(MAKE) --no-print-dir -C $@
+ @if [ -f $(a)/src/tests/CTestTestfile.cmake ]; then \
+ cd $@/src/tests && ctest; \
+ fi
windows.build:
@echo "=::=::=::= Setting up for Windows =::=::=::= "
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 949708f..1dfd143 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,5 @@
#set(CMAKE_VERBOSE_MAKEFILE ON)
-find_package(CxxTest)
-if(CXXTEST_FOUND)
- include_directories(${CXXTEST_INCLUDE_DIR})
- ENABLE_TESTING()
- CXXTEST_ADD_TEST(mh_api_network_unittest mh_api_network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/mh_api_network.h)
- target_link_libraries(mh_api_network_unittest mh_api_network_unittest)
-endif(CXXTEST_FOUND)
-
if(WIN32)
set(VARIANT "windows")
set(SUPPORT_TRACING 0)
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index e5b02e6..17e3cac 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -6,12 +6,12 @@ if(CXXTEST_FOUND)
CXXTEST_ADD_TEST(mh_api_network_unittest mh_api_network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_network.h)
target_link_libraries(mh_api_network_unittest mnetwork)
CXXTEST_ADD_TEST(mh_api_host_unittest mh_api_host_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_host.h)
- add_library(mh_tester SHARED mh_test_utilities.c)
+ add_library(mh_tester SHARED mh_test_utilities.c ../lib/utilities.c)
target_link_libraries(mh_api_network_unittest mnetwork mh_tester)
target_link_libraries(mh_api_host_unittest mhost pcre mh_tester)
- message(STATUS "Testing Found.")
endif(CXXTEST_FOUND)
file(GLOB SRCS "*.cpp")
file(GLOB HEADERS "*.h")
install(FILES ${SRCS} ${HEADERS} DESTINATION share/matahari/tests)
+
diff --git a/src/tests/mh_api_host.h b/src/tests/mh_api_host.h
index f3a6387..710d42d 100644
--- a/src/tests/mh_api_host.h
+++ b/src/tests/mh_api_host.h
@@ -57,8 +57,8 @@ class MhApiHostSuite : public CxxTest::TestSuite
{
infomsg << "Verify " << mh_host_get_hostname() << " format";
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("^([0-9a-zA-Z]+([\\.]|$)){2,3}$",
- mh_host_get_hostname())) >= 0);
+ TS_ASSERT((mh_test_is_match("^([0-9a-zA-Z]+([\\.]|$)){2,3}$",
+ mh_host_get_hostname())) >= 0);
infomsg.str("");
}
@@ -66,7 +66,7 @@ class MhApiHostSuite : public CxxTest::TestSuite
{
infomsg << "Verify " << mh_host_get_uuid() << " exists";
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("^[0-9a-zA-Z]+$", mh_host_get_uuid())) >= 0);
+ TS_ASSERT((mh_test_is_match("^[0-9a-zA-Z]+$", mh_host_get_uuid())) >= 0);
infomsg.str("");
}
@@ -74,7 +74,7 @@ class MhApiHostSuite : public CxxTest::TestSuite
{
infomsg << "Verify OS : " << mh_host_get_operating_system();
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("^Linux.*|Windows.*|Solaris.*$",
+ TS_ASSERT((mh_test_is_match("^Linux.*|Windows.*|Solaris.*$",
mh_host_get_operating_system())) >= 0);
infomsg.str("");
}
@@ -84,7 +84,7 @@ class MhApiHostSuite : public CxxTest::TestSuite
infomsg << "Verify architecture property: " \
<< mh_host_get_architecture();
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("^[0-9a-zA-Z_]+$",
+ TS_ASSERT((mh_test_is_match("^[0-9a-zA-Z_]+$",
mh_host_get_architecture())) >= 0);
infomsg.str("");
}
@@ -93,7 +93,7 @@ class MhApiHostSuite : public CxxTest::TestSuite
{
infomsg << "Verify cpu model: " << mh_host_get_cpu_model();
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("\\sCPU\\s", mh_host_get_cpu_model())) >= 0);
+ TS_ASSERT((mh_test_is_match("\\sCPU\\s", mh_host_get_cpu_model())) >= 0);
infomsg.str("");
}
@@ -101,7 +101,63 @@ class MhApiHostSuite : public CxxTest::TestSuite
{
infomsg << "Verify cpu flags: " << mh_host_get_cpu_flags();
TS_TRACE(infomsg.str());
- TS_ASSERT((is_match("\\d+", mh_host_get_cpu_flags())) >= 0);
+ TS_ASSERT((mh_test_is_match("\\d+", mh_host_get_cpu_flags())) >= 0);
+ infomsg.str("");
+ }
+
+ void testCpuCount(void)
+ {
+ infomsg << "Verify cpu count: " << mh_host_get_cpu_count();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_cpu_count()) > 0);
+ infomsg.str("");
+ }
+
+ void testCpuNumberOfCores(void)
+ {
+ infomsg << "Verify cpu num of cores: " << mh_host_get_cpu_number_of_cores();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_cpu_number_of_cores()) > 0);
+ infomsg.str("");
+ }
+
+ void testCpuWordSize(void)
+ {
+ infomsg << "Verify cpu wordsize: " << mh_host_get_cpu_wordsize();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_cpu_wordsize()) > 0);
+ infomsg.str("");
+ }
+
+ void testMemory(void)
+ {
+ infomsg << "Verify memory exist: " << mh_host_get_memory();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_memory()) > 0);
+ infomsg.str("");
+ }
+
+ void testMemoryFree(void)
+ {
+ infomsg << "Verify memory free: " << mh_host_get_mem_free();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_mem_free()) > 0);
+ infomsg.str("");
+ }
+
+ void testSwap(void)
+ {
+ infomsg << "Verify swap exists: " << mh_host_get_swap();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_swap()) > 0);
+ infomsg.str("");
+ }
+
+ void testSwapFree(void)
+ {
+ infomsg << "Verify swap free: " << mh_host_get_swap_free();
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_host_get_swap_free()) > 0);
infomsg.str("");
}
diff --git a/src/tests/mh_api_network.h b/src/tests/mh_api_network.h
index 1b2b629..908c5ee 100644
--- a/src/tests/mh_api_network.h
+++ b/src/tests/mh_api_network.h
@@ -2,6 +2,7 @@
#define __MH_API_NETWORK_UNITTEST_H
#include <iostream>
#include <string>
+#include <sstream>
#include <utility>
#include <vector>
#include <cstdlib>
@@ -28,6 +29,7 @@ class MhApiNetworkSuite : public CxxTest::TestSuite
GList *interface_list;
sigar_net_interface_config_t *ifconfig;
vector<char*> iface_names;
+ std::stringstream infomsg;
void init()
{
@@ -42,38 +44,43 @@ class MhApiNetworkSuite : public CxxTest::TestSuite
void testListNetworkDevices(void)
{
- unsigned int i;
-
/* only initialize on first test in suite */
init();
-
- for(i=0; i<iface_names.size(); i++) {
- TS_TRACE(iface_names[i]);
- TS_ASSERT(iface_names[i]);
+
+ for(std::vector<char *>::iterator it = iface_names.begin();
+ it != iface_names.end(); ++it) {
+ infomsg << "Checking for available interfaces: " << *it;
+ TS_TRACE(infomsg.str());
+ TS_ASSERT(*it);
+ infomsg.str("");
}
}
void testGetNetworkIP(void)
{
- unsigned int i;
const char *ip = NULL;
- for(i=0; i<iface_names.size(); i++) {
- ip = mh_network_get_ip_address(iface_names[i]);
- TS_TRACE(ip);
- TS_ASSERT((is_match("^\\d+\\.\\d+\\.\\d+\\.\\d+",
- ip)) >= 0);
+ for(std::vector<char *>::iterator it = iface_names.begin();
+ it != iface_names.end(); ++it) {
+ ip = mh_network_get_ip_address(*it);
+ infomsg << "Verify IP address format: " << ip;
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_test_is_match("^\\d+\\.\\d+\\.\\d+\\.\\d+",
+ ip)) >= 0);
+ infomsg.str("");
}
}
void testGetNetworkMAC(void)
{
- unsigned int i;
const char *mac = NULL;
- for(i=0; i<iface_names.size(); i++) {
- mac = mh_network_get_mac_address(iface_names[i]);
- TS_TRACE(mac);
- TS_ASSERT((is_match("^([0-9a-fA-F]{2}([:-]|$)){6}$",
- mac)) >= 0);
+ for(std::vector<char *>::iterator it = iface_names.begin();
+ it != iface_names.end(); ++it) {
+ mac = mh_network_get_mac_address(*it);
+ infomsg << "Verify MAC address format: " << mac;
+ TS_TRACE(infomsg.str());
+ TS_ASSERT((mh_test_is_match("^([0-9a-fA-F]{2}([:-]|$)){6}$",
+ mac)) >= 0);
+ infomsg.str("");
}
}
};
diff --git a/src/tests/mh_api_network_unittest.h b/src/tests/mh_api_network_unittest.h
deleted file mode 100644
index 9e69462..0000000
--- a/src/tests/mh_api_network_unittest.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef __MH_API_NETWORK_UNITTEST_H
-#define __MH_API_NETWORK_UNITTEST_H
-#include <iostream>
-#include <string>
-#include <utility>
-#include <vector>
-#include <cstdlib>
-#include <cstdio>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <cxxtest/TestSuite.h>
-
-extern "C" {
-#include "matahari/network.h"
-#include "matahari/host.h"
-#include <sigar.h>
-#include <sigar_format.h>
-#include <glib.h>
-};
-
-using namespace std;
-
-class MhApiNetworkSuite : public CxxTest::TestSuite
-{
- public:
- void setUp (void)
- {
- // will be setup
- }
-
- void tearDown (void)
- {
- // teardown
-
- }
-
- void testListNetworkDevices(void)
- {
- GList *plist = NULL;
- GList *interface_list = NULL;
-
- interface_list = mh_network_get_interfaces();
- TS_ASSERT (!interface_list.empty());
- }
-};
-
-#endif
diff --git a/src/tests/mh_test_utilities.c b/src/tests/mh_test_utilities.c
index 1c3456d..dffd23e 100644
--- a/src/tests/mh_test_utilities.c
+++ b/src/tests/mh_test_utilities.c
@@ -21,13 +21,14 @@
*/
#include "mh_test_utilities.h"
+#include "matahari/utilities.h"
#include <pcre.h>
#include <string.h>
#define OVECCOUNT 30
int
-is_match(const char *pattern, const char *subject)
+mh_test_is_match(const char *pattern, const char *subject)
{
int erroroffset;
int ovector[OVECCOUNT];
@@ -52,7 +53,7 @@ is_match(const char *pattern, const char *subject)
0,
0,
ovector,
- OVECCOUNT);
+ DIMOF(ovector));
/* Since we only care about return code for now free the regex */
pcre_free(re);
diff --git a/src/tests/mh_test_utilities.h b/src/tests/mh_test_utilities.h
index f75df05..4b1b4a4 100644
--- a/src/tests/mh_test_utilities.h
+++ b/src/tests/mh_test_utilities.h
@@ -23,6 +23,14 @@
#ifndef __MH_TEST_UTILITIES_H
#define __MH_TEST_UTILITIES_H
-extern int is_match(const char *pattern, const char *subject);
+/**
+ * Regex match against specific pattern
+ *
+ * \param[in] pattern perl regular expression pattern
+ * \param[in] subject content used to match against
+ *
+ * \return 0 or greater for successful match
+ */
+extern int mh_test_is_match(const char *pattern, const char *subject);
#endif /* __MH_TEST_UTILITIES */
--
1.7.5.1
12 years, 11 months
[PATCH] Fix mixed tab/space indentation.
by russell@russellbryant.net
Some recent changes introduced some lines that mixed the usage of tabs
and spaces for indentation. This fixes that, at least in a couple of
files.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/mh_agent.cpp | 234 +++++++++++++++++++++---------------------
src/service/service-qmf.cpp | 96 +++++++++---------
2 files changed, 165 insertions(+), 165 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index b842f86..cdd383d 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -75,7 +75,7 @@ RegistryRead(
if (lSuccess != ERROR_SUCCESS) {
mh_debug("Could not open %ls key from the registry: %ld",
- szKeyPath, lSuccess);
+ szKeyPath, lSuccess);
return -1;
}
@@ -83,7 +83,7 @@ RegistryRead(
&nSize);
if (lSuccess != ERROR_SUCCESS) {
mh_debug("Could not read '%ls[%ls]' from the registry: %ld",
- szKeyPath, szValue, lSuccess);
+ szKeyPath, szValue, lSuccess);
return -1;
}
mh_info("Obtained '%ls[%ls]' = '%ls' from the registry", szKeyPath, szValue,
@@ -119,12 +119,12 @@ mh_qpid_disconnect(gpointer user_data)
typedef struct mh_opt_s
{
- int code;
- int has_arg;
- const char *long_name;
- const char *description;
- void *userdata;
- int (*callback)(int code, const char *name, const char *arg, void *userdata);
+ int code;
+ int has_arg;
+ const char *long_name;
+ const char *description;
+ void *userdata;
+ int (*callback)(int code, const char *name, const char *arg, void *userdata);
} mh_option;
@@ -137,16 +137,16 @@ connection_option(int code, const char *name, const char *arg, void *userdata)
qpid::types::Variant::Map *options = static_cast<qpid::types::Variant::Map*>(userdata);
if(strcmp(name, "service") == 0) {
- options->insert(std::pair<std::string, qpid::types::Variant>("sasl-service", arg));
- options->insert(std::pair<std::string, qpid::types::Variant>("sasl-mechanism", "GSSAPI"));
-
+ options->insert(std::pair<std::string, qpid::types::Variant>("sasl-service", arg));
+ options->insert(std::pair<std::string, qpid::types::Variant>("sasl-mechanism", "GSSAPI"));
+
} else if(strcmp(name, "reconnect") == 0) {
- if(arg && strcmp(arg, "no") == 0) {
- options->insert(std::pair<std::string, qpid::types::Variant>("reconnect", false));
- }
-
+ if(arg && strcmp(arg, "no") == 0) {
+ options->insert(std::pair<std::string, qpid::types::Variant>("reconnect", false));
+ }
+
} else {
- options->insert(std::pair<std::string, qpid::types::Variant>(name, arg));
+ options->insert(std::pair<std::string, qpid::types::Variant>(name, arg));
}
return 0;
}
@@ -156,7 +156,7 @@ static int print_help(int code, const char *name, const char *arg, void *userdat
int lpc = 0;
printf("Usage:\tmatahari-%sd <options>\n", (char *)userdata);
printf("\nCommon options:\n");
- printf("\t-h | --help print this help message.\n");
+ printf("\t-h | --help print this help message.\n");
printf("\t-b | --broker value specify broker host name..\n");
printf("\t-p | --port value specify broker port.\n");
printf("\t-u | --username value username to use for authentication purproses.\n");
@@ -171,11 +171,11 @@ static int print_help(int code, const char *name, const char *arg, void *userdat
printf("\nCustom options:\n");
for(lpc = 0; lpc < MAX_CHAR; lpc++) {
- if(matahari_options[lpc].callback
- && matahari_options[lpc].callback != connection_option) {
- printf("\t-%c | --%s\t %s\n", matahari_options[lpc].code,
- matahari_options[lpc].long_name, matahari_options[lpc].description);
- }
+ if(matahari_options[lpc].callback
+ && matahari_options[lpc].callback != connection_option) {
+ printf("\t-%c | --%s\t %s\n", matahari_options[lpc].code,
+ matahari_options[lpc].long_name, matahari_options[lpc].description);
+ }
}
return 0;
}
@@ -198,11 +198,11 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
options["reconnect"] = true;
/* Force local-only handling */
- mh_add_option('b', required_argument, "broker", NULL, NULL, NULL);
- mh_add_option('p', required_argument, "port", NULL, NULL, NULL);
+ mh_add_option('b', required_argument, "broker", NULL, NULL, NULL);
+ mh_add_option('p', required_argument, "port", NULL, NULL, NULL);
#ifdef MH_SSL
- mh_add_option('N', required_argument, "ssl-cert-name", NULL, NULL, NULL);
- mh_add_option('C', required_argument, "ssl-cert-db", NULL, NULL, NULL);
+ mh_add_option('N', required_argument, "ssl-cert-name", NULL, NULL, NULL);
+ mh_add_option('C', required_argument, "ssl-cert-db", NULL, NULL, NULL);
mh_add_option('f', required_argument, "ssl-cert-password-file", NULL, NULL, NULL);
#endif
@@ -215,30 +215,30 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
char *value = NULL;
if (RegistryRead(HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"broker", &value) == 0) {
- free(servername);
- servername = value;
- value = NULL;
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"broker", &value) == 0) {
+ free(servername);
+ servername = value;
+ value = NULL;
}
if (RegistryRead(HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"port", &value) == 0) {
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"port", &value) == 0) {
serverport = atoi(value);
free(value);
value = NULL;
}
for (lpc = 0; lpc < MAX_CHAR; lpc++) {
- if (matahari_options[lpc].callback) {
- 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,
- value, matahari_options[lpc].userdata);
- }
+ if (matahari_options[lpc].callback) {
+ 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,
+ value, matahari_options[lpc].userdata);
+ }
}
#else
@@ -254,74 +254,74 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
opt_string[0] = 0;
for(lpc = 0; lpc < MAX_CHAR; lpc++) {
- if(matahari_options[lpc].code) {
- long_opts = (struct option *)realloc(long_opts, (2 + num_options) * sizeof(struct option));
- long_opts[num_options].name = matahari_options[lpc].long_name;
- long_opts[num_options].has_arg = matahari_options[lpc].has_arg;
- long_opts[num_options].flag = NULL;
- long_opts[num_options].val = matahari_options[lpc].code;
-
- num_options++;
-
- long_opts[num_options].name = 0;
- long_opts[num_options].has_arg = 0;
- long_opts[num_options].flag = 0;
- long_opts[num_options].val = 0;
-
- opt_string[opt_string_len++] = matahari_options[lpc].code;
- if(matahari_options[lpc].has_arg == required_argument) {
- opt_string[opt_string_len++] = ':';
- }
- opt_string[opt_string_len] = 0;
- }
+ if(matahari_options[lpc].code) {
+ long_opts = (struct option *)realloc(long_opts, (2 + num_options) * sizeof(struct option));
+ long_opts[num_options].name = matahari_options[lpc].long_name;
+ long_opts[num_options].has_arg = matahari_options[lpc].has_arg;
+ long_opts[num_options].flag = NULL;
+ long_opts[num_options].val = matahari_options[lpc].code;
+
+ num_options++;
+
+ long_opts[num_options].name = 0;
+ long_opts[num_options].has_arg = 0;
+ long_opts[num_options].flag = 0;
+ long_opts[num_options].val = 0;
+
+ opt_string[opt_string_len++] = matahari_options[lpc].code;
+ if(matahari_options[lpc].has_arg == required_argument) {
+ opt_string[opt_string_len++] = ':';
+ }
+ opt_string[opt_string_len] = 0;
+ }
}
while ((arg = getopt_long(argc, argv, opt_string, long_opts, &idx)) != -1) {
switch (arg) {
- case 'h':
- print_help('h', NULL, NULL, (void*)proc_name);
- exit(0);
- break;
- case 'v':
- mh_log_level++;
- mh_enable_stderr(1);
- break;
- case 'p':
- serverport = atoi(optarg);
- break;
- case 'b':
- servername = strdup(optarg);
- break;
- case 'N':
+ case 'h':
+ print_help('h', NULL, NULL, (void*)proc_name);
+ exit(0);
+ break;
+ case 'v':
+ mh_log_level++;
+ mh_enable_stderr(1);
+ break;
+ case 'p':
+ serverport = atoi(optarg);
+ break;
+ case 'b':
+ servername = strdup(optarg);
+ break;
+ case 'N':
ssl_cert_name = optarg;
- break;
- case 'C':
- ssl_cert_db = optarg;
- setenv("QPID_SSL_CERT_DB", optarg, 1);
- if (!g_file_test(ssl_cert_db, G_FILE_TEST_IS_DIR)) {
- fprintf(stderr, "SSL Certificate database is not accessible. See --help\n");
- exit(1);
- }
- break;
- case 'f':
- ssl_cert_password_file = optarg;
+ break;
+ case 'C':
+ ssl_cert_db = optarg;
+ setenv("QPID_SSL_CERT_DB", optarg, 1);
+ if (!g_file_test(ssl_cert_db, G_FILE_TEST_IS_DIR)) {
+ fprintf(stderr, "SSL Certificate database is not accessible. See --help\n");
+ exit(1);
+ }
+ break;
+ case 'f':
+ ssl_cert_password_file = optarg;
setenv("QPID_SSL_CERT_PASSWORD_FILE", optarg, 1);
- if (!g_file_test(ssl_cert_password_file, G_FILE_TEST_EXISTS)) {
- fprintf(stderr, "SSL Password file is not accessible. See --help.\n");
- exit(1);
- }
- break;
- default:
- if(arg > 0 && arg < MAX_CHAR && matahari_options[arg].callback) {
- matahari_options[arg].callback(
- matahari_options[arg].code, matahari_options[arg].long_name,
- optarg, matahari_options[arg].userdata);
-
- } else {
- print_help(arg, NULL, NULL, (void*)proc_name);
- exit(1);
- }
- break;
+ if (!g_file_test(ssl_cert_password_file, G_FILE_TEST_EXISTS)) {
+ fprintf(stderr, "SSL Password file is not accessible. See --help.\n");
+ exit(1);
+ }
+ break;
+ default:
+ if(arg > 0 && arg < MAX_CHAR && matahari_options[arg].callback) {
+ matahari_options[arg].callback(
+ matahari_options[arg].code, matahari_options[arg].long_name,
+ optarg, matahari_options[arg].userdata);
+
+ } else {
+ print_help(arg, NULL, NULL, (void*)proc_name);
+ exit(1);
+ }
+ break;
}
}
free(long_opts);
@@ -336,8 +336,8 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
qpid::sys::ssl::initNSS(ssl_options, true);
} else if (ssl_cert_name || ssl_cert_db || ssl_cert_password_file) {
- fprintf(stderr, "To enable SSL, you must supply a cert name, db and password file. See --help.\n");
- exit(1);
+ fprintf(stderr, "To enable SSL, you must supply a cert name, db and password file. See --help.\n");
+ exit(1);
}
#endif
@@ -348,7 +348,7 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
}
if(servername == NULL) {
- servername = strdup(MATAHARI_BROKER);
+ servername = strdup(MATAHARI_BROKER);
}
url << "amqp:" << protocol << ":" << servername << ":" << serverport ;
@@ -359,16 +359,16 @@ mh_parse_connection_options(const char *proc_name, int argc, char **argv, qpid::
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))
+ void *userdata, int(*callback)(int code, const char *name, const char *arg, void *userdata))
{
if(code > 0 && code < MAX_CHAR) {
- matahari_options[code].code = code;
- matahari_options[code].has_arg = has_arg;
- matahari_options[code].long_name = name;
- matahari_options[code].description = description;
- matahari_options[code].userdata = userdata;
- matahari_options[code].callback = callback;
- return 0;
+ matahari_options[code].code = code;
+ matahari_options[code].has_arg = has_arg;
+ matahari_options[code].long_name = name;
+ matahari_options[code].description = description;
+ matahari_options[code].userdata = userdata;
+ matahari_options[code].callback = callback;
+ return 0;
}
return -1;
}
@@ -376,8 +376,8 @@ 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)
{
if (daemon(0, 0) < 0) {
- fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
- exit(1);
+ fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
+ exit(1);
}
return 0;
}
@@ -417,7 +417,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
/* Do any setup required by our agent */
if (this->setup(_agent_session) < 0) {
mh_err("Failed to set up broker connection to %s for %s\n",
- url.c_str(), proc_name);
+ url.c_str(), proc_name);
res = -1;
goto return_cleanup;
}
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index 5467553..f22404e 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -114,22 +114,22 @@ AsyncCB::mh_async_callback(svc_action_t *op)
qpid::types::Variant::Map& args = cb_data->event.getArguments();
if (args.count("userdata") > 0) {
- userdata = args["userdata"].asString().c_str();
+ userdata = args["userdata"].asString().c_str();
}
if (cb_data->first_result) {
if (cb_data->has_rc) {
cb_data->event.addReturnArgument("rc", op->rc);
}
- if (userdata) {
- cb_data->event.addReturnArgument("userdata", userdata);
- }
+ if (userdata) {
+ cb_data->event.addReturnArgument("userdata", userdata);
+ }
cb_data->session.methodSuccess(cb_data->event);
cb_data->first_result = false;
} else if (cb_data->last_rc != op->rc) {
mh_trace("Result changed on recurring action: was '%d', now '%d'\n",
- cb_data->last_rc, op->rc);
+ cb_data->last_rc, op->rc);
cb_data->agent->raiseEvent(op, cb_data->service, userdata);
}
@@ -183,7 +183,7 @@ SrvAgent::raiseEvent(svc_action_t *op, enum service_id service, const char *user
if (service) {
// event = qmf::Data(_package.event_service_op);
- return;
+ return;
} else {
event = qmf::Data(_package.event_resource_op);
}
@@ -289,20 +289,20 @@ SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
} else if (methodName == "enable" || methodName == "disable") {
svc_action_t *op = services_action_create(
- args["name"].asString().c_str(), methodName.c_str(), 0,
- default_timeout_ms);
+ args["name"].asString().c_str(), methodName.c_str(), 0,
+ default_timeout_ms);
action_async(SRV_SERVICES, session, event, op, false);
- return TRUE;
+ return TRUE;
} else if (methodName == "start"
- || methodName == "stop"
- || methodName == "status") {
+ || methodName == "stop"
+ || methodName == "status") {
svc_action_t *op = services_action_create(
args["name"].asString().c_str(), methodName.c_str(), 0, args["timeout"].asInt32());
action_async(SRV_SERVICES, session, event, op, true);
- return TRUE;
+ return TRUE;
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
@@ -332,7 +332,7 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
GList *providers = NULL;
_qtype::Variant::List p_list;
- providers = resources_list_providers(args["standard"].asString().c_str());
+ providers = resources_list_providers(args["standard"].asString().c_str());
for (gIter = providers; gIter != NULL; gIter = gIter->next) {
p_list.push_back((const char *) gIter->data);
}
@@ -343,47 +343,47 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
GList *agents = NULL;
_qtype::Variant::List t_list;
- agents = resources_list_agents(
- args["standard"].asString().c_str(),
- args["provider"].asString().c_str());
-
+ agents = resources_list_agents(
+ args["standard"].asString().c_str(),
+ args["provider"].asString().c_str());
+
for (gIter = agents; gIter != NULL; gIter = gIter->next) {
t_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("types", t_list);
} else if (methodName == "invoke") {
- svc_action_t *op = NULL;
- bool valid_standard = false;
- _qtype::Variant::List::iterator iter;
- GHashTable *params = qmf_map_to_hash(args["parameters"].asMap());
-
- for ( iter=standards.begin() ; iter != standards.end(); iter++ ) {
- if(args["standard"].asString() == (*iter).asString()) {
- valid_standard = true;
- break;
- }
- }
-
- if(valid_standard == false) {
- mh_err("%s is not a known resource standard", args["standard"].asString().c_str());
- session.raiseException(event, MH_NOT_IMPLEMENTED);
- return TRUE;
- }
-
- op = resources_action_create(
- args["name"].asString().c_str(),
- args["standard"].asString().c_str(),
- args["provider"].asString().c_str(),
- args["type"].asString().c_str(),
- args["action"].asString().c_str(),
- args["interval"].asInt32(), args["timeout"].asInt32(), params);
-
- op->expected_rc = args["expected-rc"].asInt32();
-
- action_async(SRV_RESOURCES, session, event, op, true);
- return TRUE;
-
+ svc_action_t *op = NULL;
+ bool valid_standard = false;
+ _qtype::Variant::List::iterator iter;
+ GHashTable *params = qmf_map_to_hash(args["parameters"].asMap());
+
+ for ( iter=standards.begin() ; iter != standards.end(); iter++ ) {
+ if(args["standard"].asString() == (*iter).asString()) {
+ valid_standard = true;
+ break;
+ }
+ }
+
+ if(valid_standard == false) {
+ mh_err("%s is not a known resource standard", args["standard"].asString().c_str());
+ session.raiseException(event, MH_NOT_IMPLEMENTED);
+ return TRUE;
+ }
+
+ op = resources_action_create(
+ args["name"].asString().c_str(),
+ args["standard"].asString().c_str(),
+ args["provider"].asString().c_str(),
+ args["type"].asString().c_str(),
+ args["action"].asString().c_str(),
+ args["interval"].asInt32(), args["timeout"].asInt32(), params);
+
+ op->expected_rc = args["expected-rc"].asInt32();
+
+ action_async(SRV_RESOURCES, session, event, op, true);
+ return TRUE;
+
} else if (methodName == "cancel") {
services_action_cancel(
args["name"].asString().c_str(),
--
1.7.5.1
12 years, 11 months
Packaging cleanups and streamlining of the services API
by Andrew Beekhof
Also includes the ability for agents/consoles to have their own custom command-line options.
[PATCH 1/9] Services: Make the devision between the basic and advanced API clearer
[PATCH 2/9] Core: Set library versions appropriately
[PATCH 3/9] Build: Add a tags target
[PATCH 4/9] Broker: Turn off systemd redirects until we support it
[PATCH 5/9] Build: Have each agent create their own init script
[PATCH 6/9] Build: Fix up linux packaging
[PATCH 7/9] Services: Set an appropriate rc code for timed out operations
[PATCH 8/9] Services: Define and use additional rc codes
[PATCH 9/9] Core: Support per-agent options
12 years, 12 months
Fwd: matching async responses to async requests
by russell@russellbryant.net
This message is relevant to matahari and the handling of events
related to an earlier method call.
--
Russell Bryant
---------- Forwarded message ----------
From: Ken Giusti <kgiusti(a)redhat.com>
Date: Wed, May 11, 2011 at 9:15 AM
Subject: Re: matching async responses to async requests
To: dev(a)qpid.apache.org
Hi Angus,
Agreed, the doxygen comments are lacking. I've created a jira to address that:
https://issues.apache.org/jira/browse/QPID-3257
The method call model is a request-response pattern that really only
provides for a single response to the request. As you suggested, you
can use events to augment that pattern. Specifically, the agent may
start issuing events in response to the method call, either before or
after the response is sent. Depending on your needs, you could have
the equivalent of a "Start Events"/"Stop Events" method pair, or hold
off the response until all events are doing being generated.
One minor point - the correlation id that is returned to the client is
guaranteed to be unique only for the method call/response period.
Once the response is received, that id _may_ be recycled for future
requests (very unlikely, but I wouldn't recommend counting on it). So
I would suggest that your method call take a unique identifier that
your application provides. All events that correlate to that method
call could contain that identifier, so you don't rely on having the
correlation id be unique over the lifetime of your application.
Does that make sense?
thanks,
-K
----- Original Message -----
> On Fri, May 06, 2011 at 01:48:08PM -0400, Ken Giusti wrote:
> > Apologies for not getting back to you sooner...
> >
> > callMethodAsync() returns a unique 32 bit correlation id that
> > corresponds to the request. The ConsoleEvent that contains the
> > method response has a getCorrelator() method which returns the
> > correlation id that will match the value returned by the initiating
> > callMethodAsync().
> >
> Cool, thanks. The function could do with a doxygen comment. I assumed
> it
> was an error status.
>
> Another question, can you send multiple responses for one request?
> Or would these need to be events?
>
>
> Thanks for the help.
>
> -Angus
>
> >
> >
> > -K
> >
> > ----- Original Message -----
> > > Hi
> > >
> > > We are trying to do multiple async requests on a single qmf
> > > function.
> > > Then we need to match the response to the request in the
> > > ConsoleEvent
> > > handler. Now we could add an In-Out parameter but it seems like
> > > this
> > > is something that should be handled by QMF. Since if you had a QMF
> > > function that you were calling with callMethod() then you changed
> > > to callMethodAsync() you would not have this IO parameter.
> > >
> > > Now if the server processes these in a non serial way (like we
> > > intend
> > > doing)
> > > the responses will comeback out of order and we will have no way
> > > of knowing which request the response was for.
> > >
> > > Is there a way to do this currently?
> > >
> > > Regards
> > > Angus Salkeld
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Apache Qpid - AMQP Messaging Implementation
> > > Project: http://qpid.apache.org
> > > Use/Interact: mailto:dev-subscribe@qpid.apache.org
> >
> > ---------------------------------------------------------------------
> > Apache Qpid - AMQP Messaging Implementation
> > Project: http://qpid.apache.org
> > Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
12 years, 12 months
[PATCH] Config/Console agents
by Adam Stokes
From: Adam Stokes <astokes(a)fedoraproject.org>
- Update config and console agents to call methods on agents raising the events. Since we control both ends (broker<->agent) we give our agent instance name something unique. In this case our config agent creates a name of "config" in order for us to programatically pull the agent address when wanting to call a certain method ("configure").
- The configure method for the agent allows passing an argument (url) which can be anytype of protocol because at this time we only record the url in our "mh_configured" file. At this point this file does basically 2 things, 1) tells the broker we've already been configured, 2) tell the config agent where to pull down our configuration rules. (puppet, cfengine, etc)
- We are leaving the toplevel "console" directory and keeping our agent-console names directly related, i.e. we have a matahari-qmf-config daemon so our console agent is named "config".
---
src/CMakeLists.txt | 2 +
src/cmake/modules/FindQPID.cmake | 15 +++++
src/config/CMakeLists.txt | 24 ++++++++
src/config/config-qmf.cpp | 99 ++++++++++++++++++++++++++++++++
src/config/schema.xml | 15 +++++
src/console/CMakeLists.txt | 18 ++++++
src/console/config.cpp | 82 ++++++++++++++++++++++++++
src/include/matahari/mh_agent_config.h | 33 +++++++++++
src/lib/CMakeLists.txt | 6 ++-
src/lib/mh_agent_config.c | 47 +++++++++++++++
10 files changed, 340 insertions(+), 1 deletions(-)
create mode 100644 src/config/CMakeLists.txt
create mode 100644 src/config/config-qmf.cpp
create mode 100644 src/config/schema.xml
create mode 100644 src/console/CMakeLists.txt
create mode 100644 src/console/config.cpp
create mode 100644 src/include/matahari/mh_agent_config.h
create mode 100644 src/lib/mh_agent_config.c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4762fba..f057d1a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -141,6 +141,8 @@ add_subdirectory(lib)
add_subdirectory(host)
add_subdirectory(network)
add_subdirectory(service)
+add_subdirectory(console)
+add_subdirectory(config)
### Installation
install(FILES ${SCHEMAS} DESTINATION share/matahari)
diff --git a/src/cmake/modules/FindQPID.cmake b/src/cmake/modules/FindQPID.cmake
index 4cb0e89..5fd6f10 100644
--- a/src/cmake/modules/FindQPID.cmake
+++ b/src/cmake/modules/FindQPID.cmake
@@ -15,6 +15,7 @@ if(MSVC)
else(MSVC)
find_library(QMF_LIBRARY qmf)
find_library(QMF2_LIBRARY qmf2)
+ find_library(QMFCONSOLE_LIBRARY qmfconsole)
find_library(QPIDCLIENT_LIBRARY qpidclient)
find_library(QPIDCOMMON_LIBRARY qpidcommon)
find_library(QPIDTYPES_LIBRARY qpidtypes)
@@ -29,6 +30,10 @@ else(MSVC)
set(QMF2_FOUND true)
endif(QMF2_LIBRARY)
+ if(QMFCONSOLE_LIBRARY)
+ set(QMFCONSOLE_FOUND true)
+ endif(QMFCONSOLE_LIBRARY)
+
if(QPIDCLIENT_LIBRARY)
set(QPIDCLIENT_FOUND true)
endif(QPIDCLIENT_LIBRARY)
@@ -66,6 +71,16 @@ else(MSVC)
endif(QPID_FIND_REQUIRED)
endif(QMF2_FOUND)
+ if(QMFCONSOLE_FOUND)
+ if(NOT QPID_FIND_QUIETLY)
+ message(STATUS "Found QMFCONSOLE: ${QMFCONSOLE_LIBRARY}")
+ endif(NOT QPID_FIND_QUIETLY)
+ else(QMFCONSOLE_FOUND)
+ if(QPID_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find QMFCONSOLE")
+ endif(QPID_FIND_REQUIRED)
+ endif(QMFCONSOLE_FOUND)
+
if(QPIDCLIENT_FOUND)
if(NOT QPID_FIND_QUIETLY)
message(STATUS "Found QPIDCLIENT: ${QPIDCLIENT_LIBRARY}")
diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt
new file mode 100644
index 0000000..cd97e3f
--- /dev/null
+++ b/src/config/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(BASE "config")
+set(BASE_LIB "m${BASE}")
+set(QMF_AGENT "matahari-qmf-${BASE}d")
+
+# QMF daemon
+if(WITH-QMF)
+ set(SCHEMA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp)
+ generate_qmf_schemas(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml ${SCHEMA_SOURCES})
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES})
+ target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon mcommon_qmf)
+
+ target_link_libraries(${QMF_AGENT} ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${QMF_AGENT} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${QMF_AGENT} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${QMF_AGENT} DESTINATION sbin)
+endif(WITH-QMF)
diff --git a/src/config/config-qmf.cpp b/src/config/config-qmf.cpp
new file mode 100644
index 0000000..ddbbb49
--- /dev/null
+++ b/src/config/config-qmf.cpp
@@ -0,0 +1,99 @@
+/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include "matahari/mh_agent.h"
+
+#include "qmf/org/matahariproject/QmfPackage.h"
+
+#include <qpid/agent/ManagementAgent.h>
+
+extern "C" {
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "matahari/mh_agent_config.h"
+#include "matahari/logging.h"
+#include "matahari/network.h"
+#include "matahari/host.h"
+#include <sigar.h>
+#include <sigar_format.h>
+};
+
+class ConfigAgent : public MatahariAgent
+{
+private:
+ qmf::org::matahariproject::PackageDefinition _package;
+public:
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
+};
+
+int
+main(int argc, char **argv)
+{
+ ConfigAgent agent;
+ int rc = agent.init(argc, argv, "Config");
+ if (rc == 0) {
+ agent.run();
+ }
+ return rc;
+}
+
+int
+ConfigAgent::setup(qmf::AgentSession session)
+{
+ _package.configure(session);
+ _instance = qmf::Data(_package.data_Config);
+
+ _instance.setProperty("hostname", mh_hostname());
+ _instance.setProperty("uuid", mh_uuid());
+
+ _agent_session.addData(_instance, "config");
+ return 0;
+}
+
+gboolean
+ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+{
+ if (event.getType() != qmf::AGENT_METHOD) {
+ session.methodSuccess(event);
+ return TRUE;
+ }
+
+ const std::string& methodName(event.getMethodName());
+
+ if (methodName == "configure") {
+ int rc = mh_is_configured(
+ event.getArguments()["uri"].asString().c_str());
+ event.addReturnArgument("configured", rc);
+ } else {
+ session.raiseException(event, MH_NOT_IMPLEMENTED);
+ goto bail;
+ }
+
+ session.methodSuccess(event);
+
+bail:
+ return TRUE;
+}
diff --git a/src/config/schema.xml b/src/config/schema.xml
new file mode 100644
index 0000000..39b062c
--- /dev/null
+++ b/src/config/schema.xml
@@ -0,0 +1,15 @@
+<schema package="org.matahariproject">
+
+ <!-- Config API -->
+ <class name="Config">
+ <property name="uuid" type="sstr" access="RO" desc="Host UUID" />
+ <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
+
+ <statistic name="qmf-gen-no-crash" type="absTime" desc="Dummy stat to stop qmf-gen from crashing." />
+
+ <method name="configure" desc="Send configure method">
+ <arg name="uri" dir="I" type="sstr" />
+ <arg name="configured" dir="O" type="uint32" />
+ </method>
+ </class>
+</schema>
diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt
new file mode 100644
index 0000000..b0f847a
--- /dev/null
+++ b/src/console/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(CONSOLE_CONFIG_QMF "matahari-console-configd")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${CONSOLE_CONFIG_QMF} config.cpp)
+ target_link_libraries(${CONSOLE_CONFIG_QMF} mcommon mcommon_qmf)
+
+ target_link_libraries(${CONSOLE_CONFIG_QMF} ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${CONSOLE_CONFIG_QMF} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${CONSOLE_CONFIG_QMF} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${CONSOLE_CONFIG_QMF} DESTINATION sbin)
+endif(WITH-QMF)
diff --git a/src/console/config.cpp b/src/console/config.cpp
new file mode 100644
index 0000000..11a6c1f
--- /dev/null
+++ b/src/console/config.cpp
@@ -0,0 +1,82 @@
+/* config.cpp - Copyright (c) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/Duration.h>
+#include <qmf/ConsoleSession.h>
+#include <qmf/ConsoleEvent.h>
+#include <qmf/Agent.h>
+#include <qmf/Data.h>
+#include <qmf/DataAddr.h>
+#include <qmf/Query.h>
+#include <qpid/types/Variant.h>
+
+#include <string>
+#include <iostream>
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+int main(int argc, char** argv)
+{
+ string brokerUrl("amqp:tcp:127.0.0.1:49000");
+ qpid::types::Variant::Map connectionOptions;
+ qpid::types::Variant::Map dataProperties;
+ string sessionOptions;
+
+ connectionOptions["reconnect"] = true;
+
+ dataProperties["uri"] = argv[1] ? argv[1] : "http://localhost/config/uuid";
+
+ qpid::messaging::Connection connection(brokerUrl, connectionOptions);
+ connection.open();
+
+ ConsoleSession session(connection, sessionOptions);
+ session.open();
+
+ // Only filter connecting agents under matahariproject.org vendor
+ session.setAgentFilter("[eq, _vendor, [quote, 'matahariproject.org']]]");
+ Agent agent;
+ while (true) {
+ ConsoleEvent event;
+ if(session.nextEvent(event)) {
+ switch(event.getType()) {
+ case CONSOLE_AGENT_ADD:
+ {
+ if (session.getAgentCount() == 1) {
+ agent = session.getAgent(0);
+ DataAddr agent_event_addr("config", agent.getName(), 0);
+ ConsoleEvent result(agent.callMethod("configure",
+ dataProperties,
+ agent_event_addr));
+ cout << result.getArguments() << endl;
+ }
+ }
+ break;
+ default: {}
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/include/matahari/mh_agent_config.h b/src/include/matahari/mh_agent_config.h
new file mode 100644
index 0000000..fe87e27
--- /dev/null
+++ b/src/include/matahari/mh_agent_config.h
@@ -0,0 +1,33 @@
+/* host.h - Copyright (C) 2009 Red Hat, Inc.
+ * Written by Arjun Roy <arroy(a)redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * \file
+ * \brief Config API
+ * \ingroup coreapi
+ */
+
+#ifndef __MH_CONFIG_H__
+#define __MH_CONFIG_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+
+extern uint32_t mh_is_configured(const char *uri);
+
+#endif // __MH_CONFIG_H__
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 2538517..38485d3 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
# Library
-set(LIBS mcommon mhost mnetwork mservice)
+set(LIBS mcommon mhost mnetwork mservice mconfig)
include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c)
@@ -19,6 +19,10 @@ add_library (mservice SHARED services.c services_${VARIANT}.c)
set_target_properties(mservice PROPERTIES SOVERSION 0.0.1)
target_link_libraries(mservice ${pcre_LIBRARIES} mcommon ${SIGAR} ${glib_LIBRARIES})
+add_library (mconfig SHARED mh_agent_config.c)
+set_target_properties(mconfig PROPERTIES SOVERSION 0.0.1)
+target_link_libraries(mconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
+
if(WIN32)
foreach (lib ${LIBS})
target_link_libraries(${lib} wsock32)
diff --git a/src/lib/mh_agent_config.c b/src/lib/mh_agent_config.c
new file mode 100644
index 0000000..34282c5
--- /dev/null
+++ b/src/lib/mh_agent_config.c
@@ -0,0 +1,47 @@
+/* mh_agent_config.c - Copyright (C) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "matahari/mh_agent_config.h"
+#include "matahari/logging.h"
+
+MH_TRACE_INIT_DATA(mh_config);
+
+uint32_t mh_is_configured(const char *uri)
+{
+ int config_file_exist = 0;
+ const char *filename = "/tmp/.mh_configured";
+
+ if(!g_file_test(filename, G_FILE_TEST_EXISTS)) {
+ if(!g_file_set_contents(filename, uri, -1, NULL)) {
+ mh_log(LOG_DEBUG, "Unable to create file.");
+ }
+ config_file_exist = 1;
+ } else {
+ config_file_exist = 1;
+ }
+ return config_file_exist;
+}
--
1.7.4.4
12 years, 12 months
[PATCH] All sources updated according to new guidelines.
by Radek Novacek
Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
src/host/host-dbus.c | 309 ++++++++++----------
src/host/host-qmf.cpp | 12 +-
src/include/matahari.h.in | 4 +-
src/include/matahari/host.h | 4 +-
src/include/matahari/logging.h | 159 ++++++-----
src/include/matahari/mainloop.h | 64 +++--
src/include/matahari/mh_agent.h | 17 +-
src/include/matahari/mh_dbus_common.h | 21 +-
src/include/matahari/mh_gobject_class.h | 25 +-
src/include/matahari/services.h | 43 ++-
src/include/matahari/utilities.h | 28 +-
src/lib/doxygen.h | 6 +-
src/lib/host.c | 75 +++--
src/lib/host_linux.c | 13 +-
src/lib/host_private.h | 15 +-
src/lib/host_windows.c | 14 +-
src/lib/mainloop.c | 83 +++---
src/lib/mh_agent.cpp | 90 ++++---
src/lib/mh_dbus_common.c | 410 +++++++++++++--------------
src/lib/network.c | 24 +-
src/lib/network_linux.c | 10 +-
src/lib/network_private.h | 6 +-
src/lib/network_windows.c | 6 +-
src/lib/services.c | 65 +++--
src/lib/services_linux.c | 233 ++++++++-------
src/lib/services_private.h | 27 +-
src/lib/services_windows.c | 389 +++++++++++++------------
src/lib/utilities.c | 472 ++++++++++++++++---------------
src/network/network-dbus.c | 242 ++++++++--------
src/network/network-qmf.cpp | 38 ++-
src/service/service-dbus.c | 288 ++++++++++----------
src/service/service-qmf.cpp | 75 +++---
src/tests/t_dnssrv.c | 6 +-
33 files changed, 1701 insertions(+), 1572 deletions(-)
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index ead877e..612b457 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Roman Rakus <rrakus(a)redhat.com>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -39,7 +39,7 @@
struct Private
{
- guint update_interval;
+ guint update_interval;
};
struct Private priv;
@@ -48,44 +48,42 @@ struct Private priv;
gboolean
Host_identify(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".identify", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action identify is not implemented yet!");
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".identify", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action identify is not implemented yet!");
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
gboolean
Host_shutdown(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".shutdown", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- mh_host_shutdown();
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".shutdown", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ mh_host_shutdown();
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
gboolean
Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- mh_host_reboot();
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ mh_host_reboot();
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
/* Generated dbus stuff for host
@@ -95,149 +93,148 @@ Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_UPDATE_INTERVAL:
- priv.update_interval = g_value_get_uint (value);
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_UPDATE_INTERVAL:
+ priv.update_interval = g_value_get_uint (value);
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- sigar_proc_stat_t procs;
- sigar_loadavg_t avg;
- Dict *dict;
- GValue value_value = {0, };
-
- switch (property_id)
- {
- case PROP_UUID:
- g_value_set_string (value, mh_host_get_uuid());
- break;
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_host_get_hostname());
- break;
- case PROP_OS:
- g_value_set_string (value, mh_host_get_operating_system());
- break;
- case PROP_ARCH:
- g_value_set_string (value, mh_host_get_architecture());
- break;
- case PROP_WORDSIZE:
- g_value_set_uint (value, mh_host_get_cpu_wordsize());
- break;
- case PROP_MEMORY:
- g_value_set_uint64 (value, mh_host_get_memory());
- break;
- case PROP_SWAP:
- g_value_set_uint64 (value, mh_host_get_swap());
- break;
- case PROP_CPU_COUNT:
- g_value_set_uint (value, mh_host_get_cpu_count());
- break;
- case PROP_CPU_CORES:
- g_value_set_uint (value, mh_host_get_cpu_number_of_cores());
- break;
- case PROP_CPU_MODEL:
- g_value_set_string (value, mh_host_get_cpu_model());
- break;
- case PROP_CPU_FLAGS:
- g_value_set_string (value, mh_host_get_cpu_flags());
- break;
- case PROP_UPDATE_INTERVAL:
- g_value_set_uint (value, priv.update_interval);
- break;
- case PROP_LAST_UPDATED:
- // Not used in DBus module
- break;
- case PROP_SEQUENCE:
- // Not used in DBus module
- break;
- case PROP_FREE_MEM:
- g_value_set_uint64 (value, mh_host_get_mem_free());
- break;
- case PROP_FREE_SWAP:
- g_value_set_uint64 (value, mh_host_get_swap_free());
- break;
- case PROP_LOAD:
- // 1/5/15 minute load average - map
- mh_host_get_load_averages(&avg);
-
- dict = dict_new(value);
- g_value_init (&value_value, G_TYPE_DOUBLE);
-
- g_value_set_double(&value_value, avg.loadavg[0]);
- dict_add(dict, "1", &value_value);
-
- g_value_set_double(&value_value, avg.loadavg[1]);
- dict_add(dict, "5", &value_value);
-
- g_value_set_double(&value_value, avg.loadavg[2]);
- dict_add(dict, "15", &value_value);
- dict_free(dict);
- break;
- case PROP_PROCESS_STATISTICS:
- // Process statistics is type map string -> int
- mh_host_get_processes(&procs);
-
- dict = dict_new(value);
- g_value_init (&value_value, G_TYPE_INT);
-
- g_value_set_int(&value_value, procs.total);
- dict_add(dict, "total", &value_value);
-
- g_value_set_int(&value_value, procs.idle);
- dict_add(dict, "idle", &value_value);
-
- g_value_set_int(&value_value, procs.zombie);
- dict_add(dict, "zombie", &value_value);
-
- g_value_set_int(&value_value, procs.running);
- dict_add(dict, "running", &value_value);
-
- g_value_set_int(&value_value, procs.stopped);
- dict_add(dict, "stopped", &value_value);
-
- g_value_set_int(&value_value, procs.sleeping);
- dict_add(dict, "sleeping", &value_value);
- dict_free(dict);
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ sigar_proc_stat_t procs;
+ sigar_loadavg_t avg;
+ Dict *dict;
+ GValue value_value = {0, };
+
+ switch (property_id) {
+ case PROP_UUID:
+ g_value_set_string (value, mh_host_get_uuid());
+ break;
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_host_get_hostname());
+ break;
+ case PROP_OS:
+ g_value_set_string (value, mh_host_get_operating_system());
+ break;
+ case PROP_ARCH:
+ g_value_set_string (value, mh_host_get_architecture());
+ break;
+ case PROP_WORDSIZE:
+ g_value_set_uint (value, mh_host_get_cpu_wordsize());
+ break;
+ case PROP_MEMORY:
+ g_value_set_uint64 (value, mh_host_get_memory());
+ break;
+ case PROP_SWAP:
+ g_value_set_uint64 (value, mh_host_get_swap());
+ break;
+ case PROP_CPU_COUNT:
+ g_value_set_uint (value, mh_host_get_cpu_count());
+ break;
+ case PROP_CPU_CORES:
+ g_value_set_uint (value, mh_host_get_cpu_number_of_cores());
+ break;
+ case PROP_CPU_MODEL:
+ g_value_set_string (value, mh_host_get_cpu_model());
+ break;
+ case PROP_CPU_FLAGS:
+ g_value_set_string (value, mh_host_get_cpu_flags());
+ break;
+ case PROP_UPDATE_INTERVAL:
+ g_value_set_uint (value, priv.update_interval);
+ break;
+ case PROP_LAST_UPDATED:
+ // Not used in DBus module
+ break;
+ case PROP_SEQUENCE:
+ // Not used in DBus module
+ break;
+ case PROP_FREE_MEM:
+ g_value_set_uint64 (value, mh_host_get_mem_free());
+ break;
+ case PROP_FREE_SWAP:
+ g_value_set_uint64 (value, mh_host_get_swap_free());
+ break;
+ case PROP_LOAD:
+ // 1/5/15 minute load average - map
+ mh_host_get_load_averages(&avg);
+
+ dict = dict_new(value);
+ g_value_init (&value_value, G_TYPE_DOUBLE);
+
+ g_value_set_double(&value_value, avg.loadavg[0]);
+ dict_add(dict, "1", &value_value);
+
+ g_value_set_double(&value_value, avg.loadavg[1]);
+ dict_add(dict, "5", &value_value);
+
+ g_value_set_double(&value_value, avg.loadavg[2]);
+ dict_add(dict, "15", &value_value);
+ dict_free(dict);
+ break;
+ case PROP_PROCESS_STATISTICS:
+ // Process statistics is type map string -> int
+ mh_host_get_processes(&procs);
+
+ dict = dict_new(value);
+ g_value_init (&value_value, G_TYPE_INT);
+
+ g_value_set_int(&value_value, procs.total);
+ dict_add(dict, "total", &value_value);
+
+ g_value_set_int(&value_value, procs.idle);
+ dict_add(dict, "idle", &value_value);
+
+ g_value_set_int(&value_value, procs.zombie);
+ dict_add(dict, "zombie", &value_value);
+
+ g_value_set_int(&value_value, procs.running);
+ dict_add(dict, "running", &value_value);
+
+ g_value_set_int(&value_value, procs.stopped);
+ dict_add(dict, "stopped", &value_value);
+
+ g_value_set_int(&value_value, procs.sleeping);
+ dict_add(dict, "sleeping", &value_value);
+ dict_free(dict);
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- switch (prop)
- {
+ switch (prop) {
case PROP_LOAD:
- return G_TYPE_DOUBLE;
- break;
+ return G_TYPE_DOUBLE;
+ break;
case PROP_PROCESS_STATISTICS:
- return G_TYPE_INT;
- break;
+ return G_TYPE_INT;
+ break;
default:
- g_printerr("Type of property %s is map of unknown types\n", properties[prop].name);
- return G_TYPE_VALUE;
- }
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
+ }
}
int
main(int argc, char** argv)
{
- g_type_init();
- priv.update_interval = 5;
- return run_dbus_server(HOST_BUS_NAME, HOST_OBJECT_PATH);
+ g_type_init();
+ priv.update_interval = 5;
+ return run_dbus_server(HOST_BUS_NAME, HOST_OBJECT_PATH);
}
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index bbac480..7547daf 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -41,10 +41,11 @@ public:
int heartbeat();
virtual int setup(qmf::AgentSession session);
virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer user_data);
+ gpointer user_data);
};
-static gboolean heartbeat_timer(gpointer data)
+static gboolean
+heartbeat_timer(gpointer data)
{
HostAgent *agent = (HostAgent *)data;
g_timeout_add(agent->heartbeat(), heartbeat_timer, data);
@@ -65,7 +66,8 @@ main(int argc, char **argv)
}
gboolean
-HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
if (event.getType() != qmf::AGENT_METHOD) {
session.methodSuccess(event);
@@ -124,9 +126,9 @@ HostAgent::heartbeat()
_heartbeat_sequence++;
mh_trace("Updating stats: %d %d", _heartbeat_sequence, interval);
- if(interval == 0) {
+ if (interval == 0) {
/* Updates disabled, check again in 5min */
- return 5*60*1000;
+ return 5 * 60 * 1000;
}
#ifndef MSVC
diff --git a/src/include/matahari.h.in b/src/include/matahari.h.in
index 3eef272..4899e0c 100644
--- a/src/include/matahari.h.in
+++ b/src/include/matahari.h.in
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index 5f78564..d8d3acd 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/include/matahari/logging.h b/src/include/matahari/logging.h
index f09ea44..8d0078a 100644
--- a/src/include/matahari/logging.h
+++ b/src/include/matahari/logging.h
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -28,15 +28,15 @@
#ifdef __linux__
# include <syslog.h>
-#else
-# define LOG_EMERG 0 /* system is unusable */
-# define LOG_ALERT 1 /* action must be taken immediately */
-# define LOG_CRIT 2 /* critical conditions */
-# define LOG_ERR 3 /* error conditions */
-# define LOG_WARNING 4 /* warning conditions */
-# define LOG_NOTICE 5 /* normal but significant condition */
-# define LOG_INFO 6 /* informational */
-# define LOG_DEBUG 7 /* debug-level messages */
+#else
+# define LOG_EMERG 0 /* system is unusable */
+# define LOG_ALERT 1 /* action must be taken immediately */
+# define LOG_CRIT 2 /* critical conditions */
+# define LOG_ERR 3 /* error conditions */
+# define LOG_WARNING 4 /* warning conditions */
+# define LOG_NOTICE 5 /* normal but significant condition */
+# define LOG_INFO 6 /* informational */
+# define LOG_DEBUG 7 /* debug-level messages */
#endif
#include <stdio.h>
@@ -55,11 +55,11 @@ extern void mh_enable_stderr(gboolean to_stderr);
/* Linux with trace logging */
struct _mh_ddebug_query {
- const char *files;
- const char *formats;
- const char *functions;
- unsigned long long total;
- unsigned long long matches;
+ const char *files;
+ const char *formats;
+ const char *functions;
+ unsigned long long total;
+ unsigned long long matches;
};
/*
@@ -88,92 +88,97 @@ struct _mh_ddebug {
extern struct _mh_ddebug __start___verbose[];
extern struct _mh_ddebug __stop___verbose[];
-# define MH_TRACE_INIT_DATA(name) \
- void name(void); \
+# define MH_TRACE_INIT_DATA(name) \
+ void name(void); \
void name(void) { MH_ASSERT(__start___verbose != __stop___verbose); } \
void __attribute__ ((constructor)) name(void);
-# define MH_CHECK(expr, failure_action) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, #expr, __LINE__, LOG_TRACE}; \
- \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
- descriptor.bump != LOG_TRACE, 1); \
- failure_action; \
- } \
+# define MH_CHECK(expr, failure_action) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, #expr, __LINE__, LOG_TRACE}; \
+ \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
+ descriptor.bump != LOG_TRACE, 1); \
+ failure_action; \
+ } \
} while(0)
/*
* Throughout the macros below, note the leading, pre-comma, space in the
* various ' , ##args' occurences to aid portability across versions of 'gcc'.
- * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
+ * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
*/
-# define mh_log(level, fmt, args...) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, fmt, __LINE__, LOG_TRACE}; \
- \
- if(__likely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- \
- } else if(__unlikely(descriptor.bump != LOG_TRACE)) { \
- mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
- } \
+# define mh_log(level, fmt, args...) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, fmt, __LINE__, LOG_TRACE}; \
+ \
+ if (__likely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ \
+ } else if (__unlikely(descriptor.bump != LOG_TRACE)) { \
+ mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, \
+ __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
+ } \
} while(0)
-# define mh_log_unlikely(level, fmt, args...) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, fmt, __LINE__, LOG_TRACE }; \
- \
- if(__unlikely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- \
- } else if(__unlikely(descriptor.bump != LOG_TRACE)) { \
- mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
- } \
+# define mh_log_unlikely(level, fmt, args...) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, fmt, __LINE__, LOG_TRACE }; \
+ \
+ if (__unlikely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ \
+ } else if (__unlikely(descriptor.bump != LOG_TRACE)) { \
+ mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, \
+ __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
+ } \
} while(0)
-# define mh_log_alias(level, file, function, line, fmt, args...) do { \
- if(line) { \
- mh_log_fn(level, "TRACE: %s %s:%d "fmt, function, file, line, ##args); \
- } else { \
- mh_log_fn(level, "%s "fmt, function, ##args); \
- } \
+# define mh_log_alias(level, file, function, line, fmt, args...) do { \
+ if (line) { \
+ mh_log_fn(level, "TRACE: %s %s:%d "fmt, function, file, line, \
+ ##args); \
+ } else { \
+ mh_log_fn(level, "%s "fmt, function, ##args); \
+ } \
} while(0)
#else
# define MH_TRACE_INIT_DATA(name)
-# define MH_CHECK(expr, failure_action) do { \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, #expr, 0, 1); \
- failure_action; \
- } \
+# define MH_CHECK(expr, failure_action) do { \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, #expr, 0, 1); \
+ failure_action; \
+ } \
} while(0)
-# define mh_log(level, fmt, args...) do { \
- if(__likely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- } \
+# define mh_log(level, fmt, args...) do { \
+ if (__likely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ } \
} while(0)
-# define mh_log_unlikely(level, fmt, args...) do { \
- if(__unlikely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- } \
+# define mh_log_unlikely(level, fmt, args...) do { \
+ if (__unlikely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ } \
} while(0)
-# define mh_log_alias(level, file, function, line, fmt, args...) do { \
- mh_log_fn(level, "%s"fmt, function, ##args); \
+# define mh_log_alias(level, file, function, line, fmt, args...) do { \
+ mh_log_fn(level, "%s"fmt, function, ##args); \
} while(0)
#endif
-#define mh_log_always(level, fmt, args...) mh_log_fn(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args)
+#define mh_log_always(level, fmt, args...) mh_log_fn(level, "%s: " fmt, \
+ __PRETTY_FUNCTION__ ,\
+ ##args)
#define mh_crit(fmt, args...) mh_log(LOG_CRIT, fmt , ##args)
#define mh_err(fmt, args...) mh_log(LOG_ERR, fmt , ##args)
#define mh_warn(fmt, args...) mh_log(LOG_WARNING, fmt , ##args)
@@ -182,9 +187,9 @@ extern struct _mh_ddebug __stop___verbose[];
#define mh_debug(fmt, args...) mh_log_unlikely(LOG_DEBUG, fmt , ##args)
#define mh_trace(fmt, args...) mh_log_unlikely(LOG_TRACE, fmt , ##args)
-#define mh_perror(level, fmt, args...) do { \
- const char *err = strerror(errno); \
- fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \
- mh_log(level, fmt ": %s (%d)", ##args, err, errno); \
+#define mh_perror(level, fmt, args...) do { \
+ const char *err = strerror(errno); \
+ fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \
+ mh_log(level, fmt ": %s (%d)", ##args, err, errno); \
} while(0)
#endif
diff --git a/src/include/matahari/mainloop.h b/src/include/matahari/mainloop.h
index 2bd3f7b..43a7a20 100644
--- a/src/include/matahari/mainloop.h
+++ b/src/include/matahari/mainloop.h
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2009 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -35,39 +35,39 @@ extern gboolean mainloop_add_signal(int sig, void (*dispatch)(int sig));
extern gboolean mainloop_destroy_signal(int sig);
-typedef struct trigger_s
+typedef struct trigger_s
{
- GSource source;
- GDestroyNotify dnotify;
- gboolean trigger;
- void *user_data;
- guint id;
+ GSource source;
+ GDestroyNotify dnotify;
+ gboolean trigger;
+ void *user_data;
+ guint id;
} mainloop_trigger_t;
extern mainloop_trigger_t *mainloop_add_trigger(
int priority, gboolean (*dispatch)(gpointer user_data), gpointer userdata);
-extern void mainloop_set_trigger(mainloop_trigger_t* source);
+extern void mainloop_set_trigger(mainloop_trigger_t *source);
-extern gboolean mainloop_destroy_trigger(mainloop_trigger_t* source);
+extern gboolean mainloop_destroy_trigger(mainloop_trigger_t *source);
-typedef struct mainloop_fd_s
+typedef struct mainloop_fd_s
{
- GSource source;
- GPollFD gpoll;
- guint id;
- void *user_data;
- GDestroyNotify dnotify;
- gboolean (*dispatch)(int fd, gpointer user_data);
+ GSource source;
+ GPollFD gpoll;
+ guint id;
+ void *user_data;
+ GDestroyNotify dnotify;
+ gboolean (*dispatch)(int fd, gpointer user_data);
} mainloop_fd_t;
extern mainloop_fd_t *mainloop_add_fd(int priority, int fd,
- gboolean (*dispatch)(int fd, gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
+ gboolean (*dispatch)(int fd, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
extern gboolean mainloop_destroy_fd(mainloop_fd_t* source);
@@ -75,14 +75,14 @@ extern gboolean mainloop_destroy_fd(mainloop_fd_t* source);
typedef struct mainloop_child_s mainloop_child_t;
struct mainloop_child_s {
- pid_t pid;
- char *desc;
- unsigned timerid;
- gboolean timeout;
- void *privatedata;
+ pid_t pid;
+ char *desc;
+ unsigned timerid;
+ gboolean timeout;
+ void *privatedata;
- /* Called when a process dies */
- void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode);
+ /* Called when a process dies */
+ void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode);
};
@@ -92,8 +92,10 @@ extern void mainloop_track_children(int priority);
* Create a new tracked process
* To track a process group, use -pid
*/
-extern void mainloop_add_child(
- pid_t pid, int timeout, const char *desc, void * privatedata,
- void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode));
+extern void mainloop_add_child(pid_t pid, int timeout, const char *desc,
+ void *privatedata,
+ void (*callback)(mainloop_child_t* p,
+ int status, int signo,
+ int exitcode));
#endif
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 26fbae0..9bf86ec 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -53,14 +53,16 @@ typedef struct mainloop_qmf_s {
guint id;
void *user_data;
GDestroyNotify dnotify;
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
} mainloop_qmf_t;
extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
-extern gboolean mainloop_destroy_qmf(mainloop_qmf_t* source);
+extern gboolean mainloop_destroy_qmf(mainloop_qmf_t *source);
class MatahariAgent
{
@@ -69,7 +71,8 @@ public:
~MatahariAgent() {};
virtual int setup(qmf::AgentSession session) { return 0; };
- virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) { return FALSE; };
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data) { return FALSE; };
int init(int argc, char **argv, const char* proc_name);
void run();
diff --git a/src/include/matahari/mh_dbus_common.h b/src/include/matahari/mh_dbus_common.h
index b7edc53..e7b4936 100644
--- a/src/include/matahari/mh_dbus_common.h
+++ b/src/include/matahari/mh_dbus_common.h
@@ -30,7 +30,8 @@
#include "mh_gobject_class.h"
/* Private struct in Matahari class */
-#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MATAHARI_TYPE, MatahariPrivate))
+#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ MATAHARI_TYPE, MatahariPrivate))
// Matahari error codes
#define MATAHARI_ERROR matahari_error_quark ()
@@ -44,7 +45,8 @@ matahari_error_quark (void);
* user is authorized, otherwise return FALSE and 'error' is set.
*/
gboolean
-check_authorization(const gchar *action, GError** error, DBusGMethodInvocation *context);
+check_authorization(const gchar *action, GError** error,
+ DBusGMethodInvocation *context);
typedef struct {
int prop;
@@ -67,14 +69,16 @@ run_dbus_server(char *bus_name, char *object_path);
* action interface.name
*/
gboolean
-matahari_get(Matahari* matahari, const char *interface, const char *name, DBusGMethodInvocation *context);
+matahari_get(Matahari* matahari, const char *interface, const char *name,
+ DBusGMethodInvocation *context);
/**
* Check the authorization for setting the parameter 'name' using PolicyKit
* action interface.name
*/
gboolean
-matahari_set(Matahari *matahari, const char *interface, const char *name, GValue *value, DBusGMethodInvocation *context);
+matahari_set(Matahari *matahari, const char *interface, const char *name,
+ GValue *value, DBusGMethodInvocation *context);
/**
* This method is used for getting value of DBus property.
@@ -82,7 +86,8 @@ matahari_set(Matahari *matahari, const char *interface, const char *name, GValue
* Set the value of property_id parameter to parameter value.
*/
void
-matahari_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+matahari_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec);
/**
* This method is used for setting value of DBus property.
@@ -90,7 +95,8 @@ matahari_get_property(GObject *object, guint property_id, GValue *value, GParamS
* New value of property_id is in parameter value.
*/
void
-matahari_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+matahari_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec);
/**
* This method is used to determine type of value in all dictionary parameters.
@@ -110,7 +116,8 @@ typedef struct
} Dict;
/**
- * Constructor of dictionary type. Key is string, type of value is defined by type of 'value'.
+ * Constructor of dictionary type. Key is string, type of value is defined
+ * by type of 'value'.
* New value will be stored in 'value'. Use dict_free after setting all values.
*/
Dict *dict_new(GValue *value);
diff --git a/src/include/matahari/mh_gobject_class.h b/src/include/matahari/mh_gobject_class.h
index 821d0ac..fe13d1e 100644
--- a/src/include/matahari/mh_gobject_class.h
+++ b/src/include/matahari/mh_gobject_class.h
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Roman Rakus <rrakus(a)redhat.com>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -23,12 +23,17 @@
#ifndef MHGOBJECTCLASS_H_
#define MHGOBJECTCLASS_H_
-#define MATAHARI_TYPE (matahari_get_type())
-#define MATAHARI(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MATAHARI_TYPE, Matahari))
-#define MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MATAHARI_TYPE, MatahariClass))
-#define IS_MATAHARI(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MATAHARI_TYPE))
-#define IS_MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MATAHARI_TYPE))
-#define MATAHARI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MATAHARI_TYPE, MatahariClass))
+#define MATAHARI_TYPE (matahari_get_type())
+#define MATAHARI(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), \
+ MATAHARI_TYPE, Matahari))
+#define MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MATAHARI_TYPE, MatahariClass))
+#define IS_MATAHARI(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), \
+ MATAHARI_TYPE))
+#define IS_MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MATAHARI_TYPE))
+#define MATAHARI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MATAHARI_TYPE, MatahariClass))
typedef struct _Matahari Matahari;
typedef struct _MatahariClass MatahariClass;
@@ -39,13 +44,13 @@ matahari_get_type(void);
struct _Matahari
{
- GObject parent;
- MatahariPrivate *priv;
+ GObject parent;
+ MatahariPrivate *priv;
};
struct _MatahariClass
{
- GObjectClass parent;
+ GObjectClass parent;
};
#endif /* MHGOBJECTCLASS_H_ */
diff --git a/src/include/matahari/services.h b/src/include/matahari/services.h
index 0a48bb8..5241e73 100644
--- a/src/include/matahari/services.h
+++ b/src/include/matahari/services.h
@@ -47,7 +47,8 @@ enum lsb_exitcode {
/* 150-199 reserved for application use */
};
-/* The return codes for the status operation are not the same for other operatios - go figure */
+/* The return codes for the status operation are not the same for other
+ * operatios - go figure */
enum lsb_status_exitcode {
LSB_STATUS_OK = 0,
LSB_STATUS_VAR_PID = 1,
@@ -55,7 +56,7 @@ enum lsb_status_exitcode {
LSB_STATUS_NOT_RUNNING = 3,
LSB_STATUS_NOT_INSTALLED = 4,
- /* 150-199 reserved for application use */
+ /* 150-199 reserved for application use */
LSB_STATUS_UNKNOWN_ERROR = 199,
};
@@ -122,26 +123,35 @@ extern GList *services_list(void);
extern GList *resources_list_ocf_providers(void);
extern GList *resources_list_ocf_agents(const char *provider);
-extern svc_action_t *services_action_create(
- const char *name, const char *action, int interval /* ms */, int timeout /* ms */);
-
-/* After the call, 'params' is owned, and later free'd by the svc_action_t result */
-extern svc_action_t *resources_action_create(
- const char *name, const char *provider, const char *agent,
- const char *action, int interval /* ms */, int timeout /* ms */, GHashTable *params);
+extern svc_action_t *services_action_create(const char *name,
+ const char *action,
+ int interval /* ms */,
+ int timeout /* ms */);
+
+/* After the call, 'params' is owned, and later free'd by the
+ * svc_action_t result */
+extern svc_action_t *resources_action_create(const char *name,
+ const char *provider,
+ const char *agent,
+ const char *action,
+ int interval /* ms */,
+ int timeout /* ms */,
+ GHashTable *params);
extern void services_action_free(svc_action_t *op);
-extern gboolean services_action_sync(svc_action_t* op);
-extern gboolean services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t*));
+extern gboolean services_action_sync(svc_action_t *op);
+extern gboolean services_action_async(svc_action_t *op,
+ void (*action_callback)(svc_action_t *));
-extern gboolean services_action_cancel(const char *name, const char *action, int interval);
+extern gboolean services_action_cancel(const char *name, const char *action,
+ int interval);
static inline enum ocf_exitcode
services_get_ocf_exitcode(char *action, int lsb_exitcode)
{
- if(action != NULL && strcmp("status", action) == 0) {
- switch(lsb_exitcode) {
+ if (action != NULL && strcmp("status", action) == 0) {
+ switch (lsb_exitcode) {
case LSB_STATUS_OK: return OCF_OK;
case LSB_STATUS_VAR_PID: return OCF_NOT_RUNNING;
case LSB_STATUS_VAR_LOCK: return OCF_NOT_RUNNING;
@@ -150,11 +160,12 @@ services_get_ocf_exitcode(char *action, int lsb_exitcode)
default: return OCF_UNKNOWN_ERROR;
}
- } else if(lsb_exitcode > LSB_NOT_RUNNING) {
+ } else if (lsb_exitcode > LSB_NOT_RUNNING) {
return OCF_UNKNOWN_ERROR;
}
- /* For non-status operations, the LSB and OCF share error code meaning for rc <= 7 */
+ /* For non-status operations, the LSB and OCF share error code meaning
+ * for rc <= 7 */
return (enum ocf_exitcode)lsb_exitcode;
}
#endif
diff --git a/src/include/matahari/utilities.h b/src/include/matahari/utilities.h
index e48be25..60c5856 100644
--- a/src/include/matahari/utilities.h
+++ b/src/include/matahari/utilities.h
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,7 +34,7 @@
extern const char *mh_uuid(void);
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);
+ const char *assert_condition, int do_core, int do_fork);
#ifndef HAVE_ASPRINTF
/**
@@ -47,7 +47,7 @@ extern void mh_abort(const char *file, const char *function, int line,
extern int asprintf(char **ret, const char *fmt, ...);
#endif
-#define DIMOF(a) ((int) (sizeof(a) / sizeof(0[a])))
+#define DIMOF(a) ((int) (sizeof(a) / sizeof(0[a])))
#ifndef __GNUC__
# define __builtin_expect(expr, result) (expr)
@@ -57,16 +57,16 @@ extern int asprintf(char **ret, const char *fmt, ...);
#define __likely(expr) __builtin_expect(expr, 1)
#define __unlikely(expr) __builtin_expect(expr, 0)
-#define MH_ASSERT(expr) do { \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 1, 0); \
- } \
+#define MH_ASSERT(expr) do { \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 1, 0); \
+ } \
} while(0)
-#define MH_LOG_ASSERT(expr) do { \
- if(__unlikely((expr) == FALSE)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 0, 1); \
- } \
+#define MH_LOG_ASSERT(expr) do { \
+ if (__unlikely((expr) == FALSE)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 0, 1); \
+ } \
} while(0)
#endif
diff --git a/src/lib/doxygen.h b/src/lib/doxygen.h
index e646258..1516eaf 100644
--- a/src/lib/doxygen.h
+++ b/src/lib/doxygen.h
@@ -1,4 +1,4 @@
-/*
+/*
* doxygen.h - Copyright (C) 2011, Russell Bryant
* Written by Russell Bryant <russell(a)russellbryant.net>
*
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/lib/host.c b/src/lib/host.c
index 771ac44..6e71db0 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -63,55 +63,63 @@ static cpuinfo_t cpuinfo = {
.cores = 0,
};
-static void host_get_cpu_details(void);
+static void
+host_get_cpu_details(void);
-static void init(void)
+static void
+init(void)
{
- if(host_init.sigar_init) {
+ if (host_init.sigar_init) {
return;
}
sigar_open(&host_init.sigar);
host_init.sigar_init = TRUE;
}
-const char *mh_host_get_uuid(void)
+const char *
+mh_host_get_uuid(void)
{
return mh_uuid();
}
-const char *mh_host_get_hostname(void)
+const char *
+mh_host_get_hostname(void)
{
return mh_hostname();
}
-const char *mh_host_get_operating_system(void)
+const char *
+mh_host_get_operating_system(void)
{
static const char *operating_system = NULL;
init();
- if(operating_system == NULL) {
+ if (operating_system == NULL) {
sigar_sys_info_t sysinfo;
sigar_sys_info_get(host_init.sigar, &sysinfo);
- operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name, sysinfo.version);
+ operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name,
+ sysinfo.version);
}
return operating_system;
}
-int mh_host_get_cpu_wordsize(void)
+int
+mh_host_get_cpu_wordsize(void)
{
return (int)(CHAR_BIT * sizeof(size_t));
}
-const char *mh_host_get_architecture(void)
+const char *
+mh_host_get_architecture(void)
{
static const char *arch = NULL;
init();
- if(arch == NULL) {
+ if (arch == NULL) {
sigar_sys_info_t sysinfo;
sigar_sys_info_get(host_init.sigar, &sysinfo);
@@ -121,52 +129,61 @@ const char *mh_host_get_architecture(void)
return arch;
}
-void mh_host_reboot(void)
+void
+mh_host_reboot(void)
{
host_os_reboot();
}
-void mh_host_shutdown(void)
+void
+mh_host_shutdown(void)
{
host_os_shutdown();
}
-const char *mh_host_get_cpu_model(void)
+const char *
+mh_host_get_cpu_model(void)
{
host_get_cpu_details();
return cpuinfo.model;
}
-const char *mh_host_get_cpu_flags(void)
+const char *
+mh_host_get_cpu_flags(void)
{
return host_os_get_cpu_flags();
}
-int mh_host_get_cpu_count(void)
+int
+mh_host_get_cpu_count(void)
{
host_get_cpu_details();
return cpuinfo.cpus;
}
-int mh_host_get_cpu_number_of_cores(void)
+int
+mh_host_get_cpu_number_of_cores(void)
{
host_get_cpu_details();
return cpuinfo.cores;
}
-void mh_host_get_load_averages(sigar_loadavg_t *avg)
+void
+mh_host_get_load_averages(sigar_loadavg_t *avg)
{
init();
sigar_loadavg_get(host_init.sigar, avg);
}
-void mh_host_get_processes(sigar_proc_stat_t *procs)
+void
+mh_host_get_processes(sigar_proc_stat_t *procs)
{
init();
sigar_proc_stat_get(host_init.sigar, procs);
}
-uint64_t mh_host_get_memory(void)
+uint64_t
+mh_host_get_memory(void)
{
sigar_mem_t mem;
uint64_t total;
@@ -177,7 +194,8 @@ uint64_t mh_host_get_memory(void)
return total;
}
-uint64_t mh_host_get_mem_free(void)
+uint64_t
+mh_host_get_mem_free(void)
{
sigar_mem_t mem;
uint64_t free;
@@ -188,7 +206,8 @@ uint64_t mh_host_get_mem_free(void)
return free;
}
-uint64_t mh_host_get_swap(void)
+uint64_t
+mh_host_get_swap(void)
{
sigar_swap_t swap;
uint64_t total;
@@ -199,7 +218,8 @@ uint64_t mh_host_get_swap(void)
return total;
}
-uint64_t mh_host_get_swap_free(void)
+uint64_t
+mh_host_get_swap_free(void)
{
sigar_swap_t swap;
uint64_t free;
@@ -210,12 +230,13 @@ uint64_t mh_host_get_swap_free(void)
return free;
}
-static void host_get_cpu_details(void)
+static void
+host_get_cpu_details(void)
{
int lpc = 0;
sigar_cpu_info_list_t cpus;
- if(cpuinfo.cpus) {
+ if (cpuinfo.cpus) {
return;
}
@@ -223,9 +244,9 @@ static void host_get_cpu_details(void)
sigar_cpu_info_list_get(host_init.sigar, &cpus);
cpuinfo.cpus = cpus.number;
- for(lpc = 0; lpc < cpus.number; lpc++) {
+ for (lpc = 0; lpc < cpus.number; lpc++) {
sigar_cpu_info_t *cpu = (sigar_cpu_info_t *) cpus.data;
- if(cpuinfo.model == NULL) {
+ if (cpuinfo.model == NULL) {
cpuinfo.model = g_strdup(cpu->model);
}
cpuinfo.cores += cpu->total_cores;
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 96e1303..6c1babd 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -35,7 +35,8 @@
#include "matahari/host.h"
#include "host_private.h"
-const char *host_os_get_cpu_flags(void)
+const char *
+host_os_get_cpu_flags(void)
{
static const char regexstr[] = "(.*\\S)\\s*:\\s*(\\S.*)";
static char *flags = NULL;
@@ -75,7 +76,7 @@ const char *host_os_get_cpu_flags(void)
regex = pcre_compile(regexstr, 0, &pcre_error, &pcre_error_offset, NULL);
if (!regex) {
mh_err("Unable to compile regular expression '%s' at offset %d: %s",
- regexstr, pcre_error_offset, pcre_error);
+ regexstr, pcre_error_offset, pcre_error);
goto done;
}
@@ -87,8 +88,8 @@ const char *host_os_get_cpu_flags(void)
int found[9];
match = pcre_exec(regex, NULL, cur, strlen(cur),
- 0, PCRE_NOTEMPTY, found,
- sizeof(found) / sizeof(found[0]));
+ 0, PCRE_NOTEMPTY, found,
+ sizeof(found) / sizeof(found[0]));
if (match != expected || strncmp(cur + found[2], "flags", 5)) {
continue;
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index 55fd775..0994536 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -5,16 +5,16 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ */
/**
* \file
@@ -31,10 +31,13 @@
#include <glib.h>
-extern const char *host_os_get_cpu_flags(void);
+extern const char *
+host_os_get_cpu_flags(void);
-extern void host_os_reboot(void);
+extern void
+host_os_reboot(void);
-extern void host_os_shutdown(void);
+extern void
+host_os_shutdown(void);
#endif /* __MH_HOST_PRIVATE_H__ */
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index 90cb7f4..e86ff47 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -47,15 +47,15 @@ static void
get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp)
{
OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
- &tkp.Privileges[0].Luid);
+ &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(token, FALSE, &tkp, 0,
- (PTOKEN_PRIVILEGES)NULL, 0);
+ (PTOKEN_PRIVILEGES) NULL, 0);
}
void
@@ -66,7 +66,7 @@ host_os_reboot(void)
get_token_priv(token, tkp);
ExitWindowsEx(EWX_REBOOT | EWX_FORCE,
- SHTDN_REASON_FLAG_PLANNED);
+ SHTDN_REASON_FLAG_PLANNED);
}
void
@@ -77,5 +77,5 @@ host_os_shutdown(void)
get_token_priv(token, tkp);
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
- SHTDN_REASON_FLAG_PLANNED);
+ SHTDN_REASON_FLAG_PLANNED);
}
diff --git a/src/lib/mainloop.c b/src/lib/mainloop.c
index d3426a4..1b2e276 100644
--- a/src/lib/mainloop.c
+++ b/src/lib/mainloop.c
@@ -51,12 +51,13 @@ mainloop_trigger_check(GSource *source)
}
static gboolean
-mainloop_trigger_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
+mainloop_trigger_dispatch(GSource *source, GSourceFunc callback,
+ gpointer userdata)
{
mainloop_trigger_t *trig = (mainloop_trigger_t *) source;
trig->trigger = FALSE;
- if(callback) {
+ if (callback) {
return callback(trig->user_data);
}
return TRUE;
@@ -81,7 +82,7 @@ mainloop_setup_trigger(GSource *source, int priority,
trigger->trigger = FALSE;
trigger->user_data = userdata;
- if(dispatch) {
+ if (dispatch) {
g_source_set_callback(source, dispatch, trigger, NULL);
}
@@ -134,13 +135,13 @@ static gboolean
mainloop_signal_dispatch(GSource *source, GSourceFunc callback,
gpointer userdata)
{
- mainloop_signal_t *sig = (mainloop_signal_t*)source;
+ mainloop_signal_t *sig = (mainloop_signal_t *) source;
#if __linux__
mh_info("Invoking handler for signal %d: %s",
- sig->signal, strsignal(sig->signal));
+ sig->signal, strsignal(sig->signal));
#endif
sig->trigger.trigger = FALSE;
- if(sig->handler) {
+ if (sig->handler) {
sig->handler(sig->signal);
}
return TRUE;
@@ -149,8 +150,8 @@ mainloop_signal_dispatch(GSource *source, GSourceFunc callback,
static void
mainloop_signal_handler(int sig)
{
- if(sig > 0 && sig < NSIG && mainloop_signals[sig] != NULL) {
- mainloop_set_trigger((mainloop_trigger_t*)mainloop_signals[sig]);
+ if (sig > 0 && sig < NSIG && mainloop_signals[sig] != NULL) {
+ mainloop_set_trigger((mainloop_trigger_t *) mainloop_signals[sig]);
}
}
@@ -169,7 +170,7 @@ mainloop_signal(int sig, void (*dispatch)(int sig))
struct sigaction sa;
struct sigaction old;
- if(sigemptyset(&mask) < 0) {
+ if (sigemptyset(&mask) < 0) {
mh_perror(LOG_ERR, "Call to sigemptyset failed");
return FALSE;
}
@@ -178,8 +179,9 @@ mainloop_signal(int sig, void (*dispatch)(int sig))
sa.sa_flags = SA_RESTART;
sa.sa_mask = mask;
- if(sigaction(sig, &sa, &old) < 0) {
- mh_perror(LOG_ERR, "Could not install signal handler for signal %d", sig);
+ if (sigaction(sig, &sa, &old) < 0) {
+ mh_perror(LOG_ERR, "Could not install signal handler for signal %d",
+ sig);
return FALSE;
}
@@ -195,7 +197,7 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
{
GSource *source = NULL;
int priority = G_PRIORITY_HIGH - 1;
- if(sig == SIGTERM) {
+ if (sig == SIGTERM) {
/* TERM is higher priority than other signals,
* signals are higher priority than other ipc.
* Yes, minus: smaller is "higher"
@@ -203,11 +205,11 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
priority--;
}
- if(sig >= NSIG || sig < 0) {
+ if (sig >= NSIG || sig < 0) {
mh_err("Signal %d is out of range", sig);
return FALSE;
- } else if(mainloop_signals[sig] != NULL) {
+ } else if (mainloop_signals[sig] != NULL) {
mh_err("Signal handler for %d is already installed", sig);
return FALSE;
}
@@ -215,19 +217,20 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
MH_ASSERT(sizeof(mainloop_signal_t) > sizeof(GSource));
source = g_source_new(&mainloop_signal_funcs, sizeof(mainloop_signal_t));
- mainloop_signals[sig] = (mainloop_signal_t*)mainloop_setup_trigger(source, priority, NULL, NULL);
- if(mainloop_signals[sig] == NULL) {
+ mainloop_signals[sig] = (mainloop_signal_t *) mainloop_setup_trigger(
+ source, priority, NULL, NULL);
+ if (mainloop_signals[sig] == NULL) {
return FALSE;
}
mainloop_signals[sig]->handler = dispatch;
mainloop_signals[sig]->signal = sig;
- if(mainloop_signal(sig, mainloop_signal_handler) == FALSE) {
+ if (mainloop_signal(sig, mainloop_signal_handler) == FALSE) {
mainloop_signal_t *tmp = mainloop_signals[sig];
mainloop_signals[sig] = NULL;
- mainloop_destroy_trigger((mainloop_trigger_t*)tmp);
+ mainloop_destroy_trigger((mainloop_trigger_t *) tmp);
return FALSE;
}
@@ -239,21 +242,22 @@ mainloop_destroy_signal(int sig)
{
mainloop_signal_t *tmp = NULL;
- if(sig >= NSIG || sig < 0) {
+ if (sig >= NSIG || sig < 0) {
mh_err("Signal %d is out of range", sig);
return FALSE;
- } else if(mainloop_signal(sig, NULL) == FALSE) {
- mh_perror(LOG_ERR, "Could not uninstall signal handler for signal %d", sig);
+ } else if (mainloop_signal(sig, NULL) == FALSE) {
+ mh_perror(LOG_ERR, "Could not uninstall signal handler for signal %d",
+ sig);
return FALSE;
- } else if(mainloop_signals[sig] == NULL) {
+ } else if (mainloop_signals[sig] == NULL) {
return TRUE;
}
tmp = mainloop_signals[sig];
mainloop_signals[sig] = NULL;
- mainloop_destroy_trigger((mainloop_trigger_t*)tmp);
+ mainloop_destroy_trigger((mainloop_trigger_t *) tmp);
return TRUE;
}
@@ -326,15 +330,16 @@ mainloop_add_fd(int priority, int fd,
source = g_source_new(&mainloop_fd_funcs, sizeof(mainloop_fd_t));
MH_ASSERT(source != NULL);
- fd_source = (mainloop_fd_t*)source;
+ fd_source = (mainloop_fd_t *) source;
fd_source->id = 0;
fd_source->gpoll.fd = fd;
fd_source->gpoll.events = G_IO_ERR|G_IO_NVAL|G_IO_IN|G_IO_PRI|G_IO_HUP;
fd_source->gpoll.revents = 0;
/*
- * Normally we'd use g_source_set_callback() to specify the dispatch function,
- * But we want to supply the fd too, so we store it in fd_source->dispatch instead
+ * Normally we'd use g_source_set_callback() to specify the dispatch
+ * function, but we want to supply the fd too, so we store it in
+ * fd_source->dispatch instead
*/
fd_source->dnotify = notify;
fd_source->dispatch = dispatch;
@@ -351,10 +356,10 @@ mainloop_add_fd(int priority, int fd,
gboolean
mainloop_destroy_fd(mainloop_fd_t *source)
{
- g_source_remove_poll((GSource*)source, &source->gpoll);
+ g_source_remove_poll((GSource *) source, &source->gpoll);
g_source_remove(source->id);
source->id = 0;
- g_source_unref((GSource*)source);
+ g_source_unref((GSource *) source);
return TRUE;
}
@@ -363,7 +368,8 @@ static gboolean
child_timeout_callback(gpointer p)
{
pid_t pid = (pid_t) GPOINTER_TO_INT(p);
- mainloop_child_t *pinfo = (mainloop_child_t *) g_hash_table_lookup(mainloop_process_table, p);
+ mainloop_child_t *pinfo = (mainloop_child_t *) g_hash_table_lookup(
+ mainloop_process_table, p);
if (pinfo == NULL) {
return FALSE;
@@ -398,7 +404,7 @@ child_timeout_callback(gpointer p)
void
mainloop_add_child(pid_t pid, int timeout, const char *desc, void * privatedata,
void (*callback)(mainloop_child_t *p, int status, int signo,
- int exitcode))
+ int exitcode))
{
mainloop_child_t *p = g_new(mainloop_child_t, 1);
@@ -414,7 +420,7 @@ mainloop_add_child(pid_t pid, int timeout, const char *desc, void * privatedata,
p->privatedata = privatedata;
p->callback = callback;
- if(timeout) {
+ if (timeout) {
p->timerid = g_timeout_add(
timeout, child_timeout_callback, GINT_TO_POINTER(pid));
}
@@ -427,12 +433,13 @@ static void
child_death_dispatch(int sig)
{
int status = 0;
- while(TRUE) {
+ while (TRUE) {
pid_t pid = wait3(&status, WNOHANG, NULL);
if (pid > 0) {
- int signo = 0, exitcode = 0;
+ int signo = 0, exitcode = 0;
- mainloop_child_t *p = g_hash_table_lookup(mainloop_process_table, GINT_TO_POINTER(pid));
+ mainloop_child_t *p = g_hash_table_lookup(mainloop_process_table,
+ GINT_TO_POINTER(pid));
mh_trace("Managed process %d exited: %p", pid, p);
if (p == NULL) {
continue;
@@ -440,11 +447,13 @@ child_death_dispatch(int sig)
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
- mh_trace("Managed process %d (%s) exited with rc=%d", pid, p->desc, exitcode);
+ mh_trace("Managed process %d (%s) exited with rc=%d", pid,
+ p->desc, exitcode);
} else if (WIFSIGNALED(status)) {
signo = WTERMSIG(status);
- mh_trace("Managed process %d (%s) exited with signal=%d", pid, p->desc, signo);
+ mh_trace("Managed process %d (%s) exited with signal=%d", pid,
+ p->desc, signo);
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
@@ -462,7 +471,7 @@ child_death_dispatch(int sig)
return;
} else {
- if(errno != ECHILD) {
+ if (errno != ECHILD) {
mh_perror(LOG_ERR, "wait3() failed");
}
break;
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 23f5e3f..2b04857 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -52,33 +52,38 @@ using namespace std;
void
shutdown(int /*signal*/)
{
- exit(0);
+ exit(0);
}
#ifdef WIN32
#define BUFFER_SIZE 1024
static void
-RegistryRead (HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue, char **out)
+RegistryRead(HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue,
+ char **out)
{
HKEY hKey;
DWORD nSize = BUFFER_SIZE;
wchar_t szData[BUFFER_SIZE];
- long lSuccess = RegOpenKey (hHive, szKeyPath, &hKey);
+ long lSuccess = RegOpenKey(hHive, szKeyPath, &hKey);
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not open %ls key from the registry: %ld", szKeyPath, lSuccess);
+ mh_debug("Could not open %ls key from the registry: %ld", szKeyPath,
+ lSuccess);
return;
}
- lSuccess = RegQueryValueEx (hKey, szValue, NULL, NULL, (LPBYTE) szData, &nSize);
+ lSuccess = RegQueryValueEx(hKey, szValue, NULL, NULL, (LPBYTE) szData,
+ &nSize);
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not read '%ls[%ls]' from the registry: %ld", szKeyPath, szValue, lSuccess);
+ mh_debug("Could not read '%ls[%ls]' from the registry: %ld", szKeyPath,
+ szValue, lSuccess);
return;
}
- mh_info("Obtained '%ls[%ls]' = '%ls' from the registry", szKeyPath, szValue, szData);
- if(out) {
- *out = (char *)malloc( BUFFER_SIZE );
- wcstombs(*out, szData, (size_t)BUFFER_SIZE);
+ mh_info("Obtained '%ls[%ls]' = '%ls' from the registry", szKeyPath, szValue,
+ szData);
+ if (out) {
+ *out = (char *) malloc(BUFFER_SIZE);
+ wcstombs(*out, szData, (size_t) BUFFER_SIZE);
}
}
#else
@@ -103,20 +108,24 @@ print_usage(const char *proc_name)
printf("\t-h | --help print this help message.\n");
printf("\t-b | --broker specify broker host name..\n");
printf("\t-g | --gssapi force GSSAPI authentication.\n");
- printf("\t-u | --username username to use for authentication purproses.\n");
- printf("\t-P | --password password to use for authentication purproses.\n");
- printf("\t-s | --service service name to use for authentication purproses.\n");
+ printf("\t-u | --username username to use for authentication "
+ "purproses.\n");
+ printf("\t-P | --password password to use for authentication "
+ "purproses.\n");
+ printf("\t-s | --service service name to use for authentication "
+ "purproses.\n");
printf("\t-p | --port specify broker port.\n");
printf("\t-r | --reconnect attempt to reconnect on failure.\n");
}
#endif
static gboolean
-mh_qpid_callback(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+mh_qpid_callback(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
MatahariAgent *agent = (MatahariAgent*) user_data;
mh_trace("Qpid message recieved");
- if(event.hasDataAddr()) {
+ if (event.hasDataAddr()) {
mh_trace("Message is for %s (type: %s)",
event.getDataAddr().getName().c_str(),
event.getDataAddr().getAgentName().c_str());
@@ -160,8 +169,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
L"DebugLevel",
&value);
- if(value) {
- mh_log_level = LOG_INFO+atoi(value);
+ if (value) {
+ mh_log_level = LOG_INFO + atoi(value);
free(value);
value = NULL;
}
@@ -178,7 +187,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
L"Port",
&value);
- if(value) {
+ if (value) {
serverport = atoi(value);
free(value);
value = NULL;
@@ -290,7 +299,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
// Set up the cleanup handler for sigint
signal(SIGINT, shutdown);
- mh_info("Connecting to Qpid broker at %s on port %d", servername, serverport);
+ mh_info("Connecting to Qpid broker at %s on port %d", servername,
+ serverport);
// Create a v2 API options map.
qpid::types::Variant::Map options;
@@ -309,7 +319,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
}
std::stringstream url;
- url << servername << ":" << serverport ;
+ url << servername << ":" << serverport;
_amqp_connection = qpid::messaging::Connection(url.str(), options);
_amqp_connection.open();
@@ -321,7 +331,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
_agent_session.open();
/* Do any setup required by our agent */
- if(this->setup(_agent_session) < 0) {
+ if (this->setup(_agent_session) < 0) {
mh_err("Failed to set up broker connection to %s on %d for %s\n",
servername, serverport, proc_name);
res = -1;
@@ -329,8 +339,9 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
}
this->mainloop = g_main_new(FALSE);
- this->qpid_source = mainloop_add_qmf(
- G_PRIORITY_HIGH, _agent_session, mh_qpid_callback, mh_qpid_disconnect, this);
+ this->qpid_source = mainloop_add_qmf(G_PRIORITY_HIGH, _agent_session,
+ mh_qpid_callback, mh_qpid_disconnect,
+ this);
return_cleanup:
@@ -352,7 +363,7 @@ MatahariAgent::run()
static gboolean
mainloop_qmf_prepare(GSource* source, gint *timeout)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
if (qmf->event) {
return TRUE;
}
@@ -364,11 +375,12 @@ mainloop_qmf_prepare(GSource* source, gint *timeout)
static gboolean
mainloop_qmf_check(GSource* source)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
if (qmf->event) {
return TRUE;
- } else if(qmf->session.nextEvent(qmf->event, qpid::messaging::Duration::IMMEDIATE)) {
+ } else if (qmf->session.nextEvent(qmf->event,
+ qpid::messaging::Duration::IMMEDIATE)) {
return TRUE;
}
return FALSE;
@@ -377,13 +389,13 @@ mainloop_qmf_check(GSource* source)
static gboolean
mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
mh_trace("%p", source);
if (qmf->dispatch != NULL) {
qmf::AgentEvent event = qmf->event;
qmf->event = NULL;
- if(qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
+ if (qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
g_source_unref(source); /* Really? */
return FALSE;
}
@@ -393,9 +405,9 @@ mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
}
static void
-mainloop_qmf_destroy(GSource* source)
+mainloop_qmf_destroy(GSource *source)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
mh_trace("%p", source);
if (qmf->dnotify) {
@@ -410,10 +422,11 @@ static GSourceFuncs mainloop_qmf_funcs = {
mainloop_qmf_destroy,
};
-mainloop_qmf_t*
+mainloop_qmf_t *
mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
- GDestroyNotify notify, gpointer userdata)
+ gboolean (*dispatch)(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata)
{
GSource *source = NULL;
mainloop_qmf_t *qmf_source = NULL;
@@ -421,14 +434,15 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
source = g_source_new(&mainloop_qmf_funcs, sizeof(mainloop_qmf_t));
MH_ASSERT(source != NULL);
- qmf_source = (mainloop_qmf_t*)source;
+ qmf_source = (mainloop_qmf_t *) source;
qmf_source->id = 0;
qmf_source->event = NULL;
qmf_source->session = session;
/*
- * Normally we'd use g_source_set_callback() to specify the dispatch function,
- * But we want to supply the qmf session too, so we store it in qmf_source->dispatch instead
+ * Normally we'd use g_source_set_callback() to specify the dispatch
+ * function, but we want to supply the qmf session too, so we store it in
+ * qmf_source->dispatch instead
*/
qmf_source->dnotify = notify;
qmf_source->dispatch = dispatch;
@@ -443,11 +457,11 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
}
gboolean
-mainloop_destroy_qmf(mainloop_qmf_t* source)
+mainloop_destroy_qmf(mainloop_qmf_t *source)
{
g_source_remove(source->id);
source->id = 0;
- g_source_unref((GSource*)source);
+ g_source_unref((GSource *) source);
return TRUE;
}
diff --git a/src/lib/mh_dbus_common.c b/src/lib/mh_dbus_common.c
index d975ece..a58c8a1 100644
--- a/src/lib/mh_dbus_common.c
+++ b/src/lib/mh_dbus_common.c
@@ -36,126 +36,107 @@ const DBusGObjectInfo dbus_glib_matahari_object_info;
GQuark
matahari_error_quark (void)
{
- return g_quark_from_static_string ("matahari-error-quark");
+ return g_quark_from_static_string ("matahari-error-quark");
}
gboolean
-check_authorization(const gchar *action, GError** error, DBusGMethodInvocation *context)
+check_authorization(const gchar *action, GError** error,
+ DBusGMethodInvocation *context)
{
- GError *err;
- PolkitAuthorizationResult *result;
- PolkitSubject *subject;
- PolkitAuthority *authority;
- gboolean res;
-
- if (context == NULL)
- {
- g_printerr("Context is not set!\n");
- return FALSE;
- }
- err = NULL;
- subject = polkit_system_bus_name_new(dbus_g_method_get_sender(context));
- authority = polkit_authority_get_sync(NULL, &err);
- if (err != NULL)
- {
- g_printerr("Error in obtaining authority: %s\n", err->message);
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, err->message);
- g_error_free(err);
- return FALSE;
- }
-
- result = polkit_authority_check_authorization_sync(authority, subject, action, NULL, POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, NULL, &err);
- if (err != NULL)
- {
- g_printerr("Error in checking authorization: %s\n", err->message);
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, err->message);
- g_error_free(err);
- return FALSE;
- }
- res = polkit_authorization_result_get_is_authorized(result);
- g_object_unref(subject);
- g_object_unref(result);
- g_object_unref(authority);
- if (!res)
- {
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, "You are not authorized for specified action");
- g_printerr("Caller is not authorized for action %s\n", action);
- }
- return res;
+ GError *err;
+ PolkitAuthorizationResult *result;
+ PolkitSubject *subject;
+ PolkitAuthority *authority;
+ gboolean res;
+
+ if (context == NULL) {
+ g_printerr("Context is not set!\n");
+ return FALSE;
+ }
+ err = NULL;
+ subject = polkit_system_bus_name_new(dbus_g_method_get_sender(context));
+ authority = polkit_authority_get_sync(NULL, &err);
+ if (err != NULL) {
+ g_printerr("Error in obtaining authority: %s\n", err->message);
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ err->message);
+ g_error_free(err);
+ return FALSE;
+ }
+
+ result = polkit_authority_check_authorization_sync(authority, subject,
+ action, NULL,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, NULL,
+ &err);
+ if (err != NULL) {
+ g_printerr("Error in checking authorization: %s\n", err->message);
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ err->message);
+ g_error_free(err);
+ return FALSE;
+ }
+ res = polkit_authorization_result_get_is_authorized(result);
+ g_object_unref(subject);
+ g_object_unref(result);
+ g_object_unref(authority);
+ if (!res) {
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ "You are not authorized for specified action");
+ g_printerr("Caller is not authorized for action %s\n", action);
+ }
+ return res;
}
gboolean
get_paramspec_from_property(Property prop, GParamSpec** pspec)
{
GType value_type;
- switch (prop.type)
- {
- case 's':
- *pspec = g_param_spec_string(prop.name,
- prop.nick,
- prop.desc,
- NULL,
- prop.flags);
- break;
- case 'b':
- *pspec = g_param_spec_boolean(prop.name,
- prop.nick,
- prop.desc,
- FALSE,
- prop.flags);
- break;
- case 'n':
- case 'i':
- *pspec = g_param_spec_int(prop.name,
- prop.nick,
- prop.desc,
- G_MININT, G_MAXINT, 0,
+ switch (prop.type) {
+ case 's':
+ *pspec = g_param_spec_string(prop.name, prop.nick, prop.desc,
+ NULL, prop.flags);
+ break;
+ case 'b':
+ *pspec = g_param_spec_boolean(prop.name, prop.nick, prop.desc,
+ FALSE, prop.flags);
+ break;
+ case 'n':
+ case 'i':
+ *pspec = g_param_spec_int(prop.name, prop.nick, prop.desc,
+ G_MININT, G_MAXINT, 0, prop.flags);
+ break;
+ case 'x':
+ *pspec = g_param_spec_int64(prop.name, prop.nick, prop.desc,
+ G_MININT64, G_MAXINT64, 0, prop.flags);
+
+ break;
+ case 'y':
+ case 'q':
+ case 'u':
+ *pspec = g_param_spec_uint(prop.name, prop.nick, prop.desc,
+ 0, G_MAXUINT, 0, prop.flags);
+ break;
+ case 't':
+ *pspec = g_param_spec_uint64(prop.name, prop.nick, prop.desc,
+ 0, G_MAXUINT64, 0, prop.flags);
+ break;
+ case 'd':
+ *pspec = g_param_spec_double(prop.name, prop.nick, prop.desc,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
prop.flags);
- break;
- case 'x':
- *pspec = g_param_spec_int64(prop.name,
- prop.nick,
- prop.desc,
- G_MININT64, G_MAXINT64, 0,
- prop.flags);
-
- break;
- case 'y':
- case 'q':
- case 'u':
- *pspec = g_param_spec_uint(prop.name,
- prop.nick,
- prop.desc,
- 0, G_MAXUINT, 0,
- prop.flags);
- break;
- case 't':
- *pspec = g_param_spec_uint64(prop.name,
- prop.nick,
- prop.desc,
- 0, G_MAXUINT64, 0,
- prop.flags);
-
- break;
- case 'd':
- *pspec = g_param_spec_double(prop.name,
- prop.nick,
- prop.desc,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- prop.flags);
- break;
- case 'e':
- // Type is map - key is string, type of value must be added manually!
- value_type = matahari_dict_type(prop.prop);
- *pspec = g_param_spec_boxed(prop.name,
- prop.nick,
- prop.desc,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING, value_type),
- prop.flags);
- break;
- default:
- return FALSE;
+ break;
+ case 'e':
+ // Type is map - key is string, type of value must be added manually!
+ value_type = matahari_dict_type(prop.prop);
+ *pspec = g_param_spec_boxed(prop.name, prop.nick, prop.desc,
+ dbus_g_type_get_map("GHashTable",
+ G_TYPE_STRING,
+ value_type),
+ prop.flags);
+ break;
+ default:
+ return FALSE;
}
return TRUE;
@@ -164,146 +145,143 @@ get_paramspec_from_property(Property prop, GParamSpec** pspec)
int
run_dbus_server(char *bus_name, char *object_path)
{
- GMainLoop* loop = NULL;
- DBusGConnection *connection = NULL;
- GError *error = NULL;
- GObject *obj = NULL;
- DBusGProxy *driver_proxy = NULL;
- guint32 request_name_ret;
-
- mh_log_init(bus_name, LOG_DEBUG, FALSE);
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* Obtain a connection to the system bus */
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!connection)
- {
- g_printerr(_("Failed to open connection to bus: %s\n"), error->message);
- g_error_free(error);
- return 1;
+ GMainLoop* loop = NULL;
+ DBusGConnection *connection = NULL;
+ GError *error = NULL;
+ GObject *obj = NULL;
+ DBusGProxy *driver_proxy = NULL;
+ guint32 request_name_ret;
+
+ mh_log_init(bus_name, LOG_DEBUG, FALSE);
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ // Obtain a connection to the system bus
+ connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!connection) {
+ g_printerr(_("Failed to open connection to bus: %s\n"), error->message);
+ g_error_free(error);
+ return 1;
}
- obj = g_object_new(MATAHARI_TYPE, NULL);
- dbus_g_connection_register_g_object(connection, object_path, obj);
+ obj = g_object_new(MATAHARI_TYPE, NULL);
+ dbus_g_connection_register_g_object(connection, object_path, obj);
- driver_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ driver_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
- if (!org_freedesktop_DBus_request_name(driver_proxy, bus_name, 0,
- &request_name_ret, &error))
- {
- g_printerr(_("Failed to get name: %s\n"), error->message);
- g_error_free(error);
- return 1;
+ if (!org_freedesktop_DBus_request_name(driver_proxy, bus_name, 0,
+ &request_name_ret, &error)) {
+ g_printerr(_("Failed to get name: %s\n"), error->message);
+ g_error_free(error);
+ return 1;
}
- switch (request_name_ret)
- {
- case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
- break;
- case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
- g_printerr(
- _("Looks like another server of this type is already running: Reply in queue\n"));
- return 1;
- case DBUS_REQUEST_NAME_REPLY_EXISTS:
- g_printerr(
- _("Looks like another server of this type is already running: Reply exists\n"));
- return 1;
- case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
- g_printerr(_("We are already running\n"));
- return 1;
- default:
- g_printerr(_("Unspecified error\n"));
- return 1;
+ switch (request_name_ret) {
+ case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+ break;
+ case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+ g_printerr(_("Looks like another server of this type is already "
+ "running: Reply in queue\n"));
+ return 1;
+ case DBUS_REQUEST_NAME_REPLY_EXISTS:
+ g_printerr(_("Looks like another server of this type is already "
+ "running: Reply exists\n"));
+ return 1;
+ case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+ g_printerr(_("We are already running\n"));
+ return 1;
+ default:
+ g_printerr(_("Unspecified error\n"));
+ return 1;
}
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- g_object_unref(obj);
- g_object_unref(driver_proxy);
- return 0;
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ g_object_unref(obj);
+ g_object_unref(driver_proxy);
+ return 0;
}
gboolean
-matahari_get(Matahari* matahari, const char *interface, const char *name, DBusGMethodInvocation *context)
+matahari_get(Matahari* matahari, const char *interface, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- GParamSpec *spec;
- GValue value = {0, };
-
- char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
- sprintf(action, "%s.%s", interface, name);
- if (!check_authorization(action, &error, context))
- {
- dbus_g_method_return_error(context, error);
+ GError* error = NULL;
+ GParamSpec *spec;
+ GValue value = {0, };
+
+ char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
+ sprintf(action, "%s.%s", interface, name);
+ if (!check_authorization(action, &error, context)) {
+ dbus_g_method_return_error(context, error);
+ free(action);
+ return FALSE;
+ }
free(action);
- return FALSE;
- }
- free(action);
-
- spec = g_object_class_find_property(G_OBJECT_GET_CLASS(matahari), name);
- g_value_init(&value, spec->value_type);
- g_object_get_property(G_OBJECT(matahari), name, &value);
- dbus_g_method_return(context, &value);
- return TRUE;
+
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(matahari), name);
+ g_value_init(&value, spec->value_type);
+ g_object_get_property(G_OBJECT(matahari), name, &value);
+ dbus_g_method_return(context, &value);
+ return TRUE;
}
gboolean
-matahari_set(Matahari *matahari, const char *interface, const char *name, GValue *value, DBusGMethodInvocation *context)
+matahari_set(Matahari *matahari, const char *interface, const char *name,
+ GValue *value, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
- sprintf(action, "%s.%s", interface, name);
- if (!check_authorization(action, &error, context))
- {
- dbus_g_method_return_error(context, error);
+ GError* error = NULL;
+ char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
+ sprintf(action, "%s.%s", interface, name);
+ if (!check_authorization(action, &error, context)) {
+ dbus_g_method_return_error(context, error);
+ free(action);
+ return FALSE;
+ }
free(action);
- return FALSE;
- }
- free(action);
- g_object_set_property(G_OBJECT(matahari), name, value);
- dbus_g_method_return(context);
- return TRUE;
+ g_object_set_property(G_OBJECT(matahari), name, value);
+ dbus_g_method_return(context);
+ return TRUE;
}
/* Class init */
static void
matahari_class_init(MatahariClass *matahari_class)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(matahari_class);
- GParamSpec *pspec = NULL;
-
- //g_type_class_add_private(matahari_class, sizeof (MatahariPrivate));
-
- gobject_class->set_property = matahari_set_property;
- gobject_class->get_property = matahari_get_property;
-
- int i;
- for (i = 0; properties[i].name != NULL; i++)
- {
- if (!get_paramspec_from_property(properties[i], &pspec))
- {
- g_printerr("Unknown type: %c\n", properties[i].type);
- pspec = NULL;
+ GObjectClass *gobject_class = G_OBJECT_CLASS(matahari_class);
+ GParamSpec *pspec = NULL;
+
+ gobject_class->set_property = matahari_set_property;
+ gobject_class->get_property = matahari_get_property;
+
+ int i;
+ for (i = 0; properties[i].name != NULL; i++) {
+ if (!get_paramspec_from_property(properties[i], &pspec)) {
+ g_printerr("Unknown type: %c\n", properties[i].type);
+ pspec = NULL;
+ }
+ if (pspec)
+ g_object_class_install_property(gobject_class, properties[i].prop,
+ pspec);
}
- if (pspec)
- g_object_class_install_property(gobject_class, properties[i].prop, pspec);
- }
- dbus_g_object_type_install_info(MATAHARI_TYPE, &dbus_glib_matahari_object_info);
+ dbus_g_object_type_install_info(MATAHARI_TYPE,
+ &dbus_glib_matahari_object_info);
}
/* Instance init */
static void
matahari_init(Matahari *matahari)
{
- MatahariPrivate *priv;
- matahari->priv = priv = MATAHARI_GET_PRIVATE(matahari);
+ MatahariPrivate *priv;
+ matahari->priv = priv = MATAHARI_GET_PRIVATE(matahari);
}
-Dict *dict_new(GValue *value)
+Dict *
+dict_new(GValue *value)
{
gpointer ret;
Dict *dict = malloc(sizeof(Dict));
@@ -318,13 +296,15 @@ Dict *dict_new(GValue *value)
return dict;
}
-void dict_add(Dict *dict, const gchar *key, GValue *value)
+void
+dict_add(Dict *dict, const gchar *key, GValue *value)
{
g_value_set_static_string(dict->key, key);
dbus_g_type_specialized_map_append (&(dict->appendctx), dict->key, value);
}
-void dict_free(Dict *dict)
+void
+dict_free(Dict *dict)
{
free(dict->key);
free(dict);
diff --git a/src/lib/network.c b/src/lib/network.c
index b30fb31..d502d34 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -41,15 +41,15 @@ query_interface_table(void)
sigar_open(&sigar);
status = sigar_net_interface_list_get(sigar, &iflist);
- if(status == SIGAR_OK) {
- for(lpc = 0; lpc < iflist.number; lpc++) {
+ if (status == SIGAR_OK) {
+ for (lpc = 0; lpc < iflist.number; lpc++) {
ifconfig = g_new0(sigar_net_interface_config_t, 1);
- status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
- ifconfig);
- if(status == SIGAR_OK)
+ status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
+ ifconfig);
+ if (status == SIGAR_OK)
interfaces = g_list_prepend(interfaces, ifconfig);
}
- sigar_net_interface_list_destroy(sigar, &iflist);
+ sigar_net_interface_list_destroy(sigar, &iflist);
}
sigar_close(sigar);
return interfaces;
@@ -90,9 +90,9 @@ mh_network_status(const char *iface, uint64_t *flags)
sigar_net_interface_config_t *ifconfig;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
*flags = ifconfig->flags;
}
}
@@ -108,9 +108,9 @@ mh_network_get_ip_address(const char *iface)
char *paddr_str;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
sigar_net_address_to_string(NULL, &ifconfig->address, addr_str);
paddr_str = g_strdup(addr_str);
return paddr_str;
@@ -128,9 +128,9 @@ mh_network_get_mac_address(const char *iface)
char *mac;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
mac = g_strdup_printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
ifconfig->hwaddr.addr.mac[0],
ifconfig->hwaddr.addr.mac[1],
diff --git a/src/lib/network_linux.c b/src/lib/network_linux.c
index 23c9595..0bfd8a0 100644
--- a/src/lib/network_linux.c
+++ b/src/lib/network_linux.c
@@ -32,8 +32,9 @@ network_os_start(const char *iface)
"/sbin/ifup", (gchar *) iface, NULL
};
- ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
- if(ret == FALSE) {
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
+ &error);
+ if (ret == FALSE) {
g_error_free(error);
}
}
@@ -47,8 +48,9 @@ network_os_stop(const char *iface)
"/sbin/ifdown", (gchar *) iface, NULL
};
- ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
- if(ret == FALSE) {
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
+ &error);
+ if (ret == FALSE) {
g_error_free(error);
}
}
diff --git a/src/lib/network_private.h b/src/lib/network_private.h
index 04ba74f..859e63d 100644
--- a/src/lib/network_private.h
+++ b/src/lib/network_private.h
@@ -5,16 +5,16 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ */
#include <glib.h>
diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c
index d735ef3..8e017ad 100644
--- a/src/lib/network_windows.c
+++ b/src/lib/network_windows.c
@@ -40,7 +40,8 @@ network_os_stop(const char *iface)
char *exe_path;
p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s disabled", p, iface);
+ exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface "
+ "%s disabled", p, iface);
gboolean ok = CreateProcess(NULL,
exe_path,
@@ -67,7 +68,8 @@ network_os_start(const char *iface)
char *exe_path;
p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s enabled", p, iface);
+ exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface "
+ "%s enabled", p, iface);
gboolean ok = CreateProcess(NULL,
exe_path,
diff --git a/src/lib/services.c b/src/lib/services.c
index fc20165..5c33cae 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,8 +34,9 @@ MH_TRACE_INIT_DATA(mh_services);
GHashTable *recurring_actions = NULL;
-svc_action_t *services_action_create(
- const char *name, const char *action, int interval, int timeout)
+svc_action_t *
+services_action_create(const char *name, const char *action, int interval,
+ int timeout)
{
svc_action_t *op;
@@ -54,9 +55,10 @@ svc_action_t *services_action_create(
return op;
}
-svc_action_t *resources_action_create(
- const char *name, const char *provider, const char *agent,
- const char *action, int interval, int timeout, GHashTable *params)
+svc_action_t *
+resources_action_create(const char *name, const char *provider,
+ const char *agent, const char *action, int interval,
+ int timeout, GHashTable *params)
{
svc_action_t *op;
@@ -71,17 +73,18 @@ svc_action_t *resources_action_create(
op->provider = strdup(provider);
op->params = params;
asprintf(&op->id, "%s_%s_%d", name, action, interval);
- asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT,
- provider, agent);
+ asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT, provider,
+ agent);
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(action);
return op;
}
-void services_action_free(svc_action_t *op)
+void
+services_action_free(svc_action_t *op)
{
- if(op == NULL) {
+ if (op == NULL) {
return;
}
@@ -103,7 +106,7 @@ void services_action_free(svc_action_t *op)
free(op->stdout_data);
free(op->stderr_data);
- if(op->params) {
+ if (op->params) {
g_hash_table_destroy(op->params);
op->params = NULL;
}
@@ -111,7 +114,8 @@ void services_action_free(svc_action_t *op)
free(op);
}
-gboolean services_action_cancel(const char *name, const char *action, int interval)
+gboolean
+services_action_cancel(const char *name, const char *action, int interval)
{
svc_action_t* op = NULL;
char id[512];
@@ -124,7 +128,7 @@ gboolean services_action_cancel(const char *name, const char *action, int interv
op->opaque->cancel = TRUE;
mh_debug("Removing %s", op->id);
- if(op->opaque->repeat_timer) {
+ if (op->opaque->repeat_timer) {
g_source_remove(op->opaque->repeat_timer);
}
services_action_free(op);
@@ -133,18 +137,18 @@ gboolean services_action_cancel(const char *name, const char *action, int interv
}
gboolean
-services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t*))
+services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t *))
{
- if(action_callback) {
+ if (action_callback) {
op->opaque->callback = action_callback;
}
- if(recurring_actions == NULL) {
- recurring_actions = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, NULL);
+ if (recurring_actions == NULL) {
+ recurring_actions = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, NULL);
}
- if(op->interval > 0) {
+ if (op->interval > 0) {
g_hash_table_replace(recurring_actions, op->id, op);
}
@@ -155,11 +159,12 @@ gboolean
services_action_sync(svc_action_t* op)
{
gboolean rc = services_os_action_execute(op, TRUE);
- mh_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action, op->interval, op->opaque->exec, op->rc);
- if(op->stdout_data) {
+ mh_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action, op->interval,
+ op->opaque->exec, op->rc);
+ if (op->stdout_data) {
mh_trace(" > stdout: %s", op->stdout_data);
}
- if(op->stderr_data) {
+ if (op->stderr_data) {
mh_trace(" > stderr: %s", op->stderr_data);
}
return rc;
@@ -171,18 +176,20 @@ get_directory_list(const char *root, gboolean files)
return services_os_get_directory_list(root, files);
}
-GList *services_list(void)
+GList *
+services_list(void)
{
return services_os_list();
}
-GList *resources_list_ocf_providers(void)
+GList *
+resources_list_ocf_providers(void)
{
return resources_os_list_ocf_providers();
}
-GList *resources_list_ocf_agents(const char *provider)
+GList *
+resources_list_ocf_agents(const char *provider)
{
return resources_os_list_ocf_agents(provider);
}
-
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 3a54386..de1e014 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -38,7 +38,7 @@ set_fd_opts(int fd, int opts)
{
int flag;
if ((flag = fcntl(fd, F_GETFL)) >= 0) {
- if (fcntl(fd, F_SETFL, flag|opts) < 0) {
+ if (fcntl(fd, F_SETFL, flag | opts) < 0) {
mh_perror(LOG_ERR, "fcntl() write failed");
}
} else {
@@ -52,30 +52,30 @@ read_output(int fd, gpointer user_data)
char * data = NULL;
int rc = 0, len = 0;
gboolean is_err = FALSE;
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
char buf[500];
static const size_t buf_read_len = sizeof(buf) - 1;
- if(fd == op->opaque->stderr_fd) {
+ if (fd == op->opaque->stderr_fd) {
is_err = TRUE;
- if(op->stderr_data) {
+ if (op->stderr_data) {
len = strlen(op->stderr_data);
data = op->stderr_data;
}
- } else if(op->stdout_data) {
+ } else if (op->stdout_data) {
len = strlen(op->stdout_data);
data = op->stdout_data;
}
do {
rc = read(fd, buf, buf_read_len);
- if(rc > 0) {
+ if (rc > 0) {
buf[rc] = 0;
data = realloc(data, len + rc + 1);
- sprintf(data+len, "%s", buf);
+ sprintf(data + len, "%s", buf);
len += rc;
- } else if(errno != EINTR) {
+ } else if (errno != EINTR) {
/* error or EOF
* Cleanup happens in pipe_done()
*/
@@ -87,7 +87,7 @@ read_output(int fd, gpointer user_data)
if (data != NULL && is_err) {
op->stderr_data = data;
- } else if(data != NULL) {
+ } else if (data != NULL) {
op->stdout_data = data;
}
@@ -97,7 +97,7 @@ read_output(int fd, gpointer user_data)
static void
pipe_out_done(gpointer user_data)
{
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
op->opaque->stdout_gsource = NULL;
if (op->opaque->stdout_fd > STDERR_FILENO) {
close(op->opaque->stdout_fd);
@@ -108,7 +108,7 @@ pipe_out_done(gpointer user_data)
static void
pipe_err_done(gpointer user_data)
{
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
op->opaque->stderr_gsource = NULL;
if (op->opaque->stderr_fd > STDERR_FILENO) {
close(op->opaque->stderr_fd);
@@ -129,7 +129,7 @@ set_ocf_env_with_prefix(gpointer key, gpointer value, gpointer user_data)
{
/* TODO: Add OCF_RESKEY_ prefix to 'key' */
char buffer[500];
- snprintf(buffer, sizeof(buffer), "OCF_RESKEY_%s", (char*)key);
+ snprintf(buffer, sizeof(buffer), "OCF_RESKEY_%s", (char *) key);
set_ocf_env(buffer, value, user_data);
}
@@ -140,7 +140,7 @@ add_OCF_env_vars(svc_action_t *op)
return;
}
- if(op->params) {
+ if (op->params) {
g_hash_table_foreach(op->params, set_ocf_env_with_prefix, NULL);
}
@@ -148,7 +148,7 @@ add_OCF_env_vars(svc_action_t *op)
set_ocf_env("OCF_RA_VERSION_MINOR", "0", NULL);
set_ocf_env("OCF_ROOT", OCF_ROOT, NULL);
- if(op->rsc) {
+ if (op->rsc) {
set_ocf_env("OCF_RESOURCE_INSTANCE", op->rsc, NULL);
}
@@ -186,13 +186,15 @@ operation_finished(mainloop_child_t *p, int status, int signo, int exitcode)
op->status = LRM_OP_DONE;
MH_ASSERT(op->pid == p->pid);
- if( signo ) {
- if( p->timeout ) {
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid, op->timeout);
+ if (signo) {
+ if (p->timeout) {
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
+ op->timeout);
op->status = LRM_OP_TIMEOUT;
} else {
- mh_warn("%s:%d - terminated with signal %d", op->id, op->pid, signo);
+ mh_warn("%s:%d - terminated with signal %d", op->id, op->pid,
+ signo);
op->status = LRM_OP_ERROR;
}
@@ -200,45 +202,50 @@ operation_finished(mainloop_child_t *p, int status, int signo, int exitcode)
op->rc = exitcode;
mh_debug("%s:%d - exited with rc=%d", op->id, op->pid, exitcode);
- if(op->stdout_data) {
+ if (op->stdout_data) {
next = op->stdout_data;
do {
offset = next;
next = strchrnul(offset, '\n');
- mh_debug("%s:%d [ %.*s ]", op->id, op->pid, (int)(next-offset), offset);
- if(next[0] != 0) {
+ mh_debug("%s:%d [ %.*s ]", op->id, op->pid,
+ (int) (next - offset), offset);
+ if (next[0] != 0) {
next++;
}
- } while(next != NULL && next[0] != 0);
+ } while (next != NULL && next[0] != 0);
}
- if(op->stderr_data) {
+ if (op->stderr_data) {
next = op->stderr_data;
do {
offset = next;
next = strchrnul(offset, '\n');
- mh_notice("%s:%d [ %.*s ]", op->id, op->pid, (int)(next-offset), offset);
- if(next[0] != 0) {
+ mh_notice("%s:%d [ %.*s ]", op->id, op->pid,
+ (int) (next - offset), offset);
+ if (next[0] != 0) {
next++;
}
- } while(next != NULL && next[0] != 0);
+ } while (next != NULL && next[0] != 0);
}
}
- if(op->interval && op->opaque->cancel == FALSE) {
- op->opaque->repeat_timer = g_timeout_add(op->interval, recurring_action_timer, (void*)op);
+ if (op->interval && op->opaque->cancel == FALSE) {
+ op->opaque->repeat_timer = g_timeout_add(op->interval,
+ recurring_action_timer,
+ (void *) op);
}
op->pid = 0;
- if(op->opaque->callback) {
- /* Callback might call cancel which would result in the message being free'd
+ if (op->opaque->callback) {
+ /* Callback might call cancel which would result in the message
+ * being free'd
* Do not access 'op' after this line
*/
op->opaque->callback(op);
- } else if(op->opaque->repeat_timer == 0) {
+ } else if (op->opaque->repeat_timer == 0) {
services_action_free(op);
}
}
@@ -250,69 +257,69 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
int stdout_fd[2];
int stderr_fd[2];
- if ( pipe(stdout_fd) < 0 ) {
+ if (pipe(stdout_fd) < 0) {
mh_perror(LOG_ERR, "pipe() failed");
}
- if ( pipe(stderr_fd) < 0 ) {
+ if (pipe(stderr_fd) < 0) {
mh_perror(LOG_ERR, "pipe() failed");
}
op->pid = fork();
- switch(op->pid) {
- case -1:
- mh_perror(LOG_ERR, "fork() failed");
- close(stdout_fd[0]);
+ switch (op->pid) {
+ case -1:
+ mh_perror(LOG_ERR, "fork() failed");
+ close(stdout_fd[0]);
+ close(stdout_fd[1]);
+ close(stderr_fd[0]);
+ close(stderr_fd[1]);
+ return FALSE;
+
+ case 0: /* Child */
+ /* Man: The call setpgrp() is equivalent to setpgid(0,0)
+ * _and_ compiles on BSD variants too
+ * need to investigate if it works the same too.
+ */
+ setpgid(0, 0);
+ close(stdout_fd[0]);
+ close(stderr_fd[0]);
+ if (STDOUT_FILENO != stdout_fd[1]) {
+ if (dup2(stdout_fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stdout)");
+ }
close(stdout_fd[1]);
- close(stderr_fd[0]);
+ }
+ if (STDERR_FILENO != stderr_fd[1]) {
+ if (dup2(stderr_fd[1], STDERR_FILENO) != STDERR_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stderr)");
+ }
close(stderr_fd[1]);
- return FALSE;
+ }
- case 0: /* Child */
- /* Man: The call setpgrp() is equivalent to setpgid(0,0)
- * _and_ compiles on BSD variants too
- * need to investigate if it works the same too.
- */
- setpgid(0,0);
- close(stdout_fd[0]);
- close(stderr_fd[0]);
- if (STDOUT_FILENO != stdout_fd[1]) {
- if (dup2(stdout_fd[1], STDOUT_FILENO)!=STDOUT_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stdout)");
- }
- close(stdout_fd[1]);
- }
- if (STDERR_FILENO != stderr_fd[1]) {
- if (dup2(stderr_fd[1], STDERR_FILENO)!=STDERR_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stderr)");
- }
- close(stderr_fd[1]);
- }
+ /* close all descriptors except stdin/out/err and channels to logd */
+ for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
+ close(lpc);
+ }
- /* close all descriptors except stdin/out/err and channels to logd */
- for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
- close(lpc);
- }
+ /* Setup environment correctly */
+ add_OCF_env_vars(op);
- /* Setup environment correctly */
- add_OCF_env_vars(op);
-
- /* execute the RA */
- execvp(op->opaque->exec, op->opaque->args);
-
- switch (errno) { /* see execve(2) */
- case ENOENT: /* No such file or directory */
- case EISDIR: /* Is a directory */
- rc = OCF_NOT_INSTALLED;
- break;
- case EACCES: /* permission denied (various errors) */
- rc = OCF_INSUFFICIENT_PRIV;
- break;
- default:
- rc = OCF_UNKNOWN_ERROR;
- break;
- }
- _exit(rc);
+ /* execute the RA */
+ execvp(op->opaque->exec, op->opaque->args);
+
+ switch (errno) { /* see execve(2) */
+ case ENOENT: /* No such file or directory */
+ case EISDIR: /* Is a directory */
+ rc = OCF_NOT_INSTALLED;
+ break;
+ case EACCES: /* permission denied (various errors) */
+ rc = OCF_INSUFFICIENT_PRIV;
+ break;
+ default:
+ rc = OCF_UNKNOWN_ERROR;
+ break;
+ }
+ _exit(rc);
}
/* Only the parent reaches here */
@@ -325,21 +332,22 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
op->opaque->stderr_fd = stderr_fd[0];
set_fd_opts(op->opaque->stderr_fd, O_NONBLOCK);
- if(synchronous) {
+ if (synchronous) {
int status = 0;
int timeout = 1 + op->timeout / 1000;
mh_trace("Waiting for %d", op->pid);
- while(timeout > 0 && waitpid(op->pid, &status, WNOHANG) <= 0) {
+ while (timeout > 0 && waitpid(op->pid, &status, WNOHANG) <= 0) {
sleep(1);
timeout--;
}
mh_trace("Child done: %d", op->pid);
- if(timeout == 0) {
+ if (timeout == 0) {
int killrc = sigar_proc_kill(op->pid, 9 /*SIGKILL*/);
op->status = LRM_OP_TIMEOUT;
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid, op->timeout);
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
+ op->timeout);
if (killrc != SIGAR_OK && killrc != ESRCH) {
mh_err("kill(%d, KILL) failed: %d", op->pid, killrc);
@@ -348,12 +356,14 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
} else if (WIFEXITED(status)) {
op->status = LRM_OP_DONE;
op->rc = WEXITSTATUS(status);
- mh_err("Managed %s process %d exited with rc=%d", op->id, op->pid, op->rc);
+ mh_err("Managed %s process %d exited with rc=%d", op->id, op->pid,
+ op->rc);
} else if (WIFSIGNALED(status)) {
int signo = WTERMSIG(status);
op->status = LRM_OP_ERROR;
- mh_err("Managed %s process %d exited with signal=%d", op->id, op->pid, signo);
+ mh_err("Managed %s process %d exited with signal=%d", op->id,
+ op->pid, signo);
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
@@ -366,13 +376,14 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
} else {
mh_trace("Async waiting for %d - %s", op->pid, op->opaque->exec);
- mainloop_add_child(op->pid, op->timeout, op->id, op, operation_finished);
+ mainloop_add_child(op->pid, op->timeout, op->id, op,
+ operation_finished);
- op->opaque->stdout_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stdout_fd, read_output, pipe_out_done, op);
+ op->opaque->stdout_gsource = mainloop_add_fd(G_PRIORITY_LOW,
+ op->opaque->stdout_fd, read_output, pipe_out_done, op);
- op->opaque->stderr_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stderr_fd, read_output, pipe_err_done, op);
+ op->opaque->stderr_gsource = mainloop_add_fd(G_PRIORITY_LOW,
+ op->opaque->stderr_fd, read_output, pipe_err_done, op);
}
return TRUE;
@@ -381,7 +392,7 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
GList *
services_os_get_directory_list(const char *root, gboolean files)
{
- GList* list = NULL;
+ GList *list = NULL;
#if __linux__
struct dirent **namelist;
int entries = 0, lpc = 0;
@@ -402,20 +413,20 @@ services_os_get_directory_list(const char *root, gboolean files)
snprintf(buffer, sizeof(buffer), "%s/%s", root, namelist[lpc]->d_name);
stat(buffer, &sb);
- if(S_ISDIR(sb.st_mode)) {
- if(files) {
+ if (S_ISDIR(sb.st_mode)) {
+ if (files) {
free(namelist[lpc]);
continue;
}
- } else if(S_ISREG(sb.st_mode)) {
- if(files == FALSE) {
+ } else if (S_ISREG(sb.st_mode)) {
+ if (files == FALSE) {
free(namelist[lpc]);
continue;
- } else if( (sb.st_mode & S_IXUSR) == 0
+ } else if ((sb.st_mode & S_IXUSR) == 0
&& (sb.st_mode & S_IXGRP) == 0
- && (sb.st_mode & S_IXOTH) == 0 ) {
+ && (sb.st_mode & S_IXOTH) == 0) {
free(namelist[lpc]);
continue;
}
@@ -430,16 +441,16 @@ services_os_get_directory_list(const char *root, gboolean files)
}
void
-services_os_set_exec(svc_action_t* op)
+services_os_set_exec(svc_action_t *op)
{
- if(strcmp("enable", op->action) == 0) {
+ if (strcmp("enable", op->action) == 0) {
op->opaque->exec = strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
op->opaque->args[2] = strdup("on");
op->opaque->args[3] = NULL;
- } else if(strcmp("disable", op->action) == 0) {
+ } else if (strcmp("disable", op->action) == 0) {
op->opaque->exec = strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
@@ -454,22 +465,26 @@ services_os_set_exec(svc_action_t* op)
}
}
-GList *services_os_list(void)
+GList *
+services_os_list(void)
{
return get_directory_list(LSB_ROOT, TRUE);
}
-GList *resources_os_list_ocf_providers(void)
+GList *
+resources_os_list_ocf_providers(void)
{
- return get_directory_list(OCF_ROOT"/resource.d", FALSE);
+ return get_directory_list(OCF_ROOT "/resource.d", FALSE);
}
-GList *resources_os_list_ocf_agents(const char *provider)
+GList *
+resources_os_list_ocf_agents(const char *provider)
{
- if(provider) {
+ if (provider) {
char buffer[500];
- snprintf(buffer, sizeof(buffer), "%s//resource.d/%s", OCF_ROOT, provider);
+ snprintf(buffer, sizeof(buffer), "%s//resource.d/%s", OCF_ROOT,
+ provider);
return get_directory_list(buffer, TRUE);
}
return NULL;
diff --git a/src/lib/services_private.h b/src/lib/services_private.h
index 2b30228..c413528 100644
--- a/src/lib/services_private.h
+++ b/src/lib/services_private.h
@@ -1,21 +1,22 @@
-struct svc_action_private_s
+struct svc_action_private_s
{
- char *exec;
- char *args[4];
- gboolean cancel;
-
- guint repeat_timer;
- void (*callback)(svc_action_t *op);
-
- int stderr_fd;
- mainloop_fd_t *stderr_gsource;
+ char *exec;
+ char *args[4];
+ gboolean cancel;
- int stdout_fd;
- mainloop_fd_t *stdout_gsource;
+ guint repeat_timer;
+ void (*callback)(svc_action_t *op);
+
+ int stderr_fd;
+ mainloop_fd_t *stderr_gsource;
+
+ int stdout_fd;
+ mainloop_fd_t *stdout_gsource;
};
extern GList *services_os_get_directory_list(const char *root, gboolean files);
-extern gboolean services_os_action_execute(svc_action_t* op, gboolean synchronous);
+extern gboolean services_os_action_execute(svc_action_t* op,
+ gboolean synchronous);
extern void services_os_set_exec(svc_action_t* op);
extern GList *services_os_list(void);
extern GList *resources_os_list_ocf_providers(void);
diff --git a/src/lib/services_windows.c b/src/lib/services_windows.c
index ae1e2be..b3f43e5 100644
--- a/src/lib/services_windows.c
+++ b/src/lib/services_windows.c
@@ -1,23 +1,23 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <windows.h>
+#include <windows.h>
#include <tchar.h>
-#include <stdio.h>
+#include <stdio.h>
#include "matahari/logging.h"
#include "matahari/mainloop.h"
@@ -27,25 +27,28 @@
/* Some code adapted from http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx */
-static wchar_t *char2wide(const char *str)
+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);
+ 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)
+static void
+create_service_key(const wchar_t *template, wchar_t *buffer, int size,
+ char *name)
{
#ifdef HAVE_SWPRINTF_S
- swprintf_s
+ swprintf_s
#else
- snwprintf
+ snwprintf
#endif
- ( buffer, size, template, name);
+ (buffer, size, template, name);
}
static gboolean
@@ -58,58 +61,61 @@ windows_service_control(char *name, int command)
wchar_t *value = NULL;
wchar_t szRegistryPath[1024];
- create_service_key(
- L"SYSTEM\\CurrentControlSet\\services\\%s", szRegistryPath, DIMOF(szRegistryPath), name);
+ create_service_key(L"SYSTEM\\CurrentControlSet\\services\\%s",
+ szRegistryPath, DIMOF(szRegistryPath), name);
- fSuccess = RegOpenKey (HKEY_LOCAL_MACHINE, szRegistryPath, &key_service);
- if(fSuccess != ERROR_SUCCESS) {
- printf("Could not read key at '%ls' - %d\n\r", szRegistryPath, fSuccess);
- return FALSE;
+ fSuccess = RegOpenKey(HKEY_LOCAL_MACHINE, szRegistryPath, &key_service);
+ if (fSuccess != ERROR_SUCCESS) {
+ printf("Could not read key at '%ls' - %d\n\r", szRegistryPath,
+ fSuccess);
+ return FALSE;
}
itoa(command, raw, 10);
value = char2wide(raw);
- value_bytes = 2 * (lstrlen(value) +1);
+ value_bytes = 2 * (lstrlen(value) + 1);
+
+ fSuccess = RegSetValueEx(key_service, L"Start", 0, REG_SZ, (LPBYTE) value,
+ value_bytes);
+ mh_info("Setting Start='%ls' for %s: %s (%d)\n\r", value, name,
+ fSuccess == ERROR_SUCCESS ? "PASS" : "FAIL", fSuccess);
- fSuccess = RegSetValueEx (key_service, L"Start", 0, REG_SZ, (LPBYTE) value, value_bytes);
- mh_info("Setting Start='%ls' for %s: %s (%d)\n\r",
- value, name, fSuccess==ERROR_SUCCESS?"PASS":"FAIL", fSuccess);
-
RegCloseKey(key_service);
free(value);
-
- return fSuccess==ERROR_SUCCESS;
+
+ return fSuccess == ERROR_SUCCESS;
}
#define BUFSIZE 4096
-static void read_output(HANDLE h, char **output, int *length)
+static void
+read_output(HANDLE h, char **output, int *length)
{
/* Read output from the child process's pipe for STDOUT
* Stop when there is no more data.
*/
int len = 0;
- DWORD bytes = 0;
+ DWORD bytes = 0;
char buf[BUFSIZE];
char *data = NULL;
-
- while(1) {
- if( ReadFile(h, buf, BUFSIZE, &bytes, NULL) == 0 ) {
- break;
- } else if(bytes == 0) {
- break;
- }
-
- data = realloc(data, len + (int)bytes + 1);
- mh_info("Read %d: %.*s", len, (int)bytes, buf);
- sprintf(data+len, "%s", buf);
- data[len+bytes] = 0;
- len += (int)bytes;
+
+ while (1) {
+ if (ReadFile(h, buf, BUFSIZE, &bytes, NULL) == 0) {
+ break;
+ } else if (bytes == 0) {
+ break;
+ }
+
+ data = realloc(data, len + (int) bytes + 1);
+ mh_info("Read %d: %.*s", len, (int) bytes, buf);
+ sprintf(data + len, "%s", buf);
+ data[len + bytes] = 0;
+ len += (int)bytes;
}
*length = len;
*output = data;
mh_info("Read %d bytes", len);
-}
+}
static int
extract_service_status(const char *unmutable, int max)
@@ -117,241 +123,246 @@ extract_service_status(const char *unmutable, int max)
int lpc = 0, last = 0;
int rc = LSB_STATUS_UNKNOWN_ERROR;
- if(unmutable == NULL || max < 10) {
- return rc;
+ if (unmutable == NULL || max < 10) {
+ return rc;
+ }
+
+ for (; lpc < max; lpc++) {
+ switch (unmutable[lpc]) {
+ case '\n':
+ case '\r':
+ case 0:
+ if (lpc - last > 1) {
+ char name[512];
+ char value[512];
+ char next[2048];
+ /* char *next = malloc(1+lpc-last); */
+ int rc = 0, number = 0;
+
+ strncpy(next, unmutable + last, lpc - last);
+ next[lpc - last] = 0;
+
+ rc = sscanf(next, " %[^:]: %d %[^:]", name, &number,
+ value);
+ if (rc == 3) {
+ mh_info(" '%s' = '%s' %d", name, value, number);
+ if (strncmp("STATE", name, 5) == 0) {
+ switch (number) {
+ case 1:
+ rc = LSB_STATUS_NOT_RUNNING;
+ break;
+ case 3:
+ /* Stopping but not stopped - treat as active */
+ rc = LSB_STATUS_OK;
+ break;
+ case 4:
+ rc = LSB_STATUS_OK;
+ break;
+ default:
+ mh_info("Unknown status: %s", next);
+ }
+ /* free(next); */
+ return rc;
+ }
+ }
+ /* free(next); */
+ }
+ last = lpc + 1;
+ break;
+ }
}
-
- for(; lpc < max; lpc++) {
- switch(unmutable[lpc]) {
- case '\n':
- case '\r':
- case 0:
- if(lpc - last > 1) {
- char name[512];
- char value[512];
- char next[2048];
- /* char *next = malloc(1+lpc-last); */
- int rc = 0, number = 0;
-
- strncpy(next, unmutable+last, lpc-last);
- next[lpc-last] = 0;
-
- rc = sscanf(next, " %[^:]: %d %[^:]", name, &number, value);
- if(rc == 3) {
- mh_info(" '%s' = '%s' %d", name, value, number);
- if(strncmp("STATE", name, 5) == 0) {
- switch(number) {
- case 1:
- rc = LSB_STATUS_NOT_RUNNING;
- break;
- case 3:
- /* Stopping but not stopped - treat as active */
- rc = LSB_STATUS_OK;
- break;
- case 4:
- rc = LSB_STATUS_OK;
- break;
- default:
- mh_info("Unknown status: %s", next);
- }
- /* free(next); */
- return rc;
- }
- }
- /* free(next); */
- }
- last = lpc+1;
- break;
- }
- }
mh_info("Couldn't parse service status");
return rc;
}
gboolean
-services_os_action_execute(svc_action_t* op, gboolean synchronous)
+services_os_action_execute(svc_action_t *op, gboolean synchronous)
{
int max = 0;
DWORD status = 0;
wchar_t *exec_w = NULL;
STARTUPINFO siStartInfo;
- SECURITY_ATTRIBUTES saAttr;
- PROCESS_INFORMATION piProcInfo;
+ SECURITY_ATTRIBUTES saAttr;
+ PROCESS_INFORMATION piProcInfo;
HANDLE child_pipe_rd = NULL;
HANDLE child_pipe_wr = NULL;
gboolean is_status_op = FALSE;
- if(strcmp("status", op->action) == 0) {
- is_status_op = TRUE;
-
- } else if(strcmp("disable", op->action) == 0) {
- return windows_service_control(op->rsc, SERVICE_DISABLED);
+ if (strcmp("status", op->action) == 0) {
+ is_status_op = TRUE;
- } else if(strcmp("enable", op->action) == 0) {
- return windows_service_control(op->rsc, SERVICE_AUTO_START);
+ } else if (strcmp("disable", op->action) == 0) {
+ return windows_service_control(op->rsc, SERVICE_DISABLED);
+
+ } else if (strcmp("enable", op->action) == 0) {
+ return windows_service_control(op->rsc, SERVICE_AUTO_START);
}
-
+
/* Initialize all structures */
- ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
- ZeroMemory( &saAttr, sizeof(SECURITY_ATTRIBUTES) );
- ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
-
+ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
+ ZeroMemory(&saAttr, sizeof(SECURITY_ATTRIBUTES));
+ ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
+
/* Set the bInheritHandle flag so pipe handles are inherited. */
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ saAttr.bInheritHandle = TRUE;
+ saAttr.lpSecurityDescriptor = NULL;
/* Create a pipe for the child process's stdout */
- if ( ! CreatePipe(&child_pipe_rd, &child_pipe_wr, &saAttr, 0) ) {
- mh_err("Couldn't create child pipe");
- goto fail;
+ if (!CreatePipe(&child_pipe_rd, &child_pipe_wr, &saAttr, 0)) {
+ mh_err("Couldn't create child pipe");
+ goto fail;
}
/* Ensure the read handle to the pipe for STDOUT is not inherited. */
- if ( ! SetHandleInformation(child_pipe_rd, HANDLE_FLAG_INHERIT, 0) ) {
- mh_err("Couldn't set pipe handle information");
- goto fail;
+ if (!SetHandleInformation(child_pipe_rd, HANDLE_FLAG_INHERIT, 0)) {
+ mh_err("Couldn't set pipe handle information");
+ goto fail;
}
-
- siStartInfo.cb = sizeof(STARTUPINFO);
+
+ siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdError = child_pipe_wr;
siStartInfo.hStdOutput = child_pipe_wr;
/* siStartInfo.hStdInput = g_hChildStd_IN_Rd; */
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
exec_w = char2wide(op->opaque->exec);
- if( !CreateProcess(NULL,
- exec_w, // command line
- NULL, // process security attributes
- NULL, // primary thread security attributes
- TRUE, // handles are inherited
- 0, // creation flags
- NULL, // use parent's environment
- NULL, // use parent's current directory
- &siStartInfo, // STARTUPINFO pointer
- &piProcInfo) // receives PROCESS_INFORMATION
- ) {
- mh_err("Could not create child process");
- goto fail;
-
- /* For now, run all commands synchronously */
- /* } else if(synchronous == FALSE) { */
- /* return TRUE; */
+ if (!CreateProcess(NULL,
+ exec_w, // command line
+ NULL, // process security attributes
+ NULL, // primary thread security attributes
+ TRUE, // handles are inherited
+ 0, // creation flags
+ NULL, // use parent's environment
+ NULL, // use parent's current directory
+ &siStartInfo, // STARTUPINFO pointer
+ &piProcInfo)) { // receives PROCESS_INFORMATION
+ mh_err("Could not create child process");
+ goto fail;
+
+ /* For now, run all commands synchronously */
+ /* } else if(synchronous == FALSE) { */
+ /* return TRUE; */
}
-
+
WaitForSingleObject(piProcInfo.hProcess, op->timeout /* Or INFINITE */);
- if(GetExitCodeProcess(piProcInfo.hProcess, &status) == 0) {
- mh_err("Could not get exit code: %lu", GetLastError());
- status = STILL_ACTIVE;
+ if (GetExitCodeProcess(piProcInfo.hProcess, &status) == 0) {
+ mh_err("Could not get exit code: %lu", GetLastError());
+ status = STILL_ACTIVE;
}
-
- if(status == STILL_ACTIVE) {
- op->rc = LSB_UNKNOWN_ERROR;
- op->status = LRM_OP_TIMEOUT;
- TerminateProcess(piProcInfo.hProcess, 1);
- mh_err("Operation for %s timeout out after %dms", op->id, op->timeout);
-
- } else if(status == 1062 && strcmp("stop", op->action) == 0) {
- /* Stopping something thats stopped is a success */
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
-
- } else if(status == 1056 && strcmp("start", op->action) == 0) {
- /* Starting something thats started is a success */
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
-
- } else if(status == 0) {
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
+
+ if (status == STILL_ACTIVE) {
+ op->rc = LSB_UNKNOWN_ERROR;
+ op->status = LRM_OP_TIMEOUT;
+ TerminateProcess(piProcInfo.hProcess, 1);
+ mh_err("Operation for %s timeout out after %dms", op->id, op->timeout);
+
+ } else if (status == 1062 && strcmp("stop", op->action) == 0) {
+ /* Stopping something thats stopped is a success */
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
+
+ } else if (status == 1056 && strcmp("start", op->action) == 0) {
+ /* Starting something thats started is a success */
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
+
+ } else if (status == 0) {
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
} else {
- op->status = LRM_OP_ERROR;
- op->rc = LSB_UNKNOWN_ERROR;
- mh_info("Result of '%ls' for '%s' was %d", exec_w, op->id, (int)status);
+ op->status = LRM_OP_ERROR;
+ op->rc = LSB_UNKNOWN_ERROR;
+ mh_info("Result of '%ls' for '%s' was %d", exec_w, op->id, (int)status);
}
/* Nice to log it somewhere */
- if(op->rc == LSB_OK) {
- mh_debug("Result of '%ls' for '%s' was %d", exec_w, op->id, (int)status);
+ if (op->rc == LSB_OK) {
+ mh_debug("Result of '%ls' for '%s' was %d", exec_w, op->id, (int)status);
}
-
- /* Close the write end of the pipe before reading from the
+
+ /* Close the write end of the pipe before reading from the
* read end of the pipe, to control child process execution.
* The pipe is assumed to have enough buffer space to hold the
* data the child process has already written to it.
*/
if (!CloseHandle(child_pipe_wr)) {
- mh_err("Couldn't close write end of child pipe");
+ mh_err("Couldn't close write end of child pipe");
}
-
+
read_output(child_pipe_rd, &op->stdout_data, &max);
- if(op->stdout_data) {
- mh_debug("RAW: %s", op->stdout_data);
+ if (op->stdout_data) {
+ mh_debug("RAW: %s", op->stdout_data);
}
- if(is_status_op && op->status == LRM_OP_DONE) {
- op->rc = extract_service_status(op->stdout_data, max);
+ if (is_status_op && op->status == LRM_OP_DONE) {
+ op->rc = extract_service_status(op->stdout_data, max);
}
-
+
CloseHandle(piProcInfo.hProcess);
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_UNKNOWN_ERROR) {
+ op->rc = LSB_STATUS_UNKNOWN_ERROR;
}
-
+
return TRUE;
- fail:
+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;
+ if (is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
+ op->rc = LSB_STATUS_UNKNOWN_ERROR;
}
return FALSE;
}
void
-services_os_set_exec(svc_action_t* op)
+services_os_set_exec(svc_action_t *op)
{
char *p = getenv("WINDIR");
- if(strcmp("status", op->action) == 0) {
- op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe query %s", p, op->rsc);
- /* op->opaque->exec = g_strdup_printf("sc query %s", op->rsc); */
+ if (strcmp("status", op->action) == 0) {
+ op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe query %s", p,
+ op->rsc);
+ /* op->opaque->exec = g_strdup_printf("sc query %s", op->rsc); */
} else {
- op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe %s %s", p, op->action, op->rsc);
- /* op->opaque->exec = g_strdup_printf("sc %s %s", op->action, op->rsc); */
+ op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe %s %s", p,
+ op->action, op->rsc);
+ /* op->opaque->exec = g_strdup_printf("sc %s %s", op->action, op->rsc); */
}
}
GList *
services_os_get_directory_list(const char *root, gboolean files)
{
- /* For now, this is unsupported/unnecessary on Windows, return an empty list */
+ /* For now, this is unsupported/unnecessary on Windows,
+ * return an empty list */
return NULL;
}
-GList *services_os_list(void)
+GList *
+services_os_list(void)
{
/* Need to implement */
- /* SC QUERY state= all | findstr "SERVICE_NAME" */
+ /* SC QUERY state= all | findstr "SERVICE_NAME" */
return NULL;
}
-
-GList *resources_os_list_ocf_providers(void)
+GList *
+resources_os_list_ocf_providers(void)
{
/* Unsupported on Windows, return an empty list */
return NULL;
}
-GList *resources_os_list_ocf_agents(const char *provider)
+GList *
+resources_os_list_ocf_agents(const char *provider)
{
/* Unsupported on Windows, return an empty list */
return NULL;
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index 1151c00..57929a2 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -48,7 +48,8 @@ gboolean mh_stderr_enabled = FALSE;
#if SUPPORT_TRACING
static int
-mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start, struct _mh_ddebug *stop)
+mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start,
+ struct _mh_ddebug *stop)
{
int lpc = 0;
unsigned nfound = 0;
@@ -59,51 +60,53 @@ mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start, s
MH_ASSERT(start != NULL);
/* fprintf(stderr, "checking for fns: %s files: %s fmts: %s\n", */
- /* query->functions, query->files, query->formats); */
-
+ /* query->functions, query->files, query->formats); */
+
for (dp = start; dp != stop; dp++) {
- gboolean bump = FALSE;
- lpc++;
- /* fprintf(stderr, "checking: %-12s %20s:%u fmt:%s\n", */
- /* dp->function, dp->filename, dp->lineno, dp->format); */
-
- if (query->functions && strstr(query->functions, dp->function) != NULL) {
- match = "function";
- bump = TRUE;
- }
-
- if(query->files) {
- char token[500];
- const char *offset = NULL;
- const char *next = query->files;
-
- do {
- offset = next;
- next = strchrnul(offset, ',');
- snprintf(token, 499, "%.*s", (int)(next-offset), offset);
-
- if (query->files && strstr(dp->filename, token) != NULL) {
- match = "file";
- bump = TRUE;
-
- } else if(next[0] != 0) {
- next++;
- }
-
- } while(bump == FALSE && next != NULL && next[0] != 0);
- }
-
- if (query->formats && strstr(query->formats, dp->format) != NULL) {
- match = "format";
- bump = TRUE;
- }
-
- if(bump) {
- nfound++;
- dp->bump = LOG_NOTICE;
- mh_log_always(LOG_INFO, "Detected '%s' match: %-12s %20s:%u fmt:%s",
- match, dp->function, dp->filename, dp->lineno, dp->format);
- }
+ gboolean bump = FALSE;
+ lpc++;
+ /* fprintf(stderr, "checking: %-12s %20s:%u fmt:%s\n", */
+ /* dp->function, dp->filename, dp->lineno, dp->format); */
+
+ if (query->functions &&
+ strstr(query->functions, dp->function) != NULL) {
+ match = "function";
+ bump = TRUE;
+ }
+
+ if (query->files) {
+ char token[500];
+ const char *offset = NULL;
+ const char *next = query->files;
+
+ do {
+ offset = next;
+ next = strchrnul(offset, ',');
+ snprintf(token, 499, "%.*s", (int)(next - offset), offset);
+
+ if (query->files && strstr(dp->filename, token) != NULL) {
+ match = "file";
+ bump = TRUE;
+
+ } else if (next[0] != 0) {
+ next++;
+ }
+
+ } while (bump == FALSE && next != NULL && next[0] != 0);
+ }
+
+ if (query->formats && strstr(query->formats, dp->format) != NULL) {
+ match = "format";
+ bump = TRUE;
+ }
+
+ if (bump) {
+ nfound++;
+ dp->bump = LOG_NOTICE;
+ mh_log_always(LOG_INFO, "Detected '%s' match: %-12s %20s:%u fmt:%s",
+ match, dp->function, dp->filename, dp->lineno,
+ dp->format);
+ }
}
query->total += lpc;
@@ -114,195 +117,202 @@ mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start, s
static int
mh_ddebug_callback(struct dl_phdr_info *info, size_t size, void *data)
{
- if(strlen(info->dlpi_name) > 0) {
- struct _mh_ddebug_query *query = data;
-
- void *handle;
- void *start;
- void *stop;
- char *error;
-
- handle = dlopen (info->dlpi_name, RTLD_LAZY);
- error = dlerror();
- if (!handle || error) {
- mh_err("%s", error);
- if(handle) {
- dlclose(handle);
- }
- return 0;
- }
-
- start = dlsym(handle, "__start___verbose");
- error = dlerror();
- if (error) {
- goto done;
- }
-
- stop = dlsym(handle, "__stop___verbose");
- error = dlerror();
- if (error) {
- goto done;
-
- } else {
- unsigned long int len = (unsigned long int)stop - (unsigned long int)start;
- mh_info("Checking for query matches in %lu trace symbols from: %s (offset: %p)",
- len/sizeof(struct _mh_ddebug), info->dlpi_name, start);
-
- mh_update_trace_data(query, start, stop);
- }
- done:
- dlclose(handle);
+ if (strlen(info->dlpi_name) > 0) {
+ struct _mh_ddebug_query *query = data;
+
+ void *handle;
+ void *start;
+ void *stop;
+ char *error;
+
+ handle = dlopen (info->dlpi_name, RTLD_LAZY);
+ error = dlerror();
+ if (!handle || error) {
+ mh_err("%s", error);
+ if (handle) {
+ dlclose(handle);
+ }
+ return 0;
+ }
+
+ start = dlsym(handle, "__start___verbose");
+ error = dlerror();
+ if (error) {
+ goto done;
+ }
+
+ stop = dlsym(handle, "__stop___verbose");
+ error = dlerror();
+ if (error) {
+ goto done;
+
+ } else {
+ unsigned long int len = (unsigned long int) stop -
+ (unsigned long int) start;
+ mh_info("Checking for query matches in %lu trace symbols from: "
+ "%s (offset: %p)", len / sizeof(struct _mh_ddebug),
+ info->dlpi_name, start);
+
+ mh_update_trace_data(query, start, stop);
+ }
+ done:
+ dlclose(handle);
}
-
+
return 0;
}
#endif
static void
-mh_glib_handler(const gchar *log_domain, GLogLevelFlags flags, const gchar *message, gpointer user_data)
+mh_glib_handler(const gchar *log_domain, GLogLevelFlags flags,
+ const gchar *message, gpointer user_data)
{
int log_level = LOG_WARNING;
GLogLevelFlags msg_level = (flags & G_LOG_LEVEL_MASK);
- switch(msg_level) {
- case G_LOG_LEVEL_CRITICAL:
- /* log and record how we got here */
- mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, message, TRUE, TRUE);
- return;
-
- case G_LOG_FLAG_FATAL: log_level = LOG_CRIT; break;
- case G_LOG_LEVEL_ERROR: log_level = LOG_ERR; break;
- case G_LOG_LEVEL_MESSAGE: log_level = LOG_NOTICE; break;
- case G_LOG_LEVEL_INFO: log_level = LOG_INFO; break;
- case G_LOG_LEVEL_DEBUG: log_level = LOG_DEBUG; break;
-
- case G_LOG_LEVEL_WARNING:
- case G_LOG_FLAG_RECURSION:
- case G_LOG_LEVEL_MASK:
- log_level = LOG_WARNING;
- break;
+ switch (msg_level) {
+ case G_LOG_LEVEL_CRITICAL:
+ /* log and record how we got here */
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, message, TRUE, TRUE);
+ return;
+
+ case G_LOG_FLAG_FATAL: log_level = LOG_CRIT; break;
+ case G_LOG_LEVEL_ERROR: log_level = LOG_ERR; break;
+ case G_LOG_LEVEL_MESSAGE: log_level = LOG_NOTICE; break;
+ case G_LOG_LEVEL_INFO: log_level = LOG_INFO; break;
+ case G_LOG_LEVEL_DEBUG: log_level = LOG_DEBUG; break;
+
+ case G_LOG_LEVEL_WARNING:
+ case G_LOG_FLAG_RECURSION:
+ case G_LOG_LEVEL_MASK:
+ log_level = LOG_WARNING;
+ break;
}
mh_log(log_level, "%s: %s", log_domain, message);
}
-void mh_enable_stderr(gboolean to_stderr)
+void
+mh_enable_stderr(gboolean to_stderr)
{
mh_stderr_enabled = to_stderr;
}
-void mh_log_init(const char *ident, int level, gboolean to_stderr)
+void
+mh_log_init(const char *ident, int level, gboolean to_stderr)
{
#if SUPPORT_TRACING
gboolean search = FALSE;
const char *env_value = NULL;
struct _mh_ddebug_query query;
#endif
-
+
mh_log_level = level;
mh_stderr_enabled = to_stderr;
#ifdef __linux__
- openlog(ident, LOG_NDELAY|LOG_PID, LOG_DAEMON);
+ openlog(ident, LOG_NDELAY | LOG_PID, LOG_DAEMON);
#endif
/* Consistant glib logging */
g_log_set_default_handler(mh_glib_handler, NULL);
-
+
/* and for good measure... - this enum is a bit field (!) */
- g_log_set_always_fatal((GLogLevelFlags)0); /*value out of range*/
+ g_log_set_always_fatal((GLogLevelFlags) 0); /*value out of range*/
#if SUPPORT_TRACING
memset(&query, 0, sizeof(struct _mh_ddebug_query));
env_value = getenv("MH_trace_files");
- if(env_value) {
- search = TRUE;
- query.files = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.files = env_value;
}
env_value = getenv("MH_trace_formats");
- if(env_value) {
- search = TRUE;
- query.formats = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.formats = env_value;
}
env_value = getenv("MH_trace_functions");
- if(env_value) {
- search = TRUE;
- query.functions = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.functions = env_value;
}
-
- if(search) {
- mh_update_trace_data(&query, __start___verbose, __stop___verbose);
- dl_iterate_phdr(mh_ddebug_callback, &query);
- if(query.matches == 0) {
- mh_log_always(LOG_DEBUG,
- "no matches for query: {fn='%s', file='%s', fmt='%s'} in %llu entries",
- query.functions?query.functions:"N/A",
- query.files?query.files:"N/A",
- query.formats?query.formats:"N/A",
- query.total);
- } else {
- mh_log_always(LOG_INFO,
- "%llu matches for query: {fn='%s', file='%s', fmt='%s'} in %llu entries",
- query.matches,
- query.functions?query.functions:"N/A",
- query.files?query.files:"N/A",
- query.formats?query.formats:"N/A",
- query.total);
- }
+
+ if (search) {
+ mh_update_trace_data(&query, __start___verbose, __stop___verbose);
+ dl_iterate_phdr(mh_ddebug_callback, &query);
+ if (query.matches == 0) {
+ mh_log_always(LOG_DEBUG, "no matches for query: {fn='%s', "
+ "file='%s', fmt='%s'} in %llu entries",
+ query.functions ? query.functions : "N/A",
+ query.files ? query.files : "N/A",
+ query.formats ? query.formats : "N/A",
+ query.total);
+ } else {
+ mh_log_always(LOG_INFO, "%llu matches for query: {fn='%s', "
+ "file='%s', fmt='%s'} in %llu entries",
+ query.matches,
+ query.functions ? query.functions : "N/A",
+ query.files ? query.files : "N/A",
+ query.formats ? query.formats : "N/A",
+ query.total);
+ }
}
#endif
}
void
mh_abort(const char *file, const char *function, int line,
- const char *assert_condition, int do_core, int do_fork)
+ const char *assert_condition, int do_core, int do_fork)
{
#ifdef __linux__
int rc = 0;
int pid = 0;
int status = 0;
- if(do_core == 0) {
- mh_err("%s: Triggered assert at %s:%d : %s",
- function, file, line, assert_condition);
- return;
+ if (do_core == 0) {
+ mh_err("%s: Triggered assert at %s:%d : %s",
+ function, file, line, assert_condition);
+ return;
- } else if(do_fork) {
- pid=fork();
+ } else if (do_fork) {
+ pid = fork();
} else {
- mh_err("%s: Triggered fatal assert at %s:%d : %s",
- function, file, line, assert_condition);
+ mh_err("%s: Triggered fatal assert at %s:%d : %s",
+ function, file, line, assert_condition);
}
-
- switch(pid) {
- case -1:
- mh_crit("%s: Cannot create core for non-fatal assert at %s:%d : %s",
- function, file, line, assert_condition);
- return;
-
- default: /* Parent */
- mh_err("%s: Forked child %d to record non-fatal assert at %s:%d : %s",
- function, pid, file, line, assert_condition);
- do {
- rc = waitpid(pid, &status, 0);
- if(rc < 0 && errno != EINTR) {
- mh_perror(LOG_ERR, "%s: Cannot wait on forked child %d", function, pid);
- }
-
- } while(rc < 0 && errno == EINTR);
-
- return;
-
- case 0: /* Child */
- abort();
- break;
+
+ switch (pid) {
+ case -1:
+ mh_crit("%s: Cannot create core for non-fatal assert at %s:%d : %s",
+ function, file, line, assert_condition);
+ return;
+
+ default: /* Parent */
+ mh_err("%s: Forked child %d to record non-fatal assert at %s:%d : %s",
+ function, pid, file, line, assert_condition);
+ do {
+ rc = waitpid(pid, &status, 0);
+ if (rc < 0 && errno != EINTR) {
+ mh_perror(LOG_ERR, "%s: Cannot wait on forked child %d",
+ function, pid);
+ }
+
+ } while (rc < 0 && errno == EINTR);
+
+ return;
+
+ case 0: /* Child */
+ abort();
+ break;
}
#else
- mh_err("%s: Triggered assert at %s:%d : %s", function, file, line, assert_condition);
+ mh_err("%s: Triggered assert at %s:%d : %s", function, file, line,
+ assert_condition);
abort();
#endif
}
@@ -313,86 +323,86 @@ mh_log_fn(int priority, const char * fmt, ...)
va_list ap;
if (mh_stderr_enabled) {
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
#ifdef __linux__
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
#else
- fprintf(stderr, "\n\r");
-#endif
- va_end(ap);
+ fprintf(stderr, "\n\r");
+#endif
+ va_end(ap);
#ifdef __linux__
} else {
- va_start(ap, fmt);
- vsyslog(priority, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vsyslog(priority, fmt, ap);
+ va_end(ap);
#endif
}
-
+
return;
}
const char *
mh_hostname(void)
{
- static char *hostname = NULL;
-
- if(hostname == NULL) {
- sigar_t *sigar;
- sigar_net_info_t netinfo;
- sigar_open(&sigar);
- sigar_net_info_get(sigar, &netinfo);
- hostname = strdup(netinfo.host_name);
- }
-
- if(hostname != NULL && strcmp(hostname, "localhost") == 0) {
- free(hostname);
- hostname = strdup(mh_uuid());
- }
-
- mh_trace("Got hostname: %s", hostname);
- return hostname;
+ static char *hostname = NULL;
+
+ if (hostname == NULL) {
+ sigar_t *sigar;
+ sigar_net_info_t netinfo;
+ sigar_open(&sigar);
+ sigar_net_info_get(sigar, &netinfo);
+ hostname = strdup(netinfo.host_name);
+ }
+
+ if (hostname != NULL && strcmp(hostname, "localhost") == 0) {
+ free(hostname);
+ hostname = strdup(mh_uuid());
+ }
+
+ mh_trace("Got hostname: %s", hostname);
+ return hostname;
}
const char *
mh_uuid(void)
{
- static char *uuid = NULL;
+ static char *uuid = NULL;
- if(uuid == NULL) {
+ if (uuid == NULL) {
#ifdef __linux__
- char *buffer = NULL;
- int chunk = 512, data_length = 0, read_chars = 0;
- const char *uuid_file = "/var/lib/dbus/machine-id";
- FILE *input = fopen(uuid_file, "r");
- if(input) {
- do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
- } while (read_chars > 0);
- }
- if(data_length == 0) {
- mh_warn("Could not read from %s", uuid_file);
- uuid = strdup("unknown");
-
- } else {
- char *tmp = strchrnul(buffer, '\n');
- *tmp = '\0';
- uuid = strdup(buffer);
- }
- if(input) {
- fclose(input);
- }
- free(buffer);
+ char *buffer = NULL;
+ int chunk = 512, data_length = 0, read_chars = 0;
+ const char *uuid_file = "/var/lib/dbus/machine-id";
+ FILE *input = fopen(uuid_file, "r");
+ if (input) {
+ do {
+ buffer = realloc(buffer, chunk + data_length + 1);
+ read_chars = fread(buffer + data_length, 1, chunk, input);
+ data_length += read_chars;
+ } while (read_chars > 0);
+ }
+ if (data_length == 0) {
+ mh_warn("Could not read from %s", uuid_file);
+ uuid = strdup("unknown");
+
+ } else {
+ char *tmp = strchrnul(buffer, '\n');
+ *tmp = '\0';
+ uuid = strdup(buffer);
+ }
+ if (input) {
+ fclose(input);
+ }
+ free(buffer);
#else
- uuid = strdup("unknown");
+ uuid = strdup("unknown");
#endif
- }
+ }
- mh_trace("Got uuid: %s", uuid);
- return uuid;
+ mh_trace("Got uuid: %s", uuid);
+ return uuid;
}
#ifndef HAVE_ASPRINTF
diff --git a/src/network/network-dbus.c b/src/network/network-dbus.c
index cb35da0..31040d2 100644
--- a/src/network/network-dbus.c
+++ b/src/network/network-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Radek Novacek <rnovacek(a)redhat.com>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -43,14 +43,15 @@
enum status { INACTIVE = 0, RUNNING };
/* Get status of the interface */
-static enum status interface_status(const char *iface)
+static enum status
+interface_status(const char *iface)
{
- uint64_t flags = 0;
- mh_network_status(iface, &flags);
+ uint64_t flags = 0;
+ mh_network_status(iface, &flags);
- if(flags & SIGAR_IFF_UP)
- return RUNNING;
- return INACTIVE; /* Inactive */
+ if (flags & SIGAR_IFF_UP)
+ return RUNNING;
+ return INACTIVE; /* Inactive */
}
/* Dbus methods */
@@ -58,123 +59,123 @@ static enum status interface_status(const char *iface)
gboolean
Network_list(Matahari *matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- GList *interface_list;
- GList *plist;
- sigar_net_interface_config_t *ifconfig;
- char **list;
- int i = 0;
-
- if (!check_authorization(NETWORK_BUS_NAME ".list", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- // Get the list of interfaces
- interface_list = mh_network_get_interfaces();
-
- // Alloc array for list of interface names
- list = g_new(char *, g_list_length(interface_list) + 1);
-
- // Convert list of interfaces to the array of names
- for(plist = g_list_first(interface_list); plist; plist = g_list_next(plist))
- {
- ifconfig = (sigar_net_interface_config_t *)plist->data;
- list[i++] = strdup(ifconfig->name);
- }
- list[i] = NULL; // Sentinel
-
- dbus_g_method_return(context, list);
- g_strfreev(list);
- g_list_free(interface_list);
- return TRUE;
+ GError* error = NULL;
+ GList *interface_list;
+ GList *plist;
+ sigar_net_interface_config_t *ifconfig;
+ char **list;
+ int i = 0;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".list", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ // Get the list of interfaces
+ interface_list = mh_network_get_interfaces();
+
+ // Alloc array for list of interface names
+ list = g_new(char *, g_list_length(interface_list) + 1);
+
+ // Convert list of interfaces to the array of names
+ for (plist = g_list_first(interface_list);
+ plist;
+ plist = g_list_next(plist)) {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+ list[i++] = strdup(ifconfig->name);
+ }
+ list[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free(interface_list);
+ return TRUE;
}
gboolean
-Network_start(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_start(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int status;
-
- if (!check_authorization(NETWORK_BUS_NAME ".start", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- status = interface_status(iface);
- if (status != RUNNING)
- {
- mh_network_start(iface);
+ GError* error = NULL;
+ int status;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".start", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
status = interface_status(iface);
- }
- dbus_g_method_return(context, status);
- return TRUE;
+ if (status != RUNNING) {
+ mh_network_start(iface);
+ status = interface_status(iface);
+ }
+ dbus_g_method_return(context, status);
+ return TRUE;
}
gboolean
-Network_stop(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_stop(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int status;
-
- if (!check_authorization(NETWORK_BUS_NAME ".stop", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- status = interface_status(iface);
- if (status != INACTIVE)
- {
- mh_network_stop(iface);
+ GError* error = NULL;
+ int status;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".stop", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
status = interface_status(iface);
- }
- dbus_g_method_return(context, status);
- return TRUE;
+ if (status != INACTIVE) {
+ mh_network_stop(iface);
+ status = interface_status(iface);
+ }
+ dbus_g_method_return(context, status);
+ return TRUE;
}
gboolean
-Network_status(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_status(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".status", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, interface_status(iface));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".status", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, interface_status(iface));
+ return TRUE;
}
gboolean
-Network_get_ip_address(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_get_ip_address(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".get_ip_address", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, g_strdup(mh_network_get_ip_address(iface)));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".get_ip_address", &error,
+ context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, g_strdup(mh_network_get_ip_address(iface)));
+ return TRUE;
}
gboolean
-Network_get_mac_address(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_get_mac_address(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".get_mac_address", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, g_strdup(mh_network_get_mac_address(iface)));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".get_mac_address", &error,
+ context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, g_strdup(mh_network_get_mac_address(iface)));
+ return TRUE;
}
/* Generated dbus stuff for network
@@ -184,37 +185,38 @@ Network_get_mac_address(Matahari *matahari, const char *iface, DBusGMethodInvoca
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- // We don't have writable other property...
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ // We don't have writable other property...
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_hostname());
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_hostname());
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- g_printerr("Type of property %s is map of unknown types\n", properties[prop].name);
- return G_TYPE_VALUE;
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
}
int
main(int argc, char** argv)
{
- g_type_init();
- return run_dbus_server(NETWORK_BUS_NAME, NETWORK_OBJECT_PATH);
+ g_type_init();
+ return run_dbus_server(NETWORK_BUS_NAME, NETWORK_OBJECT_PATH);
}
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index c039235..8e9e247 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -59,16 +59,17 @@ main(int argc, char **argv)
return rc;
}
-static int interface_status(const char *iface)
+static int
+interface_status(const char *iface)
{
uint64_t flags = 0;
- if(iface == NULL)
- return 3;
+ if (iface == NULL)
+ return 3;
mh_network_status(iface, &flags);
- if(flags & SIGAR_IFF_UP) {
- return 0;
+ if (flags & SIGAR_IFF_UP) {
+ return 0;
}
return 1; /* Inactive */
}
@@ -87,7 +88,8 @@ NetAgent::setup(qmf::AgentSession session)
}
gboolean
-NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
if (event.getType() != qmf::AGENT_METHOD) {
session.methodSuccess(event);
@@ -104,32 +106,40 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user
sigar_net_interface_config_t *ifconfig = NULL;
interface_list = mh_network_get_interfaces();
- for (plist = g_list_first(interface_list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(interface_list); plist;
+ plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
s_list.push_back(ifconfig->name);
}
event.addReturnArgument("iface_map", s_list);
} else if (methodName == "start") {
- int rc = interface_status(event.getArguments()["iface"].asString().c_str());
+ int rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
if (rc == 1) {
mh_network_start(event.getArguments()["iface"].asString().c_str());
- rc = interface_status(event.getArguments()["iface"].asString().c_str());
+ rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "stop") {
- int rc = interface_status(event.getArguments()["iface"].asString().c_str());
+ int rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
if (rc == 0) {
mh_network_stop(event.getArguments()["iface"].asString().c_str());
- rc = interface_status(event.getArguments()["iface"].asString().c_str());
+ rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "status") {
- event.addReturnArgument("status", interface_status(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("status", interface_status(
+ event.getArguments()["iface"].asString().c_str()));
} else if (methodName == "get_ip_address") {
- event.addReturnArgument("ip", mh_network_get_ip_address(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("ip", mh_network_get_ip_address(
+ event.getArguments()["iface"].asString().c_str()));
} else if (methodName == "get_mac_address") {
- event.addReturnArgument("mac", mh_network_get_mac_address(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("mac", mh_network_get_mac_address(
+ event.getArguments()["iface"].asString().c_str()));
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
diff --git a/src/service/service-dbus.c b/src/service/service-dbus.c
index 23768d8..8d7c56e 100644
--- a/src/service/service-dbus.c
+++ b/src/service/service-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Radek Novacek <rnovacek(a)redhat.com>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -43,174 +43,175 @@
gboolean
Services_list(Matahari *matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int i = 0;
- GList *services;
- char **list;
+ GError* error = NULL;
+ int i = 0;
+ GList *services;
+ char **list;
- if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
+ if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
- // Get list of services
- services = services_list();
+ // Get list of services
+ services = services_list();
- // Convert GList to (char **)
- list = g_new(char *, g_list_length(services) + 1);
- for (; services != NULL; services = services->next)
- list[i++] = strdup(services->data);
- list[i] = NULL; // Sentinel
+ // Convert GList to (char **)
+ list = g_new(char *, g_list_length(services) + 1);
+ for (; services != NULL; services = services->next)
+ list[i++] = strdup(services->data);
+ list[i] = NULL; // Sentinel
- dbus_g_method_return(context, list);
- g_strfreev(list);
- g_list_free(services);
- return TRUE;
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free(services);
+ return TRUE;
}
gboolean
-Services_enable(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_enable(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- gboolean res;
+ GError* error = NULL;
+ svc_action_t *op;
+ gboolean res;
- if (!check_authorization(SERVICES_BUS_NAME ".enable", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "enable", 0, TIMEOUT_MS);
- res = services_action_sync(op);
- services_action_free(op);
- dbus_g_method_return(context, res);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".enable", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "enable", 0, TIMEOUT_MS);
+ res = services_action_sync(op);
+ services_action_free(op);
+ dbus_g_method_return(context, res);
+ return res;
}
gboolean
-Services_disable(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_disable(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- gboolean res;
+ GError* error = NULL;
+ svc_action_t *op;
+ gboolean res;
- if (!check_authorization(SERVICES_BUS_NAME ".disable", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "disable", 0, TIMEOUT_MS);
- res = services_action_sync(op);
- services_action_free(op);
- dbus_g_method_return(context, res);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".disable", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "disable", 0, TIMEOUT_MS);
+ res = services_action_sync(op);
+ services_action_free(op);
+ dbus_g_method_return(context, res);
+ return res;
}
gboolean
-Services_start(Matahari *matahari, const char *name, unsigned int timeout, DBusGMethodInvocation *context)
+Services_start(Matahari *matahari, const char *name, unsigned int timeout,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".start", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "start", 0, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".start", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "start", 0, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_stop(Matahari *matahari, const char *name, unsigned int timeout, DBusGMethodInvocation *context)
+Services_stop(Matahari *matahari, const char *name, unsigned int timeout,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".stop", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "stop", 0, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".stop", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "stop", 0, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_status(Matahari *matahari, const char *name, unsigned int interval, unsigned int timeout, DBusGMethodInvocation *context)
+Services_status(Matahari *matahari, const char *name, unsigned int interval,
+ unsigned int timeout, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".status", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "status", interval, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".status", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "status", interval, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_cancel(Matahari *matahari, const char *name, const char *action, unsigned int interval, DBusGMethodInvocation *context)
+Services_cancel(Matahari *matahari, const char *name, const char *action,
+ unsigned int interval, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int res;
+ GError* error = NULL;
+ int res;
- if (!check_authorization(SERVICES_BUS_NAME ".cancel", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- res = services_action_cancel(name, action, interval);
- dbus_g_method_return(context);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".cancel", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ res = services_action_cancel(name, action, interval);
+ dbus_g_method_return(context);
+ return res;
}
gboolean
-Services_fail(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_fail(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(SERVICES_BUS_NAME ".fail", &error, context))
- {
+ GError* error = NULL;
+ if (!check_authorization(SERVICES_BUS_NAME ".fail", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action fail is not implemented yet!");
dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action fail is not implemented yet!");
- dbus_g_method_return_error(context, error);
- return TRUE;
+ return TRUE;
}
gboolean
-Services_describe(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_describe(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(SERVICES_BUS_NAME ".describe", &error, context))
- {
+ GError* error = NULL;
+ if (!check_authorization(SERVICES_BUS_NAME ".describe", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action describe is not implemented yet!");
dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action describe is not implemented yet!");
- dbus_g_method_return_error(context, error);
- return TRUE;
+ return TRUE;
}
/* Generated dbus stuff for services
@@ -220,37 +221,38 @@ Services_describe(Matahari *matahari, const char *name, DBusGMethodInvocation *c
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- // We don't have writable other property...
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ // We don't have writable other property...
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_hostname());
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_hostname());
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- g_printerr("Type of property %s is map of unknown types\n", properties[prop].name);
- return G_TYPE_VALUE;
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
}
int
main(int argc, char** argv)
{
- g_type_init();
- return run_dbus_server(SERVICES_BUS_NAME, SERVICES_OBJECT_PATH);
+ g_type_init();
+ return run_dbus_server(SERVICES_BUS_NAME, SERVICES_OBJECT_PATH);
}
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index 06c670f..b865921 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -44,26 +44,28 @@ enum service_id {
class SrvAgent : public MatahariAgent
{
- private:
- void action_async(enum service_id service, qmf::AgentSession& session,
- qmf::AgentEvent& event, svc_action_t *op, bool has_rc);
+private:
+ void action_async(enum service_id service, qmf::AgentSession& session,
+ qmf::AgentEvent& event, svc_action_t *op, bool has_rc);
- qmf::Data _services;
- qmf::DataAddr _services_addr;
+ qmf::Data _services;
+ qmf::DataAddr _services_addr;
- qmf::Data _resources;
- qmf::DataAddr _resources_addr;
+ qmf::Data _resources;
+ qmf::DataAddr _resources_addr;
- gboolean invoke_services(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
- gboolean invoke_resources(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
+ gboolean invoke_services(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
+ gboolean invoke_resources(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
- qmf::org::matahariproject::PackageDefinition _package;
+ qmf::org::matahariproject::PackageDefinition _package;
- public:
- virtual int setup(qmf::AgentSession session);
- virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer user_data);
- void raiseEvent(svc_action_t *op, enum service_id service);
+public:
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
+ void raiseEvent(svc_action_t *op, enum service_id service);
};
/**
@@ -115,7 +117,7 @@ AsyncCB::mh_async_callback(svc_action_t *op)
cb_data->first_result = false;
} else if (cb_data->last_rc != op->rc) {
mh_trace("Result changed on recurring action: was '%d', now '%d'\n",
- cb_data->last_rc, op->rc);
+ cb_data->last_rc, op->rc);
cb_data->agent->raiseEvent(op, cb_data->service);
}
@@ -127,13 +129,14 @@ AsyncCB::mh_async_callback(svc_action_t *op)
}
}
-static GHashTable *qmf_map_to_hash(::qpid::types::Variant::Map parameters)
+static GHashTable *
+qmf_map_to_hash(::qpid::types::Variant::Map parameters)
{
qpid::types::Variant::Map::const_iterator qIter;
GHashTable *hash = g_hash_table_new_full(
g_str_hash, g_str_equal, free, free);
- for (qIter=parameters.begin() ; qIter != parameters.end(); qIter++ ) {
+ for (qIter = parameters.begin(); qIter != parameters.end(); qIter++) {
char *key = strdup(qIter->first.c_str());
char *value = strdup(qIter->second.asString().c_str());
g_hash_table_insert(hash, key, value);
@@ -148,7 +151,7 @@ main(int argc, char **argv)
SrvAgent agent;
int rc = agent.init(argc, argv, "service");
- if(rc >= 0) {
+ if (rc >= 0) {
mainloop_track_children(G_PRIORITY_DEFAULT);
agent.run();
}
@@ -156,7 +159,8 @@ main(int argc, char **argv)
return rc;
}
-void SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
+void
+SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
{
uint64_t timestamp = 0L;
qmf::Data event;
@@ -165,7 +169,7 @@ void SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
timestamp = ::time(NULL);
#endif
- if(service) {
+ if (service) {
event = qmf::Data(_package.event_service_op);
} else {
event = qmf::Data(_package.event_resource_op);
@@ -209,10 +213,11 @@ SrvAgent::setup(qmf::AgentSession session)
}
gboolean
-SrvAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+SrvAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
- if(event.getType() == qmf::AGENT_METHOD && event.hasDataAddr()) {
- if(_services_addr == event.getDataAddr()) {
+ if (event.getType() == qmf::AGENT_METHOD && event.hasDataAddr()) {
+ if (_services_addr == event.getDataAddr()) {
mh_info("Calling services API");
return invoke_services(session, event, user_data);
}
@@ -234,11 +239,12 @@ SrvAgent::action_async(enum service_id service, qmf::AgentSession& session,
}
gboolean
-SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
static const int default_timeout_ms = 60000;
const std::string& methodName(event.getMethodName());
- if(event.getType() != qmf::AGENT_METHOD) {
+ if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
}
@@ -250,8 +256,8 @@ SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event, gpoi
GList *gIter = NULL;
GList *services = services_list();
- for(gIter = services; gIter != NULL; gIter = gIter->next) {
- s_list.push_back((const char *)gIter->data);
+ for (gIter = services; gIter != NULL; gIter = gIter->next) {
+ s_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("services", s_list);
@@ -313,10 +319,11 @@ SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event, gpoi
}
gboolean
-SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
const std::string& methodName(event.getMethodName());
- if(event.getType() != qmf::AGENT_METHOD) {
+ if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
}
@@ -334,8 +341,8 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event, gpo
GList *providers = resources_list_ocf_providers();
_qtype::Variant::List p_list;
- for(gIter = providers; gIter != NULL; gIter = gIter->next) {
- p_list.push_back((const char *)gIter->data);
+ for (gIter = providers; gIter != NULL; gIter = gIter->next) {
+ p_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("providers", p_list);
@@ -345,8 +352,8 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event, gpo
args["provider"].asString().c_str());
_qtype::Variant::List t_list;
- for(gIter = agents; gIter != NULL; gIter = gIter->next) {
- t_list.push_back((const char *)gIter->data);
+ for (gIter = agents; gIter != NULL; gIter = gIter->next) {
+ t_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("types", t_list);
diff --git a/src/tests/t_dnssrv.c b/src/tests/t_dnssrv.c
index 0829f64..91b2772 100644
--- a/src/tests/t_dnssrv.c
+++ b/src/tests/t_dnssrv.c
@@ -24,10 +24,10 @@ int main(int argc, char **argv)
struct srv_reply **srvl = NULL, *srv = NULL;
int i;
- if(srvl = srv_lookup("qpid-broker", "tcp", "qpid-broker:49000")) {
+ if (srvl = srv_lookup("qpid-broker", "tcp", "qpid-broker:49000")) {
srv = *srvl;
- for(i = 1; srvl[i]; i++) {
- if(srvl[i]->prio < srv->prio)
+ for (i = 1; srvl[i]; i++) {
+ if (srvl[i]->prio < srv->prio)
srv = srvl[i];
}
--
1.7.5.1
13 years
Fwd: Re: [augeas-devel] Augeas-based configuration agent
by Radek Novacek
Forwarded from augeas-devel. I think the suggested API could work for us quite
well. Our config agent will be reduced to only one method "run" which will
take string (commands separated by \n) or list of strings (augeas commands)
and some flags (e.g. bool for suggested AUG_RUN_CONTINUE). This method will
return error code and content of "out" file (maybe parsed somehow).
Do you agree with this proposal?
Radek Novacek
---------- Forwarded Message ----------
Subject: Re: [augeas-devel] [Matahari] Augeas-based configuration agent
Date: Thursday 12 of May 2011, 01:01:10
From: David Lutterkort <lutter(a)redhat.com>
To: augeas-devel(a)redhat.com
On Wed, 2011-05-11 at 09:24 +0200, Radek Novacek wrote:
> (resended as I wasn't member of augeas-devel mailing list)
>
> > I was hoping somebody would just cook up a patch based on augtool ;) It
> > shouldn't be much more work than doing it (yet again) for standalone
> > use.
>
> I can try to do it. To be clear, the task is to add method to augeas library
> called e.g. batch, which takes string argument. In this argument will be
> command (or semicolon separated list of commands) same as for augtool. What
> will the method return? True only if all commands succeeds, false otherwise?
All good questions; I initially thought we could just take parts of
augtool.c (roughly run_command and everything it depends on) and put it
behind the API. One of my goals here is that augtool can use this new
API, without any changes in its behavior.
Besides how to indicate errors, the other question is how to deal with
all the printing to stdout and stderr that the various cmd_* handlers in
augtool.c do right now. One option would be to let the caller pass in
file pointers for that.
I am thinking we should add two functions to the API:
int aug_srun(augeas *aug,
const char *text, size_t text_len,
FILE *out, unsigned int flags)
and
int aug_frun(augeas *aug,
FILE *in, FILE *out,
unsigned int flags)
The functions return 0 on success and -1 on error; further details about
the error can be found with aug_error; if that returns AUG_ECOMMAND,
something went wrong with parsing a command. We can use
aug_error_minor_message and aug_error_details to provide more error
information.
The commands are either read from TEXT (aug_srun) or from IN (aug_frun,
reads till EOF); commands must be separated by newlines. I don't think
there's any point in getting fancy with semicolons.
If OUT is non-NULL, commands that produce output (e.g.
'get /augeas/version' or 'print /files/etc/hosts') will print that on
OUT. That way, augtool can just pass stdout and the user should see
output identical to the current output.
By default, executing commands is aborted when an error is encountered;
by setting FLAGS to AUG_RUN_CONTINUE, errors are ignored as much as
possible (e.g., a syntax error will be ignored, but an OOM would still
lead to returning with an error)
How does all that sound ? Since this now seems a little more involved
than I first thought, I might have a crack at it tomorrow. Please let me
know if the suggested API's would work for you.
David
_______________________________________________
augeas-devel mailing list
augeas-devel(a)redhat.com
https://www.redhat.com/mailman/listinfo/augeas-devel
-----------------------------------------
13 years
[PATCH] Allow the option to disable reconnect on failure
by Adam Stokes
From: Adam Stokes <astokes(a)fedoraproject.org>
- We hardcoded reconnect to True in our agent code but this can hinder us when wanting to automate testing. We set reconnect to false by default and have the user decide whether or not they want their agents to keep trying to connect to a failed/misconfigured broker.
---
src/lib/mh_agent.cpp | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index d8f8417..23f5e3f 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -91,6 +91,7 @@ struct option opt[] = {
{"password", required_argument, NULL, 'P'},
{"service", required_argument, NULL, 's'},
{"port", required_argument, NULL, 'p'},
+ {"reconnect", no_argument, NULL, 'r'},
{0, 0, 0, 0}
};
@@ -106,6 +107,7 @@ print_usage(const char *proc_name)
printf("\t-P | --password password to use for authentication purproses.\n");
printf("\t-s | --service service name to use for authentication purproses.\n");
printf("\t-p | --port specify broker port.\n");
+ printf("\t-r | --reconnect attempt to reconnect on failure.\n");
}
#endif
@@ -140,6 +142,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
#endif
bool gssapi = false;
+ bool reconnect = false;
char *servername = NULL;
char *username = NULL;
char *password = NULL;
@@ -201,7 +204,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
#else
// Get args
- while ((arg = getopt_long(argc, argv, "hdb:gu:P:s:p:v", opt, &idx)) != -1) {
+ while ((arg = getopt_long(argc, argv, "hdb:gru:P:s:p:v", opt, &idx)) != -1) {
switch (arg) {
case 'h':
case '?':
@@ -242,6 +245,9 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
case 'g':
gssapi = true;
break;
+ case 'r':
+ reconnect = true;
+ break;
case 'p':
if (optarg) {
serverport = atoi(optarg);
@@ -288,7 +294,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
// Create a v2 API options map.
qpid::types::Variant::Map options;
- options["reconnect"] = bool(true);
+ options["reconnect"] = reconnect;
if (username && *username) {
options["username"] = username;
}
--
1.7.4.4
13 years