[PATCH] Fix various memory leaks.
by Jaroslav Skarvada
This is attempt to fix several (not all) memory leaks.
---
src/config/config-qmf.cpp | 8 ++++++--
src/host/host-dbus.c | 19 +++++++++++++------
src/host/host-qmf.cpp | 19 +++++++++++++------
src/network/network-dbus.c | 10 +++++++---
src/network/network-qmf.cpp | 18 ++++++++++++++----
src/service/service-qmf-console.cpp | 5 ++++-
src/service/service-qmf.cpp | 14 ++++++++++----
7 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/src/config/config-qmf.cpp b/src/config/config-qmf.cpp
index de3e669..8244cb6 100644
--- a/src/config/config-qmf.cpp
+++ b/src/config/config-qmf.cpp
@@ -63,11 +63,15 @@ main(int argc, char **argv)
int
ConfigAgent::setup(qmf::AgentSession session)
{
+ char *str;
+
_package.configure(session);
_instance = qmf::Data(_package.data_Config);
- _instance.setProperty("hostname", mh_hostname());
- _instance.setProperty("uuid", mh_uuid());
+ _instance.setProperty("hostname", str = (char *)mh_hostname());
+ free(str);
+ _instance.setProperty("uuid", str = (char *)mh_uuid());
+ free(str);
_instance.setProperty("is_configured", mh_is_configured());
_agent_session.addData(_instance, "config");
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index 612b457..6368eb7 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -114,19 +114,24 @@ matahari_get_property(GObject *object, guint property_id, GValue *value,
sigar_loadavg_t avg;
Dict *dict;
GValue value_value = {0, };
+ char *str;
switch (property_id) {
case PROP_UUID:
- g_value_set_string (value, mh_host_get_uuid());
+ g_value_set_string (value, str = (char *)mh_host_get_uuid());
+ free(str);
break;
case PROP_HOSTNAME:
- g_value_set_string (value, mh_host_get_hostname());
+ g_value_set_string (value, str = (char *)mh_host_get_hostname());
+ free(str);
break;
case PROP_OS:
- g_value_set_string (value, mh_host_get_operating_system());
+ g_value_set_string (value, str = (char *)mh_host_get_operating_system());
+ g_free(str);
break;
case PROP_ARCH:
- g_value_set_string (value, mh_host_get_architecture());
+ g_value_set_string (value, str = (char *)mh_host_get_architecture());
+ g_free(str);
break;
case PROP_WORDSIZE:
g_value_set_uint (value, mh_host_get_cpu_wordsize());
@@ -144,10 +149,12 @@ matahari_get_property(GObject *object, guint property_id, GValue *value,
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());
+ g_value_set_string (value, str = (char *)mh_host_get_cpu_model());
+ g_free(str);
break;
case PROP_CPU_FLAGS:
- g_value_set_string (value, mh_host_get_cpu_flags());
+ g_value_set_string (value, str = (char *)mh_host_get_cpu_flags());
+ free(str);
break;
case PROP_UPDATE_INTERVAL:
g_value_set_uint (value, priv.update_interval);
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 7547daf..1561226 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -94,21 +94,28 @@ bail:
int
HostAgent::setup(qmf::AgentSession session)
{
+ char *str;
_package.configure(session);
_instance = qmf::Data(_package.data_Host);
_instance.setProperty("update_interval", 5);
- _instance.setProperty("uuid", mh_host_get_uuid());
- _instance.setProperty("hostname", mh_host_get_hostname());
- _instance.setProperty("os", mh_host_get_operating_system());
+ _instance.setProperty("uuid", str = (char *)mh_host_get_uuid());
+ free(str);
+ _instance.setProperty("hostname", str = (char *)mh_host_get_hostname());
+ free(str);
+ _instance.setProperty("os", str = (char *)mh_host_get_operating_system());
+ g_free(str);
_instance.setProperty("wordsize", mh_host_get_cpu_wordsize());
- _instance.setProperty("arch", mh_host_get_architecture());
+ _instance.setProperty("arch", str = (char *)mh_host_get_architecture());
+ g_free(str);
_instance.setProperty("memory", mh_host_get_memory());
_instance.setProperty("swap", mh_host_get_swap());
_instance.setProperty("cpu_count", mh_host_get_cpu_count());
_instance.setProperty("cpu_cores", mh_host_get_cpu_number_of_cores());
- _instance.setProperty("cpu_model", mh_host_get_cpu_model());
- _instance.setProperty("cpu_flags", mh_host_get_cpu_flags());
+ _instance.setProperty("cpu_model", str = (char *)mh_host_get_cpu_model());
+ g_free(str);
+ _instance.setProperty("cpu_flags", str = (char *)mh_host_get_cpu_flags());
+ free(str);
session.addData(_instance);
return 0;
diff --git a/src/network/network-dbus.c b/src/network/network-dbus.c
index 31040d2..49dd657 100644
--- a/src/network/network-dbus.c
+++ b/src/network/network-dbus.c
@@ -83,6 +83,7 @@ Network_list(Matahari *matahari, DBusGMethodInvocation *context)
plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
list[i++] = strdup(ifconfig->name);
+ g_free(plist->data);
}
list[i] = NULL; // Sentinel
@@ -159,7 +160,7 @@ Network_get_ip_address(Matahari *matahari, const char *iface,
return FALSE;
}
- dbus_g_method_return(context, g_strdup(mh_network_get_ip_address(iface)));
+ dbus_g_method_return(context, mh_network_get_ip_address(iface));
return TRUE;
}
@@ -174,7 +175,7 @@ Network_get_mac_address(Matahari *matahari, const char *iface,
return FALSE;
}
- dbus_g_method_return(context, g_strdup(mh_network_get_mac_address(iface)));
+ dbus_g_method_return(context, mh_network_get_mac_address(iface));
return TRUE;
}
@@ -195,9 +196,12 @@ void
matahari_get_property(GObject *object, guint property_id, GValue *value,
GParamSpec *pspec)
{
+ char *str;
+
switch (property_id) {
case PROP_HOSTNAME:
- g_value_set_string (value, mh_hostname());
+ g_value_set_string (value, str = (char *)mh_hostname());
+ free(str);
break;
default:
/* We don't have any other property... */
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index 8e9e247..fb501ec 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -77,11 +77,15 @@ interface_status(const char *iface)
int
NetAgent::setup(qmf::AgentSession session)
{
+ char *str;
+
_package.configure(session);
_instance = qmf::Data(_package.data_Network);
- _instance.setProperty("hostname", mh_hostname());
- _instance.setProperty("uuid", mh_uuid());
+ _instance.setProperty("hostname", str = (char *)mh_hostname());
+ free(str);
+ _instance.setProperty("uuid", str = (char *)mh_uuid());
+ free(str);
_agent_session.addData(_instance);
return 0;
@@ -91,6 +95,8 @@ gboolean
NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user_data)
{
+ char *str;
+
if (event.getType() != qmf::AGENT_METHOD) {
session.methodSuccess(event);
return TRUE;
@@ -110,7 +116,9 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
s_list.push_back(ifconfig->name);
+ g_free(plist->data);
}
+ g_list_free(interface_list);
event.addReturnArgument("iface_map", s_list);
} else if (methodName == "start") {
int rc = interface_status(
@@ -135,11 +143,13 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
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.addReturnArgument("ip", str = (char *)mh_network_get_ip_address(
event.getArguments()["iface"].asString().c_str()));
+ g_free(str);
} else if (methodName == "get_mac_address") {
- event.addReturnArgument("mac", mh_network_get_mac_address(
+ event.addReturnArgument("mac", str = (char *)mh_network_get_mac_address(
event.getArguments()["iface"].asString().c_str()));
+ g_free(str);
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
diff --git a/src/service/service-qmf-console.cpp b/src/service/service-qmf-console.cpp
index dac8bca..406ce7e 100644
--- a/src/service/service-qmf-console.cpp
+++ b/src/service/service-qmf-console.cpp
@@ -70,9 +70,12 @@ int main(int argc, char** argv)
string sessionOptions;
ConsoleEvent event;
Agent agent;
+ char *str;
options["api"] = "Resources";
- options["host-dns"] = mh_hostname();
+ str = (char *)mh_hostname();
+ options["host-dns"] = str;
+ free(str);
options["standard"] = "ocf";
options["provider"] = "heartbeat";
options["interval"] = 0;
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index f02fb80..cc970ee 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -213,6 +213,8 @@ SrvAgent::raiseEvent(svc_action_t *op, enum service_id service, const char *user
int
SrvAgent::setup(qmf::AgentSession session)
{
+ char *str;
+
#ifdef __linux__
standards.push_back("ocf");
#endif
@@ -225,15 +227,19 @@ SrvAgent::setup(qmf::AgentSession session)
_services = qmf::Data(_package.data_Services);
- _services.setProperty("uuid", mh_uuid());
- _services.setProperty("hostname", mh_hostname());
+ _services.setProperty("uuid", str = (char *)mh_uuid());
+ free(str);
+ _services.setProperty("hostname", str = (char *)mh_hostname());
+ free(str);
session.addData(_services, "Services");
_resources = qmf::Data(_package.data_Resources);
- _resources.setProperty("uuid", mh_uuid());
- _resources.setProperty("hostname", mh_hostname());
+ _resources.setProperty("uuid", str = (char *)mh_uuid());
+ free(str);
+ _resources.setProperty("hostname", str = (char *)mh_hostname());
+ free(str);
session.addData(_resources, "Resources");
--
1.7.5.2
12 years, 10 months
[PATCH] Cache the result of event.getArguments().
by russell@russellbryant.net
This function uses this in a number of places. Call it once, hold a
const reference, and use that instead of calling the function multiple
times.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/network/network-qmf.cpp | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index e8a1d05..d74515d 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -97,6 +97,7 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
}
const std::string& methodName(event.getMethodName());
+ qpid::types::Variant::Map& args = event.getArguments();
if (methodName == "list") {
GList *plist = NULL;
@@ -115,35 +116,35 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
event.addReturnArgument("iface_map", s_list);
} else if (methodName == "start") {
int rc = interface_status(
- event.getArguments()["iface"].asString().c_str());
+ args["iface"].asString().c_str());
if (rc == 1) {
- mh_network_start(event.getArguments()["iface"].asString().c_str());
+ mh_network_start(args["iface"].asString().c_str());
rc = interface_status(
- event.getArguments()["iface"].asString().c_str());
+ args["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "stop") {
int rc = interface_status(
- event.getArguments()["iface"].asString().c_str());
+ args["iface"].asString().c_str());
if (rc == 0) {
- mh_network_stop(event.getArguments()["iface"].asString().c_str());
+ mh_network_stop(args["iface"].asString().c_str());
rc = interface_status(
- event.getArguments()["iface"].asString().c_str());
+ args["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "status") {
event.addReturnArgument("status", interface_status(
- event.getArguments()["iface"].asString().c_str()));
+ args["iface"].asString().c_str()));
} else if (methodName == "get_ip_address") {
char buf[64];
event.addReturnArgument("ip", mh_network_get_ip_address(
- event.getArguments()["iface"].asString().c_str(),
+ args["iface"].asString().c_str(),
buf, sizeof(buf)));
} else if (methodName == "get_mac_address") {
char buf[32];
event.addReturnArgument("mac", mh_network_get_mac_address(
- event.getArguments()["iface"].asString().c_str(),
+ args["iface"].asString().c_str(),
buf, sizeof(buf)));
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
--
1.7.5.4
12 years, 10 months
[PATCH] Convert README to markdown format.
by russell@russellbryant.net
This format is still easily readable in plain text, but can also be
converted into other formats. Github will automatically convert it to
HTML for display on the project page.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
README | 61 -------------------------------------------------------
README.markdown | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 61 deletions(-)
delete mode 100644 README
create mode 100644 README.markdown
diff --git a/README b/README
deleted file mode 100644
index 0007b59..0000000
--- a/README
+++ /dev/null
@@ -1,61 +0,0 @@
---------------------------------------------------
-* Matahari Agents Build and Install Instructions *
---------------------------------------------------
-
-------------------------
-* Building from source *
-------------------------
-
-*Step 1* Install Build Dependencies
-
-Matahari has build dependencies on the following packages:
-
-1. pcre-devel
-2. glib2-devel
-3. qmf
-4. qmf-devel
-5. qpid-cpp-client
-6. qpid-cpp-serer
-7. qpid-cpp-client-devel
-8. qpid-cpp-server-devel
-9. sigar
-10. sigar-devel
-
-These packages may be available in your distribution. In Fedora 14, they can
-be installed via the yum command.
-
-*Step 2* Build Mataharhi
-
-user% make
-user% cd linux.build
-user% make
-user# make install
-
-------------------------------------
-* Installing on Fedora 14 or later *
-------------------------------------
-Matahari is pre-packaged for Fedora 14 and later.
-
-user# yum install matahari
-
-------------------------
-* Windows instructions *
-------------------------
-On your Fedora box first:
- yum install mingw32-matahari
-
- copy the /usr/share/matahari*/*iso to Windows machine.( or burn iso )
- load iso/cd; run setup
-
-Please see: https://fedorahosted.org/matahari/
-
---------------------
-* If you get stuck *
---------------------
-Join the appropriate mailing lists for help with building or installing
-Matahari:
-
-- Matahari
- https://fedorahosted.org/mailman/listinfo/matahari
-- Cloud APIs
- http://www.redhat.com/mailman/listinfo/cloud-apis
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..3abfa0b
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,57 @@
+# Matahari
+
+-------------------------------------------------------------------------------
+
+## Matahari Agents Build and Install Instructions
+
+### Building from source
+
+*Step 1* - Install Build Dependencies
+
+Matahari has build dependencies on the following packages:
+
+1. pcre-devel
+2. glib2-devel
+3. qmf
+4. qmf-devel
+5. qpid-cpp-client
+6. qpid-cpp-serer
+7. qpid-cpp-client-devel
+8. qpid-cpp-server-devel
+9. sigar
+10. sigar-devel
+
+These packages may be available in your distribution. In Fedora 14, they can
+be installed via the yum command.
+
+*Step 2* - Build Mataharhi
+
+ user% make
+ user% cd linux.build
+ user% make
+ user# make install
+
+### Installing on Fedora 14 or later
+
+Matahari is pre-packaged for Fedora 14 and later.
+
+ user# yum install matahari
+
+### Windows instructions
+
+On your Fedora box first:
+
+ yum install mingw32-matahari
+
+ copy the /usr/share/matahari*/*iso to Windows machine.( or burn iso )
+ load iso/cd; run setup
+
+Please see: https://fedorahosted.org/matahari/
+
+## If you get stuck
+
+Join the appropriate mailing lists for help with building or installing
+Matahari:
+
+- [Matahari](https://fedorahosted.org/mailman/listinfo/matahari)
+- [Cloud APIs](http://www.redhat.com/mailman/listinfo/cloud-apis)
--
1.7.5.4
12 years, 10 months
[PATCH] Implement the identify method for Host agents.
by russell@russellbryant.net
This patch implements the identify method that was defined for the Host
API. The implementation triggers a system beep for 1 second when the
identify method is invoked.
This implementation is based on documentation that I found for how to
trigger a system beep on Linux and windows. It still needs to be
tested to make sure it actually works...
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/host/host-dbus.c | 4 +---
src/host/host-qmf.cpp | 2 ++
src/include/matahari/host.h | 10 +++++++++-
src/lib/host.c | 6 ++++++
src/lib/host_linux.c | 27 +++++++++++++++++++++++++++
src/lib/host_private.h | 9 +++++++++
src/lib/host_windows.c | 14 ++++++++++++++
7 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index 612b457..0c7284e 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -53,9 +53,7 @@ Host_identify(Matahari* matahari, DBusGMethodInvocation *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!");
+ mh_host_identify();
dbus_g_method_return(context, TRUE);
return TRUE;
}
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 96bf05c..826c6b6 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -115,6 +115,8 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
mh_host_shutdown();
} else if (methodName == "reboot") {
mh_host_reboot();
+ } else if (methodName == "identify") {
+ mh_host_identify();
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index d8d3acd..89e3a2a 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -46,7 +46,15 @@ extern int mh_host_get_cpu_count(void);
extern int mh_host_get_cpu_number_of_cores(void);
extern int mh_host_get_cpu_wordsize(void);
-extern void mh_host_identify(const unsigned int iterations);
+/**
+ * Identify a host.
+ *
+ * Trigger the system beep to help identify a host.
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+extern int mh_host_identify(void);
extern void mh_host_reboot(void);
extern void mh_host_shutdown(void);
diff --git a/src/lib/host.c b/src/lib/host.c
index 6e71db0..311149f 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -254,3 +254,9 @@ host_get_cpu_details(void)
sigar_cpu_info_list_destroy(host_init.sigar, &cpus);
}
+
+int
+mh_host_identify(void)
+{
+ return host_os_identify();
+}
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 6c1babd..c5e2c9b 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -23,11 +23,14 @@
#include <unistd.h>
#include <limits.h>
#include <string.h>
+#include <fcntl.h>
#include <sys/reboot.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
+#include <sys/ioctl.h>
#include <linux/reboot.h>
+#include <linux/kd.h>
#include <pcre.h>
@@ -133,3 +136,27 @@ host_os_shutdown(void)
{
reboot(LINUX_REBOOT_CMD_HALT);
}
+
+int
+host_os_identify(void)
+{
+ static const long DURATION = 1000; /* 1 second */
+ static const long FREQ = 440; /* 440 Hz */
+
+ int fd = open("/dev/tty", O_NOCTTY);
+ int res;
+
+ if (fd == -1) {
+ return -1;
+ }
+
+ /*
+ * Reference info on KDMKTONE:
+ * http://tldp.org/LDP/lpg/node83.html
+ */
+ res = ioctl(fd, KDMKTONE, (DURATION << 32) + (1190000 / FREQ));
+
+ close(fd);
+
+ return res;
+}
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index 0994536..2900797 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -40,4 +40,13 @@ host_os_reboot(void);
extern void
host_os_shutdown(void);
+/**
+ * Platform specific implementation of a system beep.
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+extern int
+host_os_identify(void);
+
#endif /* __MH_HOST_PRIVATE_H__ */
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index e86ff47..3bb2ab7 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -79,3 +79,17 @@ host_os_shutdown(void)
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
SHTDN_REASON_FLAG_PLANNED);
}
+
+int
+host_os_identify(void)
+{
+ static const long DURATION = 1000; /* 1 second */
+ static const long FREQ = 440; /* 440 Hz */
+
+ /*
+ * Reference for Windows Beep():
+ * http://msdn.microsoft.com/en-us/library/ms679277%28v=vs.85%29.aspx
+ */
+
+ return Beep(FREQ, DURATION) ? 0 : -1;
+}
--
1.7.5.4
12 years, 10 months
[PATCH 1/4] host-qmf: Make heartbeat_timer() a static member of HostAgent.
by russell@russellbryant.net
This patch makes heartbeat_timer() a static member function of
HostAgent. It also makes it so heartbeat() can be private. Also add
some documentation for these functions.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/host/host-qmf.cpp | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 7547daf..2397492 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -17,6 +17,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+/**
+ * \file
+ * \brief Host QMF Agent
+ */
+
#ifndef WIN32
#include "config.h"
#endif
@@ -35,19 +40,43 @@ extern "C" {
class HostAgent : public MatahariAgent
{
-private:
- qmf::org::matahariproject::PackageDefinition _package;
public:
- int heartbeat();
virtual int setup(qmf::AgentSession session);
virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user_data);
+
+ /**
+ * Send a heartbeat and reset the timer.
+ *
+ * This function should be called a single time after the HostAgent
+ * is created. From then on it will automatically reschedule itself
+ * to be called.
+ *
+ * \param[in] data a pointer to the HostAgent
+ *
+ * \retval FALSE always
+ */
+ static gboolean heartbeat_timer(gpointer data);
+
+private:
+ /**
+ * Send HostAgent heartbeat.
+ *
+ * This function gets scheduled to be called periodically in
+ * heartbeat_timer().
+ *
+ * \return the number of milliseconds until the next time heartbeat()
+ * should be called.
+ */
+ int heartbeat();
+
+ qmf::org::matahariproject::PackageDefinition _package;
};
-static gboolean
-heartbeat_timer(gpointer data)
+gboolean
+HostAgent::heartbeat_timer(gpointer data)
{
- HostAgent *agent = (HostAgent *)data;
+ HostAgent *agent = (HostAgent *) data;
g_timeout_add(agent->heartbeat(), heartbeat_timer, data);
return FALSE;
}
@@ -58,7 +87,7 @@ main(int argc, char **argv)
HostAgent *agent = new HostAgent();
int rc = agent->init(argc, argv, "host");
if (rc == 0) {
- heartbeat_timer(agent);
+ HostAgent::heartbeat_timer(agent);
agent->run();
}
--
1.7.5.4
12 years, 10 months
installation of matahari via yum
by Steven Dake
Hi,
I would expect yum -y install matahari would install all the matahari
sub-packages but it doesn't, only installing a package with a license
file. Is this intentional or a bug? This same operation on rhel6
installs all the matahari apis.
Thanks
-steve
12 years, 10 months
[PATCH] Pass an argument to --reconnect in sysconf options
by Zane Bitter
The --reconnect option has a compulsory argument, so if no argument is
included it may eat the next option passed. In the case of the init
scripts, that would be the --daemon option.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
matahari.sysconf.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/matahari.sysconf.in b/matahari.sysconf.in
index 554421f..19414b8 100644
--- a/matahari.sysconf.in
+++ b/matahari.sysconf.in
@@ -1,3 +1,3 @@
-MATAHARI_AGENT_ARGS="--reconnect"
+MATAHARI_AGENT_ARGS="--reconnect=yes"
MATAHARI_BROKER=@MATAHARI_BROKER@
MATAHARI_PORT=@MATAHARI_PORT@
12 years, 10 months
[PATCH] - Change config references to postboot
by Adam Stokes
- Better name for our configuration agent.
- Add api level tests for postboot
---
matahari.spec | 40 ++++++------
src/CMakeLists.txt | 2 +-
src/config/CMakeLists.txt | 30 ---------
src/config/config-console.cpp | 79 ------------------------
src/config/config-qmf.cpp | 102 --------------------------------
src/config/schema.xml | 16 -----
src/include/matahari/mh_agent_config.h | 34 -----------
src/include/matahari/postboot.h | 34 +++++++++++
src/lib/CMakeLists.txt | 8 +-
src/lib/mh_agent_config.c | 50 ----------------
src/lib/postboot.c | 50 ++++++++++++++++
src/postboot/CMakeLists.txt | 30 +++++++++
src/postboot/postboot-console.cpp | 79 ++++++++++++++++++++++++
src/postboot/postboot-qmf.cpp | 102 ++++++++++++++++++++++++++++++++
src/postboot/schema.xml | 16 +++++
src/tests/CMakeLists.txt | 4 +-
src/tests/mh_api_postboot.h | 34 +++++++++++
17 files changed, 373 insertions(+), 337 deletions(-)
delete mode 100644 src/config/CMakeLists.txt
delete mode 100644 src/config/config-console.cpp
delete mode 100644 src/config/config-qmf.cpp
delete mode 100644 src/config/schema.xml
delete mode 100644 src/include/matahari/mh_agent_config.h
create mode 100644 src/include/matahari/postboot.h
delete mode 100644 src/lib/mh_agent_config.c
create mode 100644 src/lib/postboot.c
create mode 100644 src/postboot/CMakeLists.txt
create mode 100644 src/postboot/postboot-console.cpp
create mode 100644 src/postboot/postboot-qmf.cpp
create mode 100644 src/postboot/schema.xml
create mode 100644 src/tests/mh_api_postboot.h
diff --git a/matahari.spec b/matahari.spec
index a52b1d7..603b70d 100644
--- a/matahari.spec
+++ b/matahari.spec
@@ -128,14 +128,14 @@ Requires: %{name}-agent-lib = %{version}-%{release}
%description service
QMF agent for viewing and controlling system services
-%package config
+%package postboot
License: GPLv2+
Summary: QMF agent for post boot configuration services.
Group: Applications/System
Requires: %{name}-lib = %{version}-%{release}
Requires: %{name}-agent-lib = %{version}-%{release}
-%description config
+%description postboot
QMF agent/console for providing post boot capabilities.
%package devel
@@ -234,24 +234,24 @@ if [ "$1" -ge "1" ]; then
/sbin/service matahari-service condrestart >/dev/null 2>&1 || :
fi
-#== Config
+#== Postboot
-%post config
-/sbin/service matahari-config condrestart
-/sbin/service matahari-config-console condrestart
+%post postboot
+/sbin/service matahari-postboot condrestart
+/sbin/service matahari-postboot-console condrestart
-%preun config
+%preun postboot
if [ $1 = 0 ]; then
- /sbin/service matahari-config-console stop >/dev/null 2>&1 || :
- /sbin/service matahari-config stop >/dev/null 2>&1 || :
- chkconfig --del matahari-config-console
- chkconfig --del matahari-config
+ /sbin/service matahari-postboot-console stop >/dev/null 2>&1 || :
+ /sbin/service matahari-postboot stop >/dev/null 2>&1 || :
+ chkconfig --del matahari-postboot-console
+ chkconfig --del matahari-postboot
fi
-%postun config
+%postun postboot
if [ "$1" -ge "1" ]; then
- /sbin/service matahari-config-console condrestart >/dev/null 2>&1 || :
- /sbin/service matahari-config condrestart >/dev/null 2>&1 || :
+ /sbin/service matahari-postboot-console condrestart >/dev/null 2>&1 || :
+ /sbin/service matahari-postboot condrestart >/dev/null 2>&1 || :
fi
#== Broker
@@ -299,7 +299,7 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%{_libdir}/libmhost.so.*
%{_libdir}/libmnetwork.so.*
%{_libdir}/libmservice.so.*
-%{_libdir}/libmconfig.so.*
+%{_libdir}/libmpostboot.so.*
%doc AUTHORS COPYING
%files network
@@ -342,15 +342,15 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%attr(755, root, root) %{_sbindir}/matahari-dbus-serviced
%endif
-%files config
+%files postboot
%defattr(644, root, root, 755)
%doc AUTHORS COPYING
%if %{with qmf}
-%attr(755, root, root) %{_initddir}/matahari-config
-%attr(755, root, root) %{_initddir}/matahari-config-console
-%attr(755, root, root) %{_sbindir}/matahari-qmf-configd
-%attr(755, root, root) %{_sbindir}/matahari-qmf-config-consoled
+%attr(755, root, root) %{_initddir}/matahari-postboot
+%attr(755, root, root) %{_initddir}/matahari-postboot-console
+%attr(755, root, root) %{_sbindir}/matahari-qmf-postbootd
+%attr(755, root, root) %{_sbindir}/matahari-qmf-postboot-consoled
%endif
%if %{with qmf}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d3fd72f..6079cfd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -133,7 +133,7 @@ add_subdirectory(lib)
add_subdirectory(host)
add_subdirectory(network)
add_subdirectory(service)
-add_subdirectory(config)
+add_subdirectory(postboot)
add_subdirectory(tests)
### Installation
diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt
deleted file mode 100644
index fb6560b..0000000
--- a/src/config/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-set(BASE "config")
-set(BASE_LIB "m${BASE}")
-set(QMF_AGENT "matahari-qmf-${BASE}d")
-set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled")
-
-# 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})
- add_executable(${QMF_CONSOLE} ${BASE}-console.cpp)
-
- target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf)
- target_link_libraries(${QMF_CONSOLE} mcommon_qmf)
-
- if(NOT WIN32)
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- # Override BASE for matahari-config-console
- unset(BASE)
- set(BASE "config-console")
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- endif(NOT WIN32)
-
- install(TARGETS ${QMF_AGENT} DESTINATION sbin)
- install(TARGETS ${QMF_CONSOLE} DESTINATION sbin)
-endif(WITH-QMF)
diff --git a/src/config/config-console.cpp b/src/config/config-console.cpp
deleted file mode 100644
index 188c443..0000000
--- a/src/config/config-console.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* config-console.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);
- // 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();
-
- Agent agent;
- while (true) {
- ConsoleEvent event;
- if(session.nextEvent(event)) {
- switch(event.getType()) {
- case CONSOLE_AGENT_ADD:
- {
- agent = event.getAgent();
- DataAddr agent_event_addr("config", agent.getName(), 0);
- ConsoleEvent result(agent.callMethod("configure",
- dataProperties,
- agent_event_addr));
- }
- break;
- default: {}
- }
- }
- }
- return 0;
-}
diff --git a/src/config/config-qmf.cpp b/src/config/config-qmf.cpp
deleted file mode 100644
index de3e669..0000000
--- a/src/config/config-qmf.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/* 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());
- _instance.setProperty("is_configured", mh_is_configured());
-
- _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();
- if(rc == 0) {
- mh_configure(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
deleted file mode 100644
index da29d0d..0000000
--- a/src/config/schema.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<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"/>
- <property name="is_configured" type="uint32" access="RO" desc="Check if agent is configured." />
-
- <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/include/matahari/mh_agent_config.h b/src/include/matahari/mh_agent_config.h
deleted file mode 100644
index 9968032..0000000
--- a/src/include/matahari/mh_agent_config.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* mh_agent_config.h - 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
- */
-
-/**
- * \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();
-extern void mh_configure(const char *uri);
-
-#endif // __MH_CONFIG_H__
diff --git a/src/include/matahari/postboot.h b/src/include/matahari/postboot.h
new file mode 100644
index 0000000..9968032
--- /dev/null
+++ b/src/include/matahari/postboot.h
@@ -0,0 +1,34 @@
+/* mh_agent_config.h - 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
+ */
+
+/**
+ * \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();
+extern void mh_configure(const char *uri);
+
+#endif // __MH_CONFIG_H__
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index d33057b..86048b9 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
# Library
-set(LIBS mcommon mhost mnetwork mservice mconfig)
+set(LIBS mcommon mhost mnetwork mservice mpostboot)
include_directories(${pcre_INCLUDE_DIRS})
# See http://sourceware.org/autobook/autobook/autobook_91.html for
@@ -22,9 +22,9 @@ add_library (mservice SHARED services.c services_${VARIANT}.c)
set_target_properties(mservice PROPERTIES SOVERSION 1.0.0)
target_link_libraries(mservice ${pcre_LIBRARIES} mcommon ${SIGAR} ${glib_LIBRARIES})
-add_library (mconfig SHARED mh_agent_config.c)
-set_target_properties(mconfig PROPERTIES SOVERSION 1.0.0)
-target_link_libraries(mconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
+add_library (mpostboot SHARED postboot.c)
+set_target_properties(mpostboot PROPERTIES SOVERSION 1.0.0)
+target_link_libraries(mpostboot ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
if(WIN32)
foreach (lib ${LIBS})
diff --git a/src/lib/mh_agent_config.c b/src/lib/mh_agent_config.c
deleted file mode 100644
index 7102f61..0000000
--- a/src/lib/mh_agent_config.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 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"
-#include <stddef.h>
-#endif
-
-#include <stdint.h>
-#include <stdio.h>
-#include <glib.h>
-#include "matahari/logging.h"
-#include "matahari/mh_agent_config.h"
-
-
-MH_TRACE_INIT_DATA(mh_config);
-
-static const char *filename = "/var/lib/matahari/.mh_configured";
-
-uint32_t mh_is_configured()
-{
- int config_file_exist = 0;
-
- if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
- config_file_exist = 1;
- }
- return config_file_exist;
-}
-
-void mh_configure(const char *uri)
-{
- if(!g_file_set_contents(filename, uri, -1, NULL)) {
- mh_log(LOG_DEBUG, "Unable to create file.");
- }
-}
diff --git a/src/lib/postboot.c b/src/lib/postboot.c
new file mode 100644
index 0000000..6f970fa
--- /dev/null
+++ b/src/lib/postboot.c
@@ -0,0 +1,50 @@
+/* postboot.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"
+#include <stddef.h>
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <glib.h>
+#include "matahari/logging.h"
+#include "matahari/postboot.h"
+
+
+MH_TRACE_INIT_DATA(mh_postboot);
+
+static const char *filename = "/var/lib/matahari/.mh_configured";
+
+uint32_t mh_is_configured()
+{
+ int config_file_exist = 0;
+
+ if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
+ config_file_exist = 1;
+ }
+ return config_file_exist;
+}
+
+void mh_configure(const char *uri)
+{
+ if(!g_file_set_contents(filename, uri, -1, NULL)) {
+ mh_log(LOG_DEBUG, "Unable to create file.");
+ }
+}
diff --git a/src/postboot/CMakeLists.txt b/src/postboot/CMakeLists.txt
new file mode 100644
index 0000000..d097fd6
--- /dev/null
+++ b/src/postboot/CMakeLists.txt
@@ -0,0 +1,30 @@
+set(BASE "postboot")
+set(BASE_LIB "m${BASE}")
+set(QMF_AGENT "matahari-qmf-${BASE}d")
+set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled")
+
+# 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})
+ add_executable(${QMF_CONSOLE} ${BASE}-console.cpp)
+
+ target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf)
+ target_link_libraries(${QMF_CONSOLE} mcommon_qmf)
+
+ if(NOT WIN32)
+ configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
+ # Override BASE for matahari-config-console
+ unset(BASE)
+ set(BASE "config-console")
+ configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
+ endif(NOT WIN32)
+
+ install(TARGETS ${QMF_AGENT} DESTINATION sbin)
+ install(TARGETS ${QMF_CONSOLE} DESTINATION sbin)
+endif(WITH-QMF)
diff --git a/src/postboot/postboot-console.cpp b/src/postboot/postboot-console.cpp
new file mode 100644
index 0000000..188c443
--- /dev/null
+++ b/src/postboot/postboot-console.cpp
@@ -0,0 +1,79 @@
+/* config-console.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);
+ // 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();
+
+ Agent agent;
+ while (true) {
+ ConsoleEvent event;
+ if(session.nextEvent(event)) {
+ switch(event.getType()) {
+ case CONSOLE_AGENT_ADD:
+ {
+ agent = event.getAgent();
+ DataAddr agent_event_addr("config", agent.getName(), 0);
+ ConsoleEvent result(agent.callMethod("configure",
+ dataProperties,
+ agent_event_addr));
+ }
+ break;
+ default: {}
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp
new file mode 100644
index 0000000..5e720c0
--- /dev/null
+++ b/src/postboot/postboot-qmf.cpp
@@ -0,0 +1,102 @@
+/* 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/postboot.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_Postboot);
+
+ _instance.setProperty("hostname", mh_hostname());
+ _instance.setProperty("uuid", mh_uuid());
+ _instance.setProperty("is_configured", mh_is_configured());
+
+ _agent_session.addData(_instance, "postboot");
+ 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();
+ if(rc == 0) {
+ mh_configure(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/postboot/schema.xml b/src/postboot/schema.xml
new file mode 100644
index 0000000..2d930ce
--- /dev/null
+++ b/src/postboot/schema.xml
@@ -0,0 +1,16 @@
+<schema package="org.matahariproject">
+
+ <!-- Config API -->
+ <class name="Postboot">
+ <property name="uuid" type="sstr" access="RO" desc="Host UUID" />
+ <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
+ <property name="is_configured" type="uint32" access="RO" desc="Check if agent is configured." />
+
+ <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/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 7e29430..b8576dd 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -5,9 +5,11 @@ if(CXXTEST_FOUND)
ENABLE_TESTING()
CXXTEST_ADD_TEST(mh_api_network_unittest network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_network.h)
CXXTEST_ADD_TEST(mh_api_host_unittest host_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_host.h)
+ CXXTEST_ADD_TEST(mh_api_postboot_unittest postboot_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_postboot.h)
add_library(mh_tester SHARED test_utilities.c)
- target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost)
+ target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost mpostboot)
target_link_libraries(mh_api_network_unittest mh_tester)
target_link_libraries(mh_api_host_unittest mh_tester)
+ target_link_libraries(mh_api_postboot_unittest mh_tester)
endif(CXXTEST_FOUND)
diff --git a/src/tests/mh_api_postboot.h b/src/tests/mh_api_postboot.h
new file mode 100644
index 0000000..5e59a9b
--- /dev/null
+++ b/src/tests/mh_api_postboot.h
@@ -0,0 +1,34 @@
+#ifndef __MH_API_NETWORK_UNITTEST_H
+#define __MH_API_NETWORK_UNITTEST_H
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <utility>
+#include <vector>
+#include <cstdlib>
+#include <cstdio>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <cxxtest/TestSuite.h>
+
+extern "C" {
+#include "matahari/postboot.h"
+#include <glib.h>
+#include "mh_test_utilities.h"
+};
+
+using namespace std;
+
+class MhApiPostbootSuite : public CxxTest::TestSuite
+{
+ public:
+
+ void testIsConfigured(void)
+ {
+ const char *uri = "http://matahariproject.org/testing.xml";
+ mh_configure(uri);
+ TS_ASSERT((mh_is_configured()) == 1);
+ }
+};
+
+#endif
--
1.7.5.2
12 years, 10 months
[PATCH] Install the mainloop.h header (required by mh_agent.h)
by Zane Bitter
---
matahari.spec | 1 +
src/CMakeLists.txt | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/matahari.spec b/matahari.spec
index a52b1d7..7624833 100644
--- a/matahari.spec
+++ b/matahari.spec
@@ -396,6 +396,7 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%if %{with qmf}
%{_includedir}/matahari/mh_agent.h
+%{_includedir}/matahari/mainloop.h
%{_datadir}/cmake/Modules/FindQPID.cmake
%endif
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5dda02d..3aece97 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -146,6 +146,7 @@ install(FILES cmake/modules/MatahariMacros.cmake DESTINATION share/cmake/Modules
if(WITH-QMF)
install(FILES cmake/modules/FindQPID.cmake DESTINATION share/cmake/Modules)
install(FILES include/matahari/mh_agent.h DESTINATION include/matahari)
+ install(FILES include/matahari/mainloop.h DESTINATION include/matahari)
endif(WITH-QMF)
if(WITH-DBUS)
12 years, 10 months
[PATCH] Whitespace fixes.
by russell@russellbryant.net
Fix mixed tab/space indentation.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/services.c | 34 +++++++++++++++++-----------------
src/lib/services_linux.c | 4 ++--
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/lib/services.c b/src/lib/services.c
index 07aba1a..44d7f4d 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -61,23 +61,23 @@ svc_action_t *resources_action_create(
asprintf(&op->id, "%s_%s_%d", name, action, interval);
if(strcmp(standard, "ocf") == 0) {
- op->provider = strdup(provider);
- op->params = params;
+ op->provider = strdup(provider);
+ op->params = params;
- 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);
+ 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);
} else if(strcmp(standard, "lsb") == 0 || strcmp(standard, "windows") == 0) {
- services_os_set_exec(op);
+ services_os_set_exec(op);
} else {
- mh_err("Unknown resource standard: %s", standard);
- services_action_free(op);
- op = NULL;
+ mh_err("Unknown resource standard: %s", standard);
+ services_action_free(op);
+ op = NULL;
}
-
+
return op;
}
@@ -186,9 +186,9 @@ GList *
resources_list_providers(const char *standard)
{
if(strcmp(standard, "ocf") == 0) {
- return resources_os_list_ocf_providers();
+ return resources_os_list_ocf_providers();
}
-
+
return NULL;
}
@@ -196,12 +196,12 @@ GList *
resources_list_agents(const char *standard, const char *provider)
{
if(strcmp(standard, "ocf") == 0) {
- return resources_os_list_ocf_agents(provider);
+ return resources_os_list_ocf_agents(provider);
} else if(strcmp(standard, "lsb") == 0
- || strcmp(standard, "windows") == 0) {
- return services_os_list();
+ || strcmp(standard, "windows") == 0) {
+ return services_os_list();
}
-
+
return NULL;
}
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 83fb604..1cc2c4d 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -191,13 +191,13 @@ operation_finished(mainloop_child_t *p, int status, int signo, int exitcode)
mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
op->status = LRM_OP_TIMEOUT;
- op->rc = OCF_TIMEOUT;
+ op->rc = OCF_TIMEOUT;
} else {
mh_warn("%s:%d - terminated with signal %d", op->id, op->pid,
signo);
op->status = LRM_OP_ERROR;
- op->rc = OCF_SIGNAL;
+ op->rc = OCF_SIGNAL;
}
} else {
--
1.7.5.4
12 years, 10 months