Connection fallback take 2 summary
by Adam Stokes
Most corner cases are met except 1. If a domain outside of localhost resolves
but I assume doesn't provide any valuable feedback. Then the connection will
just sit there without ever throwing an exception. Setting reconnect to false
fixes are previous problems where we would never break out of the initial
connection. Basically we implement our own reconnect sequence here and hope
for the best :)
Ive already sent an email to some people on qpid team asking how to break
out of a connection attempting to open with no way to throw an exception.
12 years, 9 months
Matahari release(s) for Fedora 16
by Zane Bitter
As discussed on Monday, adding the libvirt-qmf package to Fedora is
dependent on having an updated version of matahari to build against.
Since the process of adding a package may take some time and the
deadline is looming, I think we will need to do two rebases of matahari
- one for an API-stable version that libvirt-qmf can list a dependency
on, and another with all of the features scheduled for F16.
Andrew (or Russell), can you give an Ack or Nack on those patches I sent
yesterday ASAP please? Since they change the API and the locations of
header files, I need to know whether they are in or out before
delivering the libvirt-qmf patches.
Once that is settled and a rebase of the matahari package in Fedora from
upstream is done, I can deliver those changes and move forward on
creating the package. In the meantime I will work on getting the spec
file into shape on the assumption that the next matahari release will be
0.5.0.
We can then do a second rebase of matahari to pull in further
non-API-breaking stuff (e.g. Adam's sysconfig work) before the F16
deadline. Are there any objections to that plan?
thanks,
Zane.
12 years, 9 months
[PATCH] - Connection fallbacks
by Adam Stokes
This code works, however, since I'm unable to timeout initial connection
open there isn't a way to actually perform the fallback. Setting reconnect
to false causes immediate exception when broker can not be initially
contacted.
12 years, 9 months
[PATCH 1/4] Get rid of _instance member in MatahariAgent
by Zane Bitter
This is not actually required by the MatahariAgent superclass. It was acting
as a convenience for subclasses that have exactly one class in the schema.
In the case of schemas with multiple classes, which is the general case, it
didn't make a whole lot of sense. Allow each agent to define its own
instance.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/host/host-qmf.cpp | 1 +
src/include/matahari/mh_agent.h | 1 -
src/network/network-qmf.cpp | 1 +
src/postboot/postboot-qmf.cpp | 1 +
4 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 826c6b6..0a5fd08 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -71,6 +71,7 @@ private:
int heartbeat();
qmf::org::matahariproject::PackageDefinition _package;
+ qmf::Data _instance;
/**
* Default update interval for HostAgent heartbeat.
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 5b6c8a3..fbde785 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -93,7 +93,6 @@ protected:
GMainLoop *mainloop;
mainloop_qmf_t *qpid_source;
- qmf::Data _instance;
qmf::AgentSession _agent_session;
qpid::messaging::Connection _amqp_connection;
};
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index d74515d..3efe70f 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -40,6 +40,7 @@ class NetAgent : public MatahariAgent
{
private:
qmf::org::matahariproject::PackageDefinition _package;
+ qmf::Data _instance;
public:
virtual int setup(qmf::AgentSession session);
virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
diff --git a/src/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp
index 7058276..fa3bbdf 100644
--- a/src/postboot/postboot-qmf.cpp
+++ b/src/postboot/postboot-qmf.cpp
@@ -43,6 +43,7 @@ class ConfigAgent : public MatahariAgent
{
private:
qmf::org::matahariproject::PackageDefinition _package;
+ qmf::Data _instance;
public:
virtual int setup(qmf::AgentSession session);
virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
12 years, 9 months
[PATCH] - Sysconfig agent
by Adam Stokes
- Updates made based off previous ML post
https://fedorahosted.org/pipermail/matahari/2011-July/001400.html
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/include/matahari/mh_agent.h | 3 +
src/include/matahari/sysconfig.h | 29 +++++------
src/lib/sysconfig_linux.c | 100 +++++++++++++++++------------------
src/sysconfig/schema.xml | 3 +-
src/sysconfig/sysconfig-console.cpp | 42 ++++++++++-----
src/sysconfig/sysconfig-qmf.cpp | 16 ++----
src/tests/mh_api_sysconfig.h | 11 ++--
7 files changed, 106 insertions(+), 98 deletions(-)
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 5b6c8a3..275e090 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -47,6 +47,9 @@ int required_argument = 1;
#define MH_NOT_IMPLEMENTED "Not implemented"
+#ifndef NS_MAXDNAME
+# define NS_MAXDNAME 1025
+#endif
using namespace qpid::management;
using namespace std;
diff --git a/src/include/matahari/sysconfig.h b/src/include/matahari/sysconfig.h
index 17ce0b0..cdd1e8d 100644
--- a/src/include/matahari/sysconfig.h
+++ b/src/include/matahari/sysconfig.h
@@ -25,30 +25,27 @@
#ifndef __MH_SYSCONFIG_H__
#define __MH_SYSCONFIG_H__
-struct conf {
- int scheme;
+typedef struct conf_s {
int flags;
- char *uri;
- char *data;
- char *query;
+ const char *uri;
+ const char *data;
+ const char *query;
const char *key;
-};
+ const char *scheme;
+} conf_t;
-// Supported SCHEME types
-#define PUPPET 1
-#define AUGEAS 2
// Supported FLAGS
-#define FORCE 1
+#define SYSCONFIG_FLAG_FORCE (1 << 0)
-extern int mh_sysconfig_run(const char *uri, int flags, int scheme, struct conf *cf);
-extern int mh_sysconfig_run_string(const char *string, int flags, int scheme, struct conf *cf);
+extern int mh_sysconfig_run_uri(const char *uri, int flags, const char *scheme);
+extern int mh_sysconfig_run_string(const char *string, int flags, const char *scheme);
extern int mh_sysconfig_query(const char *query, const char *data,
- int flags, int scheme, struct conf *cf);
+ int flags, const char *scheme);
// scheme specific
-extern int mh_sysconfig_run_puppet(struct conf *cf);
-extern int mh_sysconfig_run_augeas(struct conf *cf);
-extern int mh_sysconfig_query_augeas(struct conf *cf);
+extern int mh_sysconfig_run_puppet(conf_t *cf);
+extern int mh_sysconfig_run_augeas(conf_t *cf);
+extern int mh_sysconfig_query_augeas(conf_t *cf);
#endif // __MH_SYSCONFIG_H__
diff --git a/src/lib/sysconfig_linux.c b/src/lib/sysconfig_linux.c
index 4f239c7..a1f438a 100644
--- a/src/lib/sysconfig_linux.c
+++ b/src/lib/sysconfig_linux.c
@@ -1,4 +1,4 @@
-/* sysconfig.c - Copyright (C) 2011 Red Hat, Inc.
+/* sysconfig_linux.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
@@ -33,6 +33,7 @@
MH_TRACE_INIT_DATA(mh_sysconfig);
+static conf_t cf = {};
static int
download(const char *uri, FILE *fp)
{
@@ -41,12 +42,12 @@ download(const char *uri, FILE *fp)
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
- if(curl) {
+ if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, uri);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
- if(CURLE_OK != res) {
+ if (CURLE_OK != res) {
return -1;
}
}
@@ -55,99 +56,96 @@ download(const char *uri, FILE *fp)
}
int
-mh_sysconfig_run(const char *uri, int flags, int scheme, struct conf *cf) {
+mh_sysconfig_run_uri(const char *uri, int flags, const char *scheme) {
int rc = 0;
- switch(scheme) {
- case PUPPET:
- cf->uri = strdup(uri);
- cf->scheme = scheme;
- rc = mh_sysconfig_run_puppet(cf);
- free(cf->uri);
- break;
- default:
- rc = -1;
- break;
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ cf.uri = uri;
+ cf.scheme = scheme;
+ rc = mh_sysconfig_run_puppet(&cf);
+ } else {
+ rc = -1;
}
return rc;
}
int
-mh_sysconfig_run_string(const char *data, int flags, int scheme, struct conf *cf) {
+mh_sysconfig_run_string(const char *data, int flags, const char *scheme) {
int rc = 0;
- switch(scheme) {
- case PUPPET:
- cf->data = strdup(data);
- cf->scheme = scheme;
- rc = mh_sysconfig_run_puppet(cf);
- free(cf->data);
- break;
- default:
- rc = -1;
- break;
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ cf.data = data;
+ cf.scheme = scheme;
+ rc = mh_sysconfig_run_puppet(&cf);
+ } else {
+ rc = -1;
}
return rc;
}
int
-mh_sysconfig_query(const char *query, const char *data, int flags, int scheme, struct conf *cf) {
+mh_sysconfig_query(const char *query, const char *data, int flags, const char *scheme) {
int rc = 0;
- switch(scheme) {
- case AUGEAS:
- cf->query = strdup(query);
- cf->data = strdup(data);
- cf->scheme = scheme;
- rc = mh_sysconfig_run_augeas(cf);
- free(cf->query);
- free(cf->data);
- break;
- default:
+ if (g_strcmp0(scheme, "augeas") == 0) {
+ cf.query = query;
+ cf.data = data;
+ cf.scheme = scheme;
+ rc = mh_sysconfig_run_augeas(&cf);
+ } else {
rc = -1;
- break;
}
return rc;
}
int
-mh_sysconfig_run_puppet(struct conf *cf)
+mh_sysconfig_run_puppet(conf_t *cf)
{
- int rc = 0;
- char *filename = NULL, *cmd = NULL;
+ gboolean ret;
+ GError *error;
+ char *filename = NULL;
+ gchar cmd[PATH_MAX];
int fd;
FILE *fp;
-
- if(cf->uri != NULL) {
+ if (cf->uri != NULL) {
filename = strdup("puppet_conf_XXXXXX");
fd = mkstemp(filename);
fp = fdopen(fd, "w+b");
- rc = download(cf->uri, fp);
+ if ((download(cf->uri, fp)) != 0) {
+ fclose(fp);
+ return -1;
+ }
fclose(fp);
- } else if(cf->data != NULL) {
+ } else if (cf->data != NULL) {
filename = strdup("puppet_conf_blob");
g_file_set_contents(filename, cf->data, strlen(cf->data), NULL);
} else {
return -1;
}
-
- asprintf(cmd, "puppet %s", filename);
- rc = system(cmd);
+ g_snprintf(cmd, sizeof(cmd), "puppet %s", filename);
+ fprintf(stderr, "%s", cmd);
+ ret = g_spawn_async(NULL, (gchar **)cmd, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL, NULL, &error);
+ fprintf(stderr, "bool: %d", ret);
+ if (ret == FALSE) {
+ g_error_free(error);
+ free(filename);
+ return -1;
+ }
free(filename);
- free(cmd);
- return rc;
+ return 0;
}
int
-mh_sysconfig_run_augeas(struct conf *cf)
+mh_sysconfig_run_augeas(conf_t *cf)
{
fprintf(stderr, "not implemented\n");
return 0;
}
int
-mh_sysconfig_query_augeas(struct conf *cf)
+mh_sysconfig_query_augeas(conf_t *cf)
{
fprintf(stderr, "not implemented\n");
return 0;
diff --git a/src/sysconfig/schema.xml b/src/sysconfig/schema.xml
index d729000..065fb7a 100644
--- a/src/sysconfig/schema.xml
+++ b/src/sysconfig/schema.xml
@@ -7,8 +7,7 @@
<property name="is_postboot_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="run" desc="Send configure uri method">
+ <method name="run_uri" desc="Send configure uri method">
<arg name="uri" dir="I" type="sstr" />
<arg name="scheme" dir="I" type="sstr" />
<arg name="key" dir="I" type="sstr" />
diff --git a/src/sysconfig/sysconfig-console.cpp b/src/sysconfig/sysconfig-console.cpp
index 920cbd7..d8ed5de 100644
--- a/src/sysconfig/sysconfig-console.cpp
+++ b/src/sysconfig/sysconfig-console.cpp
@@ -30,8 +30,14 @@
#include <qmf/Query.h>
#include <qpid/types/Variant.h>
+#include <matahari/mh_agent.h>
#include <string>
#include <iostream>
+#include <sstream>
+
+extern "C" {
+#include "matahari/logging.h"
+}
using namespace std;
using namespace qmf;
@@ -40,38 +46,46 @@ 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;
+ qpid::types::Variant::Map options;
+ qpid::types::Variant::Map callOptions;
string sessionOptions;
-
- connectionOptions["reconnect"] = true;
-
- dataProperties["uri"] = argv[1] ? argv[1] : "http://localhost/config/uuid";
+ ConsoleEvent event;
+ Agent agent;
+
+ mh_log_init("sysconfig-console", LOG_TRACE, TRUE);
+
+ mh_add_option('U', required_argument, "uri", "URI of configuration", &options, NULL);
+
+ string url = mh_parse_options("sysconfig-console", argc, argv, options);
- qpid::messaging::Connection connection(brokerUrl, connectionOptions);
+ callOptions["uri"] = options["uri"];
+
+ mh_log_init("sysconfig-console", mh_log_level, mh_log_level > LOG_INFO);
+
+ qpid::messaging::Connection connection(url, options);
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, 'Sysconfig']]]");
session.open();
-
- Agent agent;
+ while(session.getAgentCount() == 0) {
+ g_usleep(1000);
+ }
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,
+ ConsoleEvent result(agent.callMethod("configure",
+ callOptions,
agent_event_addr));
}
break;
- default: {}
+ default:
+ break;
}
}
}
diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp
index 4cbdd0d..16fdf19 100644
--- a/src/sysconfig/sysconfig-qmf.cpp
+++ b/src/sysconfig/sysconfig-qmf.cpp
@@ -83,7 +83,7 @@ static int
is_configured(const char *key, int flags) {
int rc = 0;
- if(flags == FORCE) {
+ if(flags & SYSCONFIG_FLAG_FORCE) {
return rc;
}
@@ -95,7 +95,6 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
{
int rc = 0;
int flags;
- struct conf *cf = NULL;
if (event.getType() != qmf::AGENT_METHOD) {
@@ -104,13 +103,12 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
const std::string& methodName(event.getMethodName());
- if (methodName == "run") {
+ if (methodName == "run_uri") {
flags = event.getArguments()["flags"].asInt32();
if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
- rc = mh_sysconfig_run(event.getArguments()["uri"].asString().c_str(),
+ rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
flags,
- event.getArguments()["scheme"].asInt32(),
- cf);
+ event.getArguments()["scheme"].asString().c_str());
}
event.addReturnArgument("configured", rc);
} else if (methodName == "run_string") {
@@ -118,8 +116,7 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
flags,
- event.getArguments()["scheme"].asInt32(),
- cf);
+ event.getArguments()["scheme"].asString().c_str());
}
event.addReturnArgument("configured", rc);
} else if (methodName == "query") {
@@ -127,9 +124,8 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
event.getArguments()["data"].asString().c_str(),
- event.getArguments()["scheme"].asInt32(),
flags,
- cf);
+ event.getArguments()["scheme"].asString().c_str());
}
event.addReturnArgument("configured", rc);
} else if (methodName == "is_configured") {
diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h
index 48cadfa..7e1b2b4 100644
--- a/src/tests/mh_api_sysconfig.h
+++ b/src/tests/mh_api_sysconfig.h
@@ -19,16 +19,17 @@ extern "C" {
using namespace std;
-class MhApisysconfigSuite : public CxxTest::TestSuite
+class MhApiSysconfigSuite : public CxxTest::TestSuite
{
public:
void testIsConfigured(void)
{
- const char *uri = "http://matahariproject.org/atom.xml";
- struct conf *cf = NULL;
-
- TS_ASSERT((mh_sysconfig_run(uri, PUPPET, 0, cf)) != -1);
+ conf_t cf = {};
+ cf.uri = "http://matahariproject.org/atom.xml";
+ cf.flags = 0;
+ cf.scheme = "puppet";
+ TS_ASSERT((mh_sysconfig_run_uri(cf.uri, cf.flags, cf.scheme)) != -1);
}
};
--
1.7.6
12 years, 9 months
[PATCH] - Sysconfig agent
by Adam Stokes
- Full patch with all mentioned changes from ML
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari.spec | 40 ++++----
src/CMakeLists.txt | 2 +-
src/include/matahari/mh_agent.h | 3 +
src/include/matahari/postboot.h | 34 -------
src/include/matahari/sysconfig.h | 36 ++++++++
src/lib/CMakeLists.txt | 13 ++--
src/lib/postboot.c | 50 -----------
src/lib/sysconfig_linux.c | 148 +++++++++++++++++++++++++++++++
src/postboot/CMakeLists.txt | 30 -------
src/postboot/postboot-console.cpp | 79 -----------------
src/postboot/postboot-qmf.cpp | 101 ---------------------
src/postboot/schema.xml | 16 ----
src/sysconfig/CMakeLists.txt | 30 +++++++
src/sysconfig/schema.xml | 35 ++++++++
src/sysconfig/sysconfig-console.cpp | 96 ++++++++++++++++++++
src/sysconfig/sysconfig-qmf.cpp | 163 +++++++++++++++++++++++++++++++++++
src/tests/CMakeLists.txt | 6 +-
src/tests/mh_api_postboot.h | 34 -------
src/tests/mh_api_sysconfig.h | 34 +++++++
19 files changed, 576 insertions(+), 374 deletions(-)
delete mode 100644 src/include/matahari/postboot.h
create mode 100644 src/include/matahari/sysconfig.h
delete mode 100644 src/lib/postboot.c
create mode 100644 src/lib/sysconfig_linux.c
delete mode 100644 src/postboot/CMakeLists.txt
delete mode 100644 src/postboot/postboot-console.cpp
delete mode 100644 src/postboot/postboot-qmf.cpp
delete mode 100644 src/postboot/schema.xml
create mode 100644 src/sysconfig/CMakeLists.txt
create mode 100644 src/sysconfig/schema.xml
create mode 100644 src/sysconfig/sysconfig-console.cpp
create mode 100644 src/sysconfig/sysconfig-qmf.cpp
delete mode 100644 src/tests/mh_api_postboot.h
create mode 100644 src/tests/mh_api_sysconfig.h
diff --git a/matahari.spec b/matahari.spec
index 49f9eca..29703cf 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 postboot
+%package sysconfig
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 postboot
+%description sysconfig
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
-#== Postboot
+#== sysconfig
-%post postboot
-/sbin/service matahari-postboot condrestart
-/sbin/service matahari-postboot-console condrestart
+%post sysconfig
+/sbin/service matahari-sysconfig condrestart
+/sbin/service matahari-sysconfig-console condrestart
-%preun postboot
+%preun sysconfig
if [ $1 = 0 ]; then
- /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
+ /sbin/service matahari-sysconfig-console stop >/dev/null 2>&1 || :
+ /sbin/service matahari-sysconfig stop >/dev/null 2>&1 || :
+ chkconfig --del matahari-sysconfig-console
+ chkconfig --del matahari-sysconfig
fi
-%postun postboot
+%postun sysconfig
if [ "$1" -ge "1" ]; then
- /sbin/service matahari-postboot-console condrestart >/dev/null 2>&1 || :
- /sbin/service matahari-postboot condrestart >/dev/null 2>&1 || :
+ /sbin/service matahari-sysconfig-console condrestart >/dev/null 2>&1 || :
+ /sbin/service matahari-sysconfig 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}/libmpostboot.so.*
+%{_libdir}/libmsysconfig.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 postboot
+%files sysconfig
%defattr(644, root, root, 755)
%doc AUTHORS COPYING
%if %{with qmf}
-%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
+%attr(755, root, root) %{_initddir}/matahari-sysconfig
+%attr(755, root, root) %{_initddir}/matahari-sysconfig-console
+%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfigd
+%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfig-consoled
%endif
%if %{with qmf}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 227e89c..50b3ea7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -138,7 +138,7 @@ add_subdirectory(lib)
add_subdirectory(host)
add_subdirectory(network)
add_subdirectory(service)
-add_subdirectory(postboot)
+add_subdirectory(sysconfig)
add_subdirectory(tests)
### Installation
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 5b6c8a3..275e090 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -47,6 +47,9 @@ int required_argument = 1;
#define MH_NOT_IMPLEMENTED "Not implemented"
+#ifndef NS_MAXDNAME
+# define NS_MAXDNAME 1025
+#endif
using namespace qpid::management;
using namespace std;
diff --git a/src/include/matahari/postboot.h b/src/include/matahari/postboot.h
deleted file mode 100644
index b2b79e0..0000000
--- a/src/include/matahari/postboot.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* postboot.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/sysconfig.h b/src/include/matahari/sysconfig.h
new file mode 100644
index 0000000..9359123
--- /dev/null
+++ b/src/include/matahari/sysconfig.h
@@ -0,0 +1,36 @@
+/* sysconfig.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_SYSCONFIG_H__
+#define __MH_SYSCONFIG_H__
+
+#include <stdint.h>
+// Supported FLAGS
+#define SYSCONFIG_FLAG_FORCE (1 << 0)
+
+extern int mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme);
+extern int mh_sysconfig_run_string(const char *string, uint32_t flags, const char *scheme);
+extern int mh_sysconfig_query(const char *query, const char *data,
+ uint32_t flags, const char *scheme);
+#endif // __MH_SYSCONFIG_H__
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index cf37cf3..f7e38ba 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
# Library
-set(LIBS mcommon mhost mnetwork mservice mpostboot)
+set(LIBS mcommon mhost mnetwork mservice msysconfig)
include_directories(${pcre_INCLUDE_DIRS})
# See http://sourceware.org/autobook/autobook/autobook_91.html for
@@ -8,7 +8,7 @@ include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c dnssrv_${VARIANT}.c)
set_target_properties(mcommon PROPERTIES SOVERSION 1.0.0)
-target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES} resolv)
+target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES})
add_library (mhost SHARED host.c host_${VARIANT}.c)
set_target_properties(mhost PROPERTIES SOVERSION 1.0.0)
@@ -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 (mpostboot SHARED postboot.c)
-set_target_properties(mpostboot PROPERTIES SOVERSION 1.0.0)
-target_link_libraries(mpostboot ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
+add_library (msysconfig SHARED sysconfig_${VARIANT}.c)
+set_target_properties(msysconfig PROPERTIES SOVERSION 1.0.0)
+target_link_libraries(msysconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
if(WIN32)
foreach (lib ${LIBS})
@@ -33,7 +33,8 @@ if(WIN32)
endforeach (lib ${LIBS})
else(WIN32)
foreach (lib ${LIBS})
- install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
+ target_link_libraries(${lib} resolv curl)
+ install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
endforeach (lib ${LIBS})
endif(WIN32)
diff --git a/src/lib/postboot.c b/src/lib/postboot.c
deleted file mode 100644
index 6f970fa..0000000
--- a/src/lib/postboot.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 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/lib/sysconfig_linux.c b/src/lib/sysconfig_linux.c
new file mode 100644
index 0000000..cd2b725
--- /dev/null
+++ b/src/lib/sysconfig_linux.c
@@ -0,0 +1,148 @@
+/* sysconfig_linux.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 <stdlib.h>
+#include <glib.h>
+#include <curl/curl.h>
+#include "matahari/logging.h"
+#include "matahari/sysconfig.h"
+#include "matahari/utilities.h"
+
+
+MH_TRACE_INIT_DATA(mh_sysconfig);
+
+static int
+download(const char *uri, FILE *fp)
+{
+ CURL *curl;
+ CURLcode res;
+
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = curl_easy_init();
+ if (curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, uri);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+ res = curl_easy_perform(curl);
+
+ if (CURLE_OK != res) {
+ return -1;
+ }
+ }
+ curl_global_cleanup();
+ return 0;
+}
+
+
+static int
+mh_sysconfig_run_puppet(const char *uri, const char *data)
+{
+ gboolean ret;
+ GError *error;
+ char *filename = NULL;
+ gchar cmd[PATH_MAX];
+ int fd;
+ FILE *fp;
+
+ if (uri != NULL) {
+ filename = strdup("puppet_conf_XXXXXX");
+ fd = mkstemp(filename);
+ fp = fdopen(fd, "w+b");
+ if ((download(uri, fp)) != 0) {
+ fclose(fp);
+ return -1;
+ }
+ fclose(fp);
+ } else if (data != NULL) {
+ filename = strdup("puppet_conf_blob");
+ g_file_set_contents(filename, data, strlen(data), NULL);
+ } else {
+ return -1;
+ }
+
+ g_snprintf(cmd, sizeof(cmd), "puppet %s", filename);
+ fprintf(stderr, "%s", cmd);
+ ret = g_spawn_async(NULL, (gchar **)cmd, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL, NULL, &error);
+ fprintf(stderr, "bool: %d", ret);
+ if (ret == FALSE) {
+ g_error_free(error);
+ free(filename);
+ return -1;
+ }
+
+ free(filename);
+
+ return 0;
+}
+
+static int
+mh_sysconfig_run_augeas(const char *query, const char *data)
+{
+ fprintf(stderr, "not implemented\n");
+ return 0;
+}
+
+static int
+mh_sysconfig_query_augeas(const char *query, const char *data)
+{
+ fprintf(stderr, "not implemented\n");
+ return 0;
+}
+
+int
+mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ rc = mh_sysconfig_run_puppet(uri, NULL);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
+
+int
+mh_sysconfig_run_string(const char *data, uint32_t flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ rc = mh_sysconfig_run_puppet(NULL, data);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
+
+int
+mh_sysconfig_query(const char *query, const char *data, uint32_t flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "augeas") == 0) {
+ rc = mh_sysconfig_run_augeas(query, data);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
diff --git a/src/postboot/CMakeLists.txt b/src/postboot/CMakeLists.txt
deleted file mode 100644
index 36d59a1..0000000
--- a/src/postboot/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-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(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- # Override BASE for matahari-postboot-console
- unset(BASE)
- set(BASE "postboot-console")
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(PROGRAMS ${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
deleted file mode 100644
index 188c443..0000000
--- a/src/postboot/postboot-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/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp
deleted file mode 100644
index 7058276..0000000
--- a/src/postboot/postboot-qmf.cpp
+++ /dev/null
@@ -1,101 +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/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) {
- 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
deleted file mode 100644
index 2d930ce..0000000
--- a/src/postboot/schema.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<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/sysconfig/CMakeLists.txt b/src/sysconfig/CMakeLists.txt
new file mode 100644
index 0000000..1d9fba8
--- /dev/null
+++ b/src/sysconfig/CMakeLists.txt
@@ -0,0 +1,30 @@
+set(BASE "sysconfig")
+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(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
+ # Override BASE for matahari-sysconfig-console
+ unset(BASE)
+ set(BASE "sysconfig-console")
+ configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
+ install(PROGRAMS ${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/sysconfig/schema.xml b/src/sysconfig/schema.xml
new file mode 100644
index 0000000..d5c52aa
--- /dev/null
+++ b/src/sysconfig/schema.xml
@@ -0,0 +1,35 @@
+<schema package="org.matahariproject">
+
+ <!-- Config API -->
+ <class name="Sysconfig">
+ <property name="uuid" type="sstr" access="RO" desc="Host UUID" />
+ <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
+ <property name="is_postboot_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="run_uri" desc="Send configure uri method">
+ <arg name="uri" dir="I" type="sstr" />
+ <arg name="scheme" dir="I" type="sstr" />
+ <arg name="key" dir="I" type="sstr" />
+ <arg name="flags" dir="I" type="uint32" />
+ </method>
+
+ <method name="run_string" desc="Send configure text method">
+ <arg name="text" dir="I" type="sstr" />
+ <arg name="scheme" dir="I" type="sstr" />
+ <arg name="key" dir="I" type="sstr" />
+ <arg name="flags" dir="I" type="uint32" />
+ </method>
+
+ <method name="query" desc="Perform query lookup">
+ <arg name="text" dir="I" type="sstr" />
+ <arg name="scheme" dir="I" type="sstr" />
+ <arg name="flags" dir="I" type="uint32" />
+ </method>
+
+ <method name="is_configured" desc="Check if system is configured">
+ <arg name="key" dir="I" type="sstr" />
+ </method>
+ </class>
+</schema>
diff --git a/src/sysconfig/sysconfig-console.cpp b/src/sysconfig/sysconfig-console.cpp
new file mode 100644
index 0000000..e294152
--- /dev/null
+++ b/src/sysconfig/sysconfig-console.cpp
@@ -0,0 +1,96 @@
+/* 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 <matahari/mh_agent.h>
+
+#include <string>
+#include <iostream>
+#include <sstream>
+
+extern "C" {
+#include "matahari/logging.h"
+}
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+int main(int argc, char** argv)
+{
+ qpid::types::Variant::Map options;
+ qpid::types::Variant::Map callOptions;
+ string sessionOptions;
+ ConsoleEvent event;
+ Agent agent;
+
+ mh_log_init("sysconfig-console", LOG_TRACE, TRUE);
+
+ mh_add_option('U', required_argument, "uri", "URI of configuration", &options, NULL);
+
+ string url = mh_parse_options("sysconfig-console", argc, argv, options);
+
+ callOptions["uri"] = options["uri"];
+
+ mh_log_init("sysconfig-console", mh_log_level, mh_log_level > LOG_INFO);
+
+ qpid::messaging::Connection connection(url, options);
+ 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, 'Sysconfig']]]");
+ session.open();
+
+ while(session.getAgentCount() == 0) {
+ g_usleep(1000);
+ }
+
+ while (true) {
+ 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",
+ callOptions,
+ agent_event_addr));
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp
new file mode 100644
index 0000000..1cacd87
--- /dev/null
+++ b/src/sysconfig/sysconfig-qmf.cpp
@@ -0,0 +1,163 @@
+/* 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
+ */
+
+/**
+ * \file
+ * \brief Sysconfig QMF Agent
+ */
+
+#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 <fcntl.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gprintf.h>
+#include "matahari/sysconfig.h"
+#include "matahari/logging.h"
+#include "matahari/network.h"
+#include "matahari/host.h"
+#include <sigar.h>
+#include <sigar_format.h>
+};
+
+static const char *configured_fn = "/var/lib/matahari/.is_configured";
+
+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, "Sysconfig");
+ if (rc == 0) {
+ agent.run();
+ }
+ return rc;
+}
+
+int
+ConfigAgent::setup(qmf::AgentSession session)
+{
+ _package.configure(session);
+ _instance = qmf::Data(_package.data_Sysconfig);
+
+ _instance.setProperty("hostname", mh_hostname());
+ _instance.setProperty("uuid", mh_uuid());
+ _instance.setProperty("is_postboot_configured", 0);
+
+ _agent_session.addData(_instance, "sysconfig");
+ return 0;
+}
+
+static void
+set_configured() {
+ if(!g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
+ g_creat(configured_fn, S_IRWXU);
+ }
+}
+
+static int
+is_configured(uint32_t flags) {
+
+ if(flags & SYSCONFIG_FLAG_FORCE) {
+ return 0;
+ }
+
+ if(g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
+ return 1;
+ }
+ return 0;
+}
+
+gboolean
+ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+{
+ int rc = 0;
+ uint32_t flags;
+
+
+ if (event.getType() != qmf::AGENT_METHOD) {
+ return TRUE;
+ }
+
+ const std::string& methodName(event.getMethodName());
+
+ if (methodName == "run_uri") {
+ flags = event.getArguments()["flags"].asInt32();
+ if((is_configured(flags)) == 0) {
+ rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
+ flags,
+ event.getArguments()["scheme"].asString().c_str());
+ if (rc == 0) {
+ set_configured();
+ }
+ }
+ event.addReturnArgument("configured", rc);
+ } else if (methodName == "run_string") {
+ flags = event.getArguments()["flags"].asInt32();
+ if((is_configured(flags)) == 0) {
+ rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
+ flags,
+ event.getArguments()["scheme"].asString().c_str());
+ if (rc == 0) {
+ set_configured();
+ }
+ }
+ event.addReturnArgument("configured", rc);
+ } else if (methodName == "query") {
+ flags = event.getArguments()["flags"].asInt32();
+ if((is_configured(flags)) == 0) {
+ rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
+ event.getArguments()["data"].asString().c_str(),
+ flags,
+ event.getArguments()["scheme"].asString().c_str());
+ }
+ event.addReturnArgument("configured", rc);
+ } else if (methodName == "is_configured") {
+ rc = is_configured(0);
+ _instance.setProperty("is_postboot_configured", rc);
+ event.addReturnArgument("configured", rc);
+ } else {
+ session.raiseException(event, MH_NOT_IMPLEMENTED);
+ goto bail;
+ }
+
+ session.methodSuccess(event);
+
+bail:
+ return TRUE;
+}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 6db157c..8fe81f2 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -5,13 +5,13 @@ 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)
+ CXXTEST_ADD_TEST(mh_api_sysconfig_unittest sysconfig_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig.h)
CXXTEST_ADD_TEST(mh_hsa_unittest hsa_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_hsa_${VARIANT}.h)
add_library(mh_tester SHARED test_utilities.c)
- target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost mpostboot)
+ target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost msysconfig)
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)
+ target_link_libraries(mh_api_sysconfig_unittest mh_tester)
target_link_libraries(mh_hsa_unittest mh_tester)
endif(CXXTEST_FOUND)
diff --git a/src/tests/mh_api_postboot.h b/src/tests/mh_api_postboot.h
deleted file mode 100644
index 5e59a9b..0000000
--- a/src/tests/mh_api_postboot.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#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
diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h
new file mode 100644
index 0000000..a9a3ebc
--- /dev/null
+++ b/src/tests/mh_api_sysconfig.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/sysconfig.h"
+#include <glib.h>
+#include "mh_test_utilities.h"
+};
+
+using namespace std;
+
+class MhApiSysconfigSuite : public CxxTest::TestSuite
+{
+ public:
+
+ void testIsConfigured(void)
+ {
+ const char *uri = "http://matahariproject.org/atom.xml";
+ uint32_t flags = 0;
+ TS_ASSERT((mh_sysconfig_run_uri(uri, flags, "puppet")) != -1);
+ }
+};
+
+#endif
--
1.7.6
12 years, 9 months
[PATCH] Build: Warn when variables are shadowed
by Zane Bitter
Also fixed some false positives.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/CMakeLists.txt | 4 ++--
src/lib/host.c | 26 +++++++++++++-------------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 28a3ef3..7db1449 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,8 +20,8 @@ else(WIN32)
endif(WIN32)
option(WITH-QMF "Build the QMF daemon" ON)
-set(CMAKE_C_FLAGS "-Wall")
-set(CMAKE_CXX_FLAGS "-Wall")
+set(CMAKE_C_FLAGS "-Wall -Wshadow")
+set(CMAKE_CXX_FLAGS "-Wall -Wshadow")
include(FindPkgConfig)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
diff --git a/src/lib/host.c b/src/lib/host.c
index 311149f..c390e2b 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -96,11 +96,11 @@ mh_host_get_operating_system(void)
init();
if (operating_system == NULL) {
- sigar_sys_info_t sysinfo;
+ sigar_sys_info_t sys_info;
- sigar_sys_info_get(host_init.sigar, &sysinfo);
- operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name,
- sysinfo.version);
+ sigar_sys_info_get(host_init.sigar, &sys_info);
+ operating_system = g_strdup_printf("%s (%s)", sys_info.vendor_name,
+ sys_info.version);
}
return operating_system;
@@ -120,10 +120,10 @@ mh_host_get_architecture(void)
init();
if (arch == NULL) {
- sigar_sys_info_t sysinfo;
+ sigar_sys_info_t sys_info;
- sigar_sys_info_get(host_init.sigar, &sysinfo);
- arch = g_strdup(sysinfo.arch);
+ sigar_sys_info_get(host_init.sigar, &sys_info);
+ arch = g_strdup(sys_info.arch);
}
return arch;
@@ -198,12 +198,12 @@ uint64_t
mh_host_get_mem_free(void)
{
sigar_mem_t mem;
- uint64_t free;
+ uint64_t free_mem;
init();
sigar_mem_get(host_init.sigar, &mem);
- free = mem.free / 1024;
- return free;
+ free_mem = mem.free / 1024;
+ return free_mem;
}
uint64_t
@@ -222,12 +222,12 @@ uint64_t
mh_host_get_swap_free(void)
{
sigar_swap_t swap;
- uint64_t free;
+ uint64_t free_mem;
init();
sigar_swap_get(host_init.sigar, &swap);
- free = swap.free / 1024;
- return free;
+ free_mem = swap.free / 1024;
+ return free_mem;
}
static void
12 years, 9 months
[PATCH] Export more headers
by Zane Bitter
Export headers for logging, and also headers required for external code to
use agent libraries like libmhost, libmnetwork &c.
Also standardise the naming convention by removing the mh_ prefix from the
headers that were previously exported. Their presence in the matahari/
directory is sufficient to prevent naming collisions.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
matahari.spec | 13 ++-
src/CMakeLists.txt | 13 ++-
src/host/host-dbus.c | 2
src/host/host-qmf.cpp | 2
src/include/matahari/agent.h | 100 +++++++++++++++++++++++
src/include/matahari/dbus_common.h | 135 +++++++++++++++++++++++++++++++
src/include/matahari/gobject_class.h | 56 +++++++++++++
src/include/matahari/mh_agent.h | 100 -----------------------
src/include/matahari/mh_dbus_common.h | 135 -------------------------------
src/include/matahari/mh_gobject_class.h | 56 -------------
src/lib/mh_agent.cpp | 2
src/lib/mh_dbus_common.c | 2
src/network/network-dbus.c | 2
src/network/network-qmf.cpp | 2
src/postboot/postboot-qmf.cpp | 2
src/service/service-dbus.c | 2
src/service/service-qmf-console.cpp | 2
src/service/service-qmf.cpp | 2
18 files changed, 321 insertions(+), 307 deletions(-)
create mode 100644 src/include/matahari/agent.h
create mode 100644 src/include/matahari/dbus_common.h
create mode 100644 src/include/matahari/gobject_class.h
delete mode 100644 src/include/matahari/mh_agent.h
delete mode 100644 src/include/matahari/mh_dbus_common.h
delete mode 100644 src/include/matahari/mh_gobject_class.h
diff --git a/matahari.spec b/matahari.spec
index 49f9eca..80adf30 100644
--- a/matahari.spec
+++ b/matahari.spec
@@ -391,17 +391,24 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%{_libdir}/libm*.so
%{_includedir}/matahari.h
+%{_includedir}/matahari/logging.h
+%{_includedir}/matahari/utilities.h
+%{_includedir}/matahari/dnssrv.h
+%{_includedir}/matahari/host.h
+%{_includedir}/matahari/network.h
+%{_includedir}/matahari/postboot.h
+%{_includedir}/matahari/services.h
%{_datadir}/cmake/Modules/FindMatahari.cmake
%if %{with qmf}
-%{_includedir}/matahari/mh_agent.h
+%{_includedir}/matahari/agent.h
%{_includedir}/matahari/mainloop.h
%{_datadir}/cmake/Modules/FindQPID.cmake
%endif
%if %{with dbus}
-%{_includedir}/matahari/mh_dbus_common.h
-%{_includedir}/matahari/mh_gobject_class.h
+%{_includedir}/matahari/dbus_common.h
+%{_includedir}/matahari/gobject_class.h
%{_datadir}/cmake/Modules/MatahariMacros.cmake
%{_datadir}/matahari/schema-to-dbus.xsl
%{_datadir}/matahari/dbus-to-c.xsl
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 227e89c..28a3ef3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -144,20 +144,27 @@ add_subdirectory(tests)
### Installation
install(FILES ${SCHEMAS} DESTINATION share/matahari)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h DESTINATION include)
+install(FILES include/matahari/logging.h DESTINATION include/matahari)
+install(FILES include/matahari/utilities.h DESTINATION include/matahari)
+install(FILES include/matahari/dnssrv.h DESTINATION include/matahari)
+install(FILES include/matahari/host.h DESTINATION include/matahari)
+install(FILES include/matahari/network.h DESTINATION include/matahari)
+install(FILES include/matahari/postboot.h DESTINATION include/matahari)
+install(FILES include/matahari/services.h DESTINATION include/matahari)
install(FILES cmake/modules/FindMatahari.cmake DESTINATION share/cmake/Modules)
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/agent.h DESTINATION include/matahari)
install(FILES include/matahari/mainloop.h DESTINATION include/matahari)
endif(WITH-QMF)
if(WITH-DBUS)
install(FILES schema-to-dbus.xsl DESTINATION share/matahari)
install(FILES dbus-to-c.xsl DESTINATION share/matahari)
- install(FILES include/matahari/mh_dbus_common.h DESTINATION include/matahari)
- install(FILES include/matahari/mh_gobject_class.h DESTINATION include/matahari)
+ install(FILES include/matahari/dbus_common.h DESTINATION include/matahari)
+ install(FILES include/matahari/gobject_class.h DESTINATION include/matahari)
endif(WITH-DBUS)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index 0c7284e..117b97f 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
-#include "matahari/mh_dbus_common.h"
+#include "matahari/dbus_common.h"
/* Host methods */
#include "matahari/host.h"
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index 0a5fd08..5658dd7 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -27,7 +27,7 @@
#endif
#include <set>
-#include "matahari/mh_agent.h"
+#include "matahari/agent.h"
#include <qmf/Data.h>
#include "qmf/org/matahariproject/QmfPackage.h"
diff --git a/src/include/matahari/agent.h b/src/include/matahari/agent.h
new file mode 100644
index 0000000..20eca51
--- /dev/null
+++ b/src/include/matahari/agent.h
@@ -0,0 +1,100 @@
+/* mh_agent.cpp - Copyright (C) 2010 Red Hat, Inc.
+ * Written by 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
+ */
+
+/**
+ * \file
+ * \brief Matahari Agent API
+ * \ingroup coreapi
+ */
+
+#ifndef __MATAHARI_DAEMON_H
+#define __MATAHARI_DAEMON_H
+
+#include <string>
+#include <qpid/sys/Time.h>
+#include <qpid/agent/ManagementAgent.h>
+#include <qpid/management/Manageable.h>
+#include <qpid/messaging/Connection.h>
+#include <qmf/AgentEvent.h>
+#include <qmf/AgentSession.h>
+#include <qmf/Data.h>
+
+extern "C" {
+#include "matahari/mainloop.h"
+#ifdef WIN32
+int no_argument = 0;
+int required_argument = 1;
+#else
+# include <getopt.h>
+#endif
+}
+
+#define MH_NOT_IMPLEMENTED "Not implemented"
+
+using namespace qpid::management;
+using namespace std;
+
+namespace _qtype = ::qpid::types;
+
+typedef struct mainloop_qmf_s {
+ GSource source;
+ qmf::AgentSession session;
+ qmf::AgentEvent event;
+ guint id;
+ void *user_data;
+ GDestroyNotify dnotify;
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
+} mainloop_qmf_t;
+
+extern int mh_add_option(
+ int code, int has_arg, const char *name, const char *description,
+ void *userdata, int(*callback)(int code, const char *name, const char *arg, void *userdata));
+
+extern string mh_parse_options(
+ const char *proc_name, int argc, char **argv, qpid::types::Variant::Map &options);
+
+extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
+
+extern gboolean mainloop_destroy_qmf(mainloop_qmf_t *source);
+
+class MatahariAgent
+{
+public:
+ MatahariAgent() {};
+ virtual ~MatahariAgent();
+
+ virtual int setup(qmf::AgentSession session) { return 0; };
+ 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();
+
+protected:
+ GMainLoop *mainloop;
+ mainloop_qmf_t *qpid_source;
+
+ qmf::AgentSession _agent_session;
+ qpid::messaging::Connection _amqp_connection;
+};
+
+#endif // __MATAHARI_DAEMON_H
diff --git a/src/include/matahari/dbus_common.h b/src/include/matahari/dbus_common.h
new file mode 100644
index 0000000..3df3f75
--- /dev/null
+++ b/src/include/matahari/dbus_common.h
@@ -0,0 +1,135 @@
+/*
+ * mh_dbus_common.h
+ *
+ * Copyright (C) 2011 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
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MH_DBUS_COMMON_H
+#define MH_DBUS_COMMON_H
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+/* GObject class definition */
+#include "matahari/gobject_class.h"
+
+/* Private struct in Matahari class */
+#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ MATAHARI_TYPE, MatahariPrivate))
+
+// Matahari error codes
+#define MATAHARI_ERROR matahari_error_quark ()
+enum { MATAHARI_AUTHENTICATION_ERROR, MATAHARI_NOT_IMPLEMENTED };
+
+GQuark
+matahari_error_quark (void);
+
+/**
+ * Check the authorization for given 'action' using PolicyKit. Returns TRUE if
+ * user is authorized, otherwise return FALSE and 'error' is set.
+ */
+gboolean
+check_authorization(const gchar *action, GError** error,
+ DBusGMethodInvocation *context);
+
+typedef struct {
+ int prop;
+ gchar *name, *nick, *desc;
+ GParamFlags flags;
+ char type;
+} Property;
+
+// This array is defined in auto-generated matahari-module-properties.h
+extern Property properties[];
+
+/**
+ * Start DBus server with name 'bus_name' and object path 'object_path'
+ */
+int
+run_dbus_server(char *bus_name, char *object_path);
+
+/**
+ * Check the authorization for getting the parameter 'name' using PolicyKit
+ * action interface.name
+ */
+gboolean
+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);
+
+/**
+ * This method is used for getting value of DBus property.
+ * It must be implemented in each module.
+ * Set the value of property_id parameter to parameter value.
+ */
+void
+matahari_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec);
+
+/**
+ * This method is used for setting value of DBus property.
+ * It must be implemented in each module.
+ * New value of property_id is in parameter value.
+ */
+void
+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.
+ * It must be implemented in each module.
+ */
+GType
+matahari_dict_type(int prop);
+
+/**
+ * Dictionary type. Key is always string, value is set in constructor dict_new.
+ */
+typedef struct
+{
+ GValue *value;
+ GValue *key;
+ DBusGTypeSpecializedAppendContext appendctx;
+} Dict;
+
+/**
+ * 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);
+
+/**
+ * Add 'value' to the dictionary 'dict'.
+ */
+void dict_add(Dict *dict, const gchar *key, GValue *value);
+
+/**
+ * Frees memory allocated by dict_new.
+ */
+void dict_free(Dict *dict);
+
+#endif
diff --git a/src/include/matahari/gobject_class.h b/src/include/matahari/gobject_class.h
new file mode 100644
index 0000000..fe13d1e
--- /dev/null
+++ b/src/include/matahari/gobject_class.h
@@ -0,0 +1,56 @@
+/*
+ * mh_gobject_class.h
+ *
+ * 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
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#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))
+
+typedef struct _Matahari Matahari;
+typedef struct _MatahariClass MatahariClass;
+typedef struct _MatahariPrivate MatahariPrivate;
+
+GType
+matahari_get_type(void);
+
+struct _Matahari
+{
+ GObject parent;
+ MatahariPrivate *priv;
+};
+
+struct _MatahariClass
+{
+ GObjectClass parent;
+};
+
+#endif /* MHGOBJECTCLASS_H_ */
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
deleted file mode 100644
index 20eca51..0000000
--- a/src/include/matahari/mh_agent.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* mh_agent.cpp - Copyright (C) 2010 Red Hat, Inc.
- * Written by 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
- */
-
-/**
- * \file
- * \brief Matahari Agent API
- * \ingroup coreapi
- */
-
-#ifndef __MATAHARI_DAEMON_H
-#define __MATAHARI_DAEMON_H
-
-#include <string>
-#include <qpid/sys/Time.h>
-#include <qpid/agent/ManagementAgent.h>
-#include <qpid/management/Manageable.h>
-#include <qpid/messaging/Connection.h>
-#include <qmf/AgentEvent.h>
-#include <qmf/AgentSession.h>
-#include <qmf/Data.h>
-
-extern "C" {
-#include "matahari/mainloop.h"
-#ifdef WIN32
-int no_argument = 0;
-int required_argument = 1;
-#else
-# include <getopt.h>
-#endif
-}
-
-#define MH_NOT_IMPLEMENTED "Not implemented"
-
-using namespace qpid::management;
-using namespace std;
-
-namespace _qtype = ::qpid::types;
-
-typedef struct mainloop_qmf_s {
- GSource source;
- qmf::AgentSession session;
- qmf::AgentEvent event;
- guint id;
- void *user_data;
- GDestroyNotify dnotify;
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer user_data);
-} mainloop_qmf_t;
-
-extern int mh_add_option(
- int code, int has_arg, const char *name, const char *description,
- void *userdata, int(*callback)(int code, const char *name, const char *arg, void *userdata));
-
-extern string mh_parse_options(
- const char *proc_name, int argc, char **argv, qpid::types::Variant::Map &options);
-
-extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
-
-extern gboolean mainloop_destroy_qmf(mainloop_qmf_t *source);
-
-class MatahariAgent
-{
-public:
- MatahariAgent() {};
- virtual ~MatahariAgent();
-
- virtual int setup(qmf::AgentSession session) { return 0; };
- 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();
-
-protected:
- GMainLoop *mainloop;
- mainloop_qmf_t *qpid_source;
-
- qmf::AgentSession _agent_session;
- qpid::messaging::Connection _amqp_connection;
-};
-
-#endif // __MATAHARI_DAEMON_H
diff --git a/src/include/matahari/mh_dbus_common.h b/src/include/matahari/mh_dbus_common.h
deleted file mode 100644
index e7b4936..0000000
--- a/src/include/matahari/mh_dbus_common.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * mh_dbus_common.h
- *
- * Copyright (C) 2011 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
- * of the License, or (at your option) any later version.
- *
- * This program 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 program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef MH_DBUS_COMMON_H
-#define MH_DBUS_COMMON_H
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-/* GObject class definition */
-#include "mh_gobject_class.h"
-
-/* Private struct in Matahari class */
-#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- MATAHARI_TYPE, MatahariPrivate))
-
-// Matahari error codes
-#define MATAHARI_ERROR matahari_error_quark ()
-enum { MATAHARI_AUTHENTICATION_ERROR, MATAHARI_NOT_IMPLEMENTED };
-
-GQuark
-matahari_error_quark (void);
-
-/**
- * Check the authorization for given 'action' using PolicyKit. Returns TRUE if
- * user is authorized, otherwise return FALSE and 'error' is set.
- */
-gboolean
-check_authorization(const gchar *action, GError** error,
- DBusGMethodInvocation *context);
-
-typedef struct {
- int prop;
- gchar *name, *nick, *desc;
- GParamFlags flags;
- char type;
-} Property;
-
-// This array is defined in auto-generated matahari-module-properties.h
-extern Property properties[];
-
-/**
- * Start DBus server with name 'bus_name' and object path 'object_path'
- */
-int
-run_dbus_server(char *bus_name, char *object_path);
-
-/**
- * Check the authorization for getting the parameter 'name' using PolicyKit
- * action interface.name
- */
-gboolean
-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);
-
-/**
- * This method is used for getting value of DBus property.
- * It must be implemented in each module.
- * Set the value of property_id parameter to parameter value.
- */
-void
-matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec);
-
-/**
- * This method is used for setting value of DBus property.
- * It must be implemented in each module.
- * New value of property_id is in parameter value.
- */
-void
-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.
- * It must be implemented in each module.
- */
-GType
-matahari_dict_type(int prop);
-
-/**
- * Dictionary type. Key is always string, value is set in constructor dict_new.
- */
-typedef struct
-{
- GValue *value;
- GValue *key;
- DBusGTypeSpecializedAppendContext appendctx;
-} Dict;
-
-/**
- * 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);
-
-/**
- * Add 'value' to the dictionary 'dict'.
- */
-void dict_add(Dict *dict, const gchar *key, GValue *value);
-
-/**
- * Frees memory allocated by dict_new.
- */
-void dict_free(Dict *dict);
-
-#endif
diff --git a/src/include/matahari/mh_gobject_class.h b/src/include/matahari/mh_gobject_class.h
deleted file mode 100644
index fe13d1e..0000000
--- a/src/include/matahari/mh_gobject_class.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * mh_gobject_class.h
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * This program 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 program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#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))
-
-typedef struct _Matahari Matahari;
-typedef struct _MatahariClass MatahariClass;
-typedef struct _MatahariPrivate MatahariPrivate;
-
-GType
-matahari_get_type(void);
-
-struct _Matahari
-{
- GObject parent;
- MatahariPrivate *priv;
-};
-
-struct _MatahariClass
-{
- GObjectClass parent;
-};
-
-#endif /* MHGOBJECTCLASS_H_ */
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 9eeb37f..adb137e 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -39,7 +39,7 @@ int use_stderr = 0;
#include <qpid/client/ConnectionSettings.h>
// #include <qpid/sys/ssl/util.h>
#include <qmf/DataAddr.h>
-#include "matahari/mh_agent.h"
+#include "matahari/agent.h"
extern "C" {
#include "matahari/logging.h"
diff --git a/src/lib/mh_dbus_common.c b/src/lib/mh_dbus_common.c
index 89405ed..4e1359b 100644
--- a/src/lib/mh_dbus_common.c
+++ b/src/lib/mh_dbus_common.c
@@ -20,7 +20,7 @@
*
*/
-#include "matahari/mh_dbus_common.h"
+#include "matahari/dbus_common.h"
#include "matahari/logging.h"
#include <glib/gi18n.h>
diff --git a/src/network/network-dbus.c b/src/network/network-dbus.c
index c639cb3..7b18810 100644
--- a/src/network/network-dbus.c
+++ b/src/network/network-dbus.c
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
-#include "matahari/mh_dbus_common.h"
+#include "matahari/dbus_common.h"
/* Network methods */
#include "matahari/network.h"
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index 3efe70f..6692d83 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -20,7 +20,7 @@
#include "config.h"
#endif
-#include "matahari/mh_agent.h"
+#include "matahari/agent.h"
#include "qmf/org/matahariproject/QmfPackage.h"
diff --git a/src/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp
index fa3bbdf..fa69751 100644
--- a/src/postboot/postboot-qmf.cpp
+++ b/src/postboot/postboot-qmf.cpp
@@ -20,7 +20,7 @@
#include "config.h"
#endif
-#include "matahari/mh_agent.h"
+#include "matahari/agent.h"
#include "qmf/org/matahariproject/QmfPackage.h"
diff --git a/src/service/service-dbus.c b/src/service/service-dbus.c
index 4964713..879163d 100644
--- a/src/service/service-dbus.c
+++ b/src/service/service-dbus.c
@@ -22,7 +22,7 @@
#include <string.h>
-#include "matahari/mh_dbus_common.h"
+#include "matahari/dbus_common.h"
/* Services methods */
#include "matahari/services.h"
diff --git a/src/service/service-qmf-console.cpp b/src/service/service-qmf-console.cpp
index dac8bca..f89bd1c 100644
--- a/src/service/service-qmf-console.cpp
+++ b/src/service/service-qmf-console.cpp
@@ -28,7 +28,7 @@
#include <qmf/Query.h>
#include <qpid/types/Variant.h>
-#include <matahari/mh_agent.h>
+#include <matahari/agent.h>
#include <string>
#include <iostream>
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index 492a803..9da1866 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -28,7 +28,7 @@ extern "C" {
#include <string>
#include <qpid/management/Manageable.h>
#include <qpid/agent/ManagementAgent.h>
-#include "matahari/mh_agent.h"
+#include "matahari/agent.h"
#include "qmf/org/matahariproject/QmfPackage.h"
12 years, 9 months
[PATCH] - Sysconfig agent
by Adam Stokes
- Removed struct conf reference
- Made scheme routines internal only
- add configured routines in agent
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/include/matahari/sysconfig.h | 12 -----
src/lib/sysconfig_linux.c | 100 +++++++++++++++++--------------------
src/sysconfig/sysconfig-qmf.cpp | 34 ++++++++++---
src/tests/mh_api_sysconfig.h | 8 +--
4 files changed, 75 insertions(+), 79 deletions(-)
diff --git a/src/include/matahari/sysconfig.h b/src/include/matahari/sysconfig.h
index cdd1e8d..8b28ca8 100644
--- a/src/include/matahari/sysconfig.h
+++ b/src/include/matahari/sysconfig.h
@@ -25,14 +25,6 @@
#ifndef __MH_SYSCONFIG_H__
#define __MH_SYSCONFIG_H__
-typedef struct conf_s {
- int flags;
- const char *uri;
- const char *data;
- const char *query;
- const char *key;
- const char *scheme;
-} conf_t;
// Supported FLAGS
@@ -43,9 +35,5 @@ extern int mh_sysconfig_run_string(const char *string, int flags, const char *sc
extern int mh_sysconfig_query(const char *query, const char *data,
int flags, const char *scheme);
-// scheme specific
-extern int mh_sysconfig_run_puppet(conf_t *cf);
-extern int mh_sysconfig_run_augeas(conf_t *cf);
-extern int mh_sysconfig_query_augeas(conf_t *cf);
#endif // __MH_SYSCONFIG_H__
diff --git a/src/lib/sysconfig_linux.c b/src/lib/sysconfig_linux.c
index a1f438a..cb6cb5d 100644
--- a/src/lib/sysconfig_linux.c
+++ b/src/lib/sysconfig_linux.c
@@ -33,7 +33,6 @@
MH_TRACE_INIT_DATA(mh_sysconfig);
-static conf_t cf = {};
static int
download(const char *uri, FILE *fp)
{
@@ -55,52 +54,9 @@ download(const char *uri, FILE *fp)
return 0;
}
-int
-mh_sysconfig_run_uri(const char *uri, int flags, const char *scheme) {
- int rc = 0;
-
- if (g_strcmp0(scheme, "puppet") == 0) {
- cf.uri = uri;
- cf.scheme = scheme;
- rc = mh_sysconfig_run_puppet(&cf);
- } else {
- rc = -1;
- }
- return rc;
-}
-
-int
-mh_sysconfig_run_string(const char *data, int flags, const char *scheme) {
- int rc = 0;
-
- if (g_strcmp0(scheme, "puppet") == 0) {
- cf.data = data;
- cf.scheme = scheme;
- rc = mh_sysconfig_run_puppet(&cf);
- } else {
- rc = -1;
- }
- return rc;
-}
-
-int
-mh_sysconfig_query(const char *query, const char *data, int flags, const char *scheme) {
- int rc = 0;
-
- if (g_strcmp0(scheme, "augeas") == 0) {
- cf.query = query;
- cf.data = data;
- cf.scheme = scheme;
- rc = mh_sysconfig_run_augeas(&cf);
- } else {
- rc = -1;
- }
- return rc;
-}
-
-int
-mh_sysconfig_run_puppet(conf_t *cf)
+static int
+mh_sysconfig_run_puppet(const char *uri, const char *data)
{
gboolean ret;
GError *error;
@@ -108,18 +64,18 @@ mh_sysconfig_run_puppet(conf_t *cf)
gchar cmd[PATH_MAX];
int fd;
FILE *fp;
- if (cf->uri != NULL) {
+ if (uri != NULL) {
filename = strdup("puppet_conf_XXXXXX");
fd = mkstemp(filename);
fp = fdopen(fd, "w+b");
- if ((download(cf->uri, fp)) != 0) {
+ if ((download(uri, fp)) != 0) {
fclose(fp);
return -1;
}
fclose(fp);
- } else if (cf->data != NULL) {
+ } else if (data != NULL) {
filename = strdup("puppet_conf_blob");
- g_file_set_contents(filename, cf->data, strlen(cf->data), NULL);
+ g_file_set_contents(filename, data, strlen(data), NULL);
} else {
return -1;
}
@@ -137,16 +93,52 @@ mh_sysconfig_run_puppet(conf_t *cf)
return 0;
}
-int
-mh_sysconfig_run_augeas(conf_t *cf)
+static int
+mh_sysconfig_run_augeas(const char *query, const char *data)
{
fprintf(stderr, "not implemented\n");
return 0;
}
-int
-mh_sysconfig_query_augeas(conf_t *cf)
+static int
+mh_sysconfig_query_augeas(const char *query, const char *data)
{
fprintf(stderr, "not implemented\n");
return 0;
}
+
+int
+mh_sysconfig_run_uri(const char *uri, int flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ rc = mh_sysconfig_run_puppet(uri, NULL);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
+
+int
+mh_sysconfig_run_string(const char *data, int flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "puppet") == 0) {
+ rc = mh_sysconfig_run_puppet(NULL, data);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
+
+int
+mh_sysconfig_query(const char *query, const char *data, int flags, const char *scheme) {
+ int rc = 0;
+
+ if (g_strcmp0(scheme, "augeas") == 0) {
+ rc = mh_sysconfig_run_augeas(query, data);
+ } else {
+ rc = -1;
+ }
+ return rc;
+}
diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp
index 16fdf19..440b966 100644
--- a/src/sysconfig/sysconfig-qmf.cpp
+++ b/src/sysconfig/sysconfig-qmf.cpp
@@ -34,7 +34,9 @@
extern "C" {
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <glib/gprintf.h>
#include "matahari/sysconfig.h"
#include "matahari/logging.h"
@@ -44,6 +46,7 @@ extern "C" {
#include <sigar_format.h>
};
+static const char *configured_fn = "/var/lib/matahari/.is_configured";
class ConfigAgent : public MatahariAgent
{
private:
@@ -79,15 +82,24 @@ ConfigAgent::setup(qmf::AgentSession session)
return 0;
}
+static void
+set_configured() {
+ if(!g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
+ g_creat(configured_fn, S_IRWXU);
+ }
+}
+
static int
-is_configured(const char *key, int flags) {
- int rc = 0;
+is_configured(int flags) {
if(flags & SYSCONFIG_FLAG_FORCE) {
- return rc;
+ return 0;
}
- return rc;
+ if(g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
+ return 1;
+ }
+ return 0;
}
gboolean
@@ -105,23 +117,29 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
if (methodName == "run_uri") {
flags = event.getArguments()["flags"].asInt32();
- if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
+ if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
+ if (rc == 0) {
+ set_configured();
+ }
}
event.addReturnArgument("configured", rc);
} else if (methodName == "run_string") {
flags = event.getArguments()["flags"].asInt32();
- if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
+ if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
+ if (rc == 0) {
+ set_configured();
+ }
}
event.addReturnArgument("configured", rc);
} else if (methodName == "query") {
flags = event.getArguments()["flags"].asInt32();
- if((is_configured(_instance.getProperty("uuid").asString().c_str(), flags)) == 0) {
+ if((is_configured(flags)) == 0) {
rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
event.getArguments()["data"].asString().c_str(),
flags,
@@ -129,7 +147,7 @@ ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer u
}
event.addReturnArgument("configured", rc);
} else if (methodName == "is_configured") {
- rc = is_configured(event.getArguments()["key"].asString().c_str(), 0);
+ rc = is_configured(0);
_instance.setProperty("is_postboot_configured", rc);
event.addReturnArgument("configured", rc);
} else {
diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h
index 7e1b2b4..7ae11af 100644
--- a/src/tests/mh_api_sysconfig.h
+++ b/src/tests/mh_api_sysconfig.h
@@ -25,11 +25,9 @@ class MhApiSysconfigSuite : public CxxTest::TestSuite
void testIsConfigured(void)
{
- conf_t cf = {};
- cf.uri = "http://matahariproject.org/atom.xml";
- cf.flags = 0;
- cf.scheme = "puppet";
- TS_ASSERT((mh_sysconfig_run_uri(cf.uri, cf.flags, cf.scheme)) != -1);
+ const char *uri = "http://matahariproject.org/atom.xml";
+ int flags = 0;
+ TS_ASSERT((mh_sysconfig_run_uri(uri, flags, "puppet")) != -1);
}
};
--
1.7.6
12 years, 9 months
[PATCH] Invalid redefinition of variables in network library.
by Roman Rakus
Invalid redefinition causes functions get_ip_address and get_mac_address
to work improper.
Signed-off-by: Roman Rakus <rrakus(a)redhat.com>
---
src/lib/network.c | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/lib/network.c b/src/lib/network.c
index 9a1687b..f264856 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -154,10 +154,10 @@ mh_network_get_ip_address(const char *iface, char *buf, size_t len)
list = mh_network_get_interfaces();
for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
- struct mh_network_interface *iface = plist->data;
+ struct mh_network_interface *mh_iface = plist->data;
- if ((g_str_equal(mh_network_interface_get_name(iface), iface)) == TRUE) {
- sigar_net_address_to_string(NULL, &iface->ifconfig.address, addr_str);
+ if ((g_str_equal(mh_network_interface_get_name(mh_iface), iface)) == TRUE) {
+ sigar_net_address_to_string(NULL, &mh_iface->ifconfig.address, addr_str);
strncpy(buf, addr_str, len - 1);
buf[len - 1] = '\0';
break;
@@ -180,16 +180,16 @@ mh_network_get_mac_address(const char *iface, char *buf, size_t len)
list = mh_network_get_interfaces();
for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
- struct mh_network_interface *iface = plist->data;
+ struct mh_network_interface *mh_iface = plist->data;
- if ((g_str_equal(mh_network_interface_get_name(iface), iface)) == TRUE) {
+ if ((g_str_equal(mh_network_interface_get_name(mh_iface), iface)) == TRUE) {
snprintf(buf, len, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
- iface->ifconfig.hwaddr.addr.mac[0],
- iface->ifconfig.hwaddr.addr.mac[1],
- iface->ifconfig.hwaddr.addr.mac[2],
- iface->ifconfig.hwaddr.addr.mac[3],
- iface->ifconfig.hwaddr.addr.mac[4],
- iface->ifconfig.hwaddr.addr.mac[5]);
+ mh_iface->ifconfig.hwaddr.addr.mac[0],
+ mh_iface->ifconfig.hwaddr.addr.mac[1],
+ mh_iface->ifconfig.hwaddr.addr.mac[2],
+ mh_iface->ifconfig.hwaddr.addr.mac[3],
+ mh_iface->ifconfig.hwaddr.addr.mac[4],
+ mh_iface->ifconfig.hwaddr.addr.mac[5]);
break;
}
}
--
1.7.6
12 years, 9 months