[PATCH 1/3] Network routine added: network_status
by Adam Stokes
---
src/include/matahari/network.h | 2 +-
src/lib/network.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/src/include/matahari/network.h b/src/include/matahari/network.h
index 227670a..085f136 100644
--- a/src/include/matahari/network.h
+++ b/src/include/matahari/network.h
@@ -28,6 +28,6 @@ extern const gchar *network_get_mac_address(const gchar *iface);
extern void network_stop(const gchar *iface);
extern void network_start(const gchar *iface);
extern void network_restart(const gchar *iface);
-
+extern void network_status(const gchar *iface, guint64 *flags);
#endif /* __NETWORK_H */
diff --git a/src/lib/network.c b/src/lib/network.c
index bbb079a..a7f1762 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -78,6 +78,22 @@ network_restart(const gchar *iface)
network_os_start(iface);
}
+void
+network_status(const gchar *iface, guint64 *flags)
+{
+ GList *list = NULL;
+ GList *plist;
+ sigar_net_interface_config_t *ifconfig;
+
+ list = network_get_interfaces();
+ for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+ if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ *flags = ifconfig->flags;
+ }
+ }
+}
+
const gchar *
network_get_ip_address(const gchar *iface)
{
--
1.7.2.3
13 years, 5 months
[PATCH] Set proper autorun label for windows install
by Adam Stokes
---
src/windows/autorun.inf | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/windows/autorun.inf b/src/windows/autorun.inf
index 1222d6d..598e597 100644
--- a/src/windows/autorun.inf
+++ b/src/windows/autorun.inf
@@ -2,4 +2,4 @@
[autorun]
open=matahari.exe
icon=matahari.exe,0
-label=Matahari-0.0.4 Installation CD
+label=Matahari-0.4.0 Installation CD
--
1.7.2.3
13 years, 5 months
[PATCH] Network Agent routines:
by Adam Stokes
- Including support for starting/stopping interface devices
- Obtaining a couple of properties for device (mac, ip)
---
src/CMakeLists.txt | 13 ++++-
src/include/matahari/network.h | 33 +++++++++++
src/lib/network.c | 125 ++++++++++++++++++++++++++++++++++++++++
src/lib/network_linux.c | 56 ++++++++++++++++++
src/lib/network_private.h | 22 +++++++
src/lib/network_windows.c | 70 ++++++++++++++++++++++
6 files changed, 318 insertions(+), 1 deletions(-)
create mode 100644 src/include/matahari/network.h
create mode 100644 src/lib/network.c
create mode 100644 src/lib/network_linux.c
create mode 100644 src/lib/network_private.h
create mode 100644 src/lib/network_windows.c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9bd1c8..1089410 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -47,6 +47,9 @@ target_link_libraries(mhost mcommon)
add_library (msrv lib/services.c lib/services_${VARIANT}.c)
target_link_libraries(msrv mcommon)
+add_library (mnet lib/network.c lib/network_${VARIANT}.c)
+target_link_libraries(mnet mcommon)
+
if(WIN32)
target_link_libraries(mhost wsock32)
target_link_libraries(mcommon wsock32)
@@ -57,6 +60,7 @@ add_executable(${M_HOST} host/matahari-host.cpp ${SCHEMA_SOURCES} ${COMMON_SOURC
target_link_libraries(${M_HOST} mhost)
add_executable(${M_NET} net/matahari-net.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
+target_link_libraries(${M_NET} mnet)
add_executable(${M_SRV} service/matahari-srv.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
target_link_libraries(${M_SRV} msrv)
@@ -192,6 +196,13 @@ if(NOT QPIDTYPES)
set(QPIDTYPES "")
endif(NOT QPIDTYPES)
+# sigar
+find_library(SIGAR sigar)
+if(NOT SIGAR)
+ message("SIGAR library not found.")
+ set(SIGAR "")
+endif(NOT SIGAR)
+
find_program(QMFGEN qmf-gen)
if(QMFGEN-NOTFOUND)
message(FATAL_ERROR Missing QMF schema processor.)
@@ -228,7 +239,7 @@ endif (regen_schema)
# Add QF libraries
foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} ${QPIDCOMMON} ${QPIDCLIENT} ${QPIDTYPES} ${QMF})
+ target_link_libraries(${daemon} ${QPIDCOMMON} ${QPIDCLIENT} ${QPIDTYPES} ${QMF} ${SIGAR})
endforeach(daemon ${DAEMONS})
# Install targets
diff --git a/src/include/matahari/network.h b/src/include/matahari/network.h
new file mode 100644
index 0000000..227670a
--- /dev/null
+++ b/src/include/matahari/network.h
@@ -0,0 +1,33 @@
+#ifndef __NETWORK_H
+#define __NETWORK_H
+
+/* network.h - Copyright (c) 2010 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
+ */
+
+#include <glib.h>
+
+extern GList *network_get_interfaces(void);
+extern const gchar *network_get_ip_address(const gchar *iface);
+extern const gchar *network_get_mac_address(const gchar *iface);
+
+extern void network_stop(const gchar *iface);
+extern void network_start(const gchar *iface);
+extern void network_restart(const gchar *iface);
+
+
+#endif /* __NETWORK_H */
diff --git a/src/lib/network.c b/src/lib/network.c
new file mode 100644
index 0000000..bbb079a
--- /dev/null
+++ b/src/lib/network.c
@@ -0,0 +1,125 @@
+/* network.c - Copyright (c) 2010 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 "matahari/network.h"
+#include "network_private.h"
+#include "matahari/logging.h"
+#include <sigar.h>
+
+static GList *
+query_interface_table(void)
+{
+ gint status;
+ guint32 lpc = 0;
+ GList *interfaces = NULL;
+ sigar_t* sigar;
+ sigar_net_interface_list_t iflist;
+ sigar_net_interface_config_t *ifconfig;
+
+ sigar_open(&sigar);
+ status = sigar_net_interface_list_get(sigar, &iflist);
+ if(status == SIGAR_OK) {
+ for(lpc; lpc < iflist.number; lpc++) {
+ ifconfig = g_new0(sigar_net_interface_config_t, 1);
+ status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
+ ifconfig);
+ if(status == SIGAR_OK)
+ interfaces = g_list_prepend(interfaces, ifconfig);
+ }
+ sigar_net_interface_list_destroy(sigar, &iflist);
+ }
+ sigar_close(sigar);
+ return interfaces;
+}
+
+GList *
+network_get_interfaces(void)
+{
+ GList *list = NULL;
+ list = query_interface_table();
+ return list;
+}
+
+void
+network_start(const gchar *iface)
+{
+ network_os_start(iface);
+}
+
+void
+network_stop(const gchar *iface)
+{
+ network_os_stop(iface);
+}
+
+void
+network_restart(const gchar *iface)
+{
+ network_os_stop(iface);
+ network_os_start(iface);
+}
+
+const gchar *
+network_get_ip_address(const gchar *iface)
+{
+ GList *list = NULL;
+ GList *plist;
+ sigar_net_interface_config_t *ifconfig;
+ gchar addr_str[SIGAR_INET6_ADDRSTRLEN];
+ gchar *paddr_str;
+
+ list = network_get_interfaces();
+ for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+ if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ sigar_net_address_to_string(NULL, &ifconfig->address, addr_str);
+ paddr_str = g_strdup(addr_str);
+ return paddr_str;
+ }
+ }
+ return NULL;
+}
+
+const gchar *
+network_get_mac_address(const gchar *iface)
+{
+ GList *list = NULL;
+ GList *plist;
+ sigar_net_interface_config_t *ifconfig;
+ gchar *mac;
+
+ list = network_get_interfaces();
+ for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+ if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ mac = g_strdup_printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+ ifconfig->hwaddr.addr.mac[0],
+ ifconfig->hwaddr.addr.mac[1],
+ ifconfig->hwaddr.addr.mac[2],
+ ifconfig->hwaddr.addr.mac[3],
+ ifconfig->hwaddr.addr.mac[4],
+ ifconfig->hwaddr.addr.mac[5]);
+ return mac;
+ }
+ }
+ return NULL;
+}
diff --git a/src/lib/network_linux.c b/src/lib/network_linux.c
new file mode 100644
index 0000000..2172c33
--- /dev/null
+++ b/src/lib/network_linux.c
@@ -0,0 +1,56 @@
+/*
+ * network_linux.c: linux network functions
+ *
+ * Copyright (C) 2010 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ * Author: Adam Stokes <astokes(a)fedoraproject.org>
+ */
+
+#include "matahari/network.h"
+#include <string.h>
+
+void
+network_os_start(const char *iface)
+{
+ gchar *argv[2];
+ gboolean ret;
+ GError *error = NULL;
+
+ argv[0] = "/sbin/ifup";
+ argv[1] = strdup(iface);
+ argv[2] = NULL;
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
+ if(ret == FALSE) {
+ g_error_free(error);
+ }
+}
+
+void
+network_os_stop(const char *iface)
+{
+ gchar *argv[2];
+ gboolean ret;
+ GError *error = NULL;
+
+ argv[0] = "/sbin/ifdown";
+ argv[1] = strdup(iface);
+ argv[2] = NULL;
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
+ if(ret == FALSE) {
+ g_error_free(error);
+ }
+}
diff --git a/src/lib/network_private.h b/src/lib/network_private.h
new file mode 100644
index 0000000..4a12488
--- /dev/null
+++ b/src/lib/network_private.h
@@ -0,0 +1,22 @@
+/* network_private.h - Copyright (C) 2010 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
+*/
+
+#include <glib.h>
+
+extern void network_os_stop(const gchar *iface);
+extern void network_os_start(const gchar *iface);
diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c
new file mode 100644
index 0000000..23f3872
--- /dev/null
+++ b/src/lib/network_windows.c
@@ -0,0 +1,70 @@
+/*
+ * network_windows.c: windows network functions
+ *
+ * Copyright (C) 2010 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ * Author: Adam Stokes <astokes(a)fedoraproject.org>
+ */
+
+#ifndef WINVER
+# define WINVER 0x0501
+#endif
+
+#include "matahari/network.h"
+
+#include <config.h>
+
+#include <spawn.h>
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windns.h>
+#include <iphlpapi.h>
+#include <process.h>
+
+#define GAA_FLAGS ( GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_ANYCAST )
+#define BUFSIZE 1024
+
+void
+network_os_stop(const char *iface)
+{
+ gchar *exe_path;
+ gchar *p;
+ gint r;
+
+ p = getenv("WINDIR");
+ exe_path = g_strdup_printf("%s\\system32\\netsh", p);
+
+ r = _spawnl(_P_WAIT, exe_path, exe_path, "interface",
+ "set", "interface", iface, "disabled", NULL);
+ g_free(exe_path);
+}
+
+void
+network_os_start(const char *iface)
+{
+ gchar *exe_path;
+ gchar *p;
+ gint r;
+
+ p = getenv("WINDIR");
+ exe_path = g_strdup_printf("%s\\system32\\netsh", p);
+
+ r = _spawnl(_P_WAIT, exe_path, exe_path, "interface",
+ "set", "interface", iface, "enabled", NULL);
+ g_free(exe_path);
+}
--
1.7.2.3
13 years, 5 months
[PATCH] Few improvements in host_linux.c
by Radek Novacek
Hi, since we don't have any git workflow (and I even don't have git access
yet), I'm sending this patch for host_linux.c this way.
Radek Novacek
---
src/lib/host_linux.c | 69
++++++++++++++++++++++++++------------------------
1 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 726e1a2..0aaf025 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -40,20 +40,35 @@
#include "matahari/host.h"
#include "host_private.h"
+/** Reads whole content of file \p input and returns pointer to it
+ * \param input Input file (must already opened for reading)
+ * \param data_length Pointer to length of read data
+ * \return Pointer to the read data (must be freed!)
+ */
+char *read_file(FILE *input, size_t *data_length)
+{
+ char *buffer = NULL;
+ *data_length = 0;
+ int chunk = 512, read_chars = 0;
+ do {
+ buffer = realloc(buffer, chunk + *data_length + 1);
+ read_chars = fread(buffer + *data_length, 1, chunk, input);
+ *data_length += read_chars;
+ } while (read_chars > 0);
+ buffer[*data_length] = '\0';
+ return buffer;
+}
+
+
const char *
host_os_get_uuid()
{
static char * uuid = NULL;
- if(uuid != NULL) {
+ if(uuid == NULL) {
FILE *input = fopen("/var/lib/dbus/machine-id", "r");
- char *buffer = NULL;
- int chunk = 512, data_length = 0, read_chars = 0;
- do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
- } while (read_chars > 0);
+ size_t data_length;
+ char *buffer = read_file(input, &data_length);
if(data_length == 0) {
mh_warn("Could not read from /var/lib/dbus/machine-id");
@@ -63,8 +78,8 @@ host_os_get_uuid()
switch(buffer[lpc]) {
case '\0':
case '\n':
- uuid = malloc(lpc);
- snprintf(uuid, lpc-1, "%s", buffer);
+ uuid = strndup(buffer, lpc);
+ break;
}
}
}
@@ -99,7 +114,7 @@ host_os_get_operating_system(void)
struct utsname details;
if(!uname(&details)) {
int len = 4 + strlen(details.sysname) + strlen(details.release);
- operating_system = malloc(len);
+ operating_system = malloc(len * sizeof(char));
sprintf(operating_system, "%s (%s)", details.sysname,
details.release);
}
}
@@ -110,7 +125,7 @@ host_os_get_operating_system(void)
const char *
host_os_get_hypervisor(void)
{
- static char * hypervisor;
+ static char *hypervisor = NULL;
if(hypervisor == NULL) {
@@ -164,8 +179,6 @@ host_os_get_memory(void)
void
host_os_get_load_averages(double *one, double *five, double *fifteen)
{
- size_t chunk = 512;
- size_t read_chars = 0;
size_t data_length = 0;
char *buffer = NULL;
@@ -177,14 +190,10 @@ host_os_get_load_averages(double *one, double *five,
double *fifteen)
input = fopen("/proc/loadavg", "r");
- do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
- } while (read_chars > 0);
+ buffer = read_file(input, &data_length);
if(data_length != 0) {
- sscanf(buffer, "%f %f %f", one, five, fifteen);
+ sscanf(buffer, "%lf %lf %lf", one, five, fifteen);
}
fclose(input);
free(buffer);
@@ -206,23 +215,17 @@ host_os_shutdown(void)
void
host_os_get_cpu_details(void)
{
- size_t chunk = 512;
- size_t read_chars = 0;
size_t data_length = 0;
-
+
char *buffer = NULL;
FILE *input = NULL;
-
+
if(cpuinfo.initialized) return;
cpuinfo.initialized = 1;
input = fopen("/proc/cpuinfo", "r");
- do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
- } while (read_chars > 0);
+ buffer = read_file(input, &data_length);
if(data_length == 0) {
mh_warn("Could not read from /proc/cpuinfo");
@@ -260,16 +263,16 @@ host_os_get_cpu_details(void)
value = malloc(1 + found[5] - found[4]);
snprintf(value, found[5] - found[4], "%s", buffer +
offset + found[4]);
- if (name == "processor") {
+ if (strcmp(name, "processor") == 0) {
cpuinfo.cpus++;
- } else if (name == "cpu cores") {
+ } else if (strcmp(name, "cpu cores") == 0) {
cpuinfo.cores += atoi(value);
- } else if (name == "model name") {
+ } else if (strcmp(name, "model name") == 0) {
cpuinfo.model = strdup(value);
- } else if (name == "flags") {
+ } else if (strcmp(name, "flags") == 0) {
/* if the cpuflags contain "lm" then it's a 64 bit
CPU
*
http://www.brandonhutchinson.com/Understanding_proc_cpuinfo.html
*/
--
1.7.3.2
13 years, 5 months
best way to split a qmf schema into separate files
by Adam Stokes
So I have a schema file with :
<schema package="org.mataharproject">
<class name="Host">
<class name="Network">
...
Is there some sort of include directive so that I can split this up into their own files like
schema.xml
schema-host.xml
schema-net.xml
If i create 3 schema files with the schema package directive then some of the generated files will be overwritten, for example, Package.h/cpp
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 5 months
[RFC] initial schema for Logging agent
by apevec@redhat.com
---
src/CMakeLists.txt | 6 ++-
src/log/matahari-log.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++
src/schema.xml | 38 +++++++++++++++++
3 files changed, 144 insertions(+), 1 deletions(-)
create mode 100644 src/log/matahari-log.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9664781..ee8906d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,8 +15,9 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
set(M_HOST "matahari-hostd")
set(M_NET "matahari-netd")
set(M_SRV "matahari-serviced")
+set(M_LOG "matahari-logd")
-set(DAEMONS ${M_HOST} ${M_NET} ${M_SRV})
+set(DAEMONS ${M_HOST} ${M_NET} ${M_SRV} ${M_LOG})
file(GLOB SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/*.xml")
@@ -29,6 +30,7 @@ add_definitions(-DMATAHARI_BROKER="${MATAHARI_BROKER}")
set(SCHEMA_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/Host.cpp
${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/Network.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/Logging.cpp
${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/Services.cpp
${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/Resources.cpp
${CMAKE_CURRENT_BINARY_DIR}/qmf/com/redhat/matahari/EventHeartbeat.cpp
@@ -61,6 +63,8 @@ add_executable(${M_NET} net/matahari-net.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCE
add_executable(${M_SRV} service/matahari-srv.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
target_link_libraries(${M_HOST} msrv)
+add_executable(${M_LOG} log/matahari-log.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
+
foreach(daemon ${DAEMONS})
target_link_libraries(${daemon} mcommon)
if(WIN32)
diff --git a/src/log/matahari-log.cpp b/src/log/matahari-log.cpp
new file mode 100644
index 0000000..6b62ff4
--- /dev/null
+++ b/src/log/matahari-log.cpp
@@ -0,0 +1,101 @@
+/* matahari-log.cpp - Copyright (C) 2010 Red Hat, Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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. A copy of the GNU General Public License is
+ * also available at http://www.gnu.org/copyleft/gpl.html.
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include <string>
+#include <qpid/management/Manageable.h>
+#include <qpid/agent/ManagementAgent.h>
+#include "matahari/mh_agent.h"
+
+#include "qmf/com/redhat/matahari/Logging.h"
+#include "qmf/com/redhat/matahari/ArgsLoggingExtract_date_range.h"
+#include "qmf/com/redhat/matahari/ArgsLoggingExtract_pattern.h"
+#include "qmf/com/redhat/matahari/ArgsLoggingSystem_logfile.h"
+#include "qmf/com/redhat/matahari/ArgsLoggingTruncate_logfile.h"
+
+extern "C" {
+#include "matahari/logging.h"
+}
+
+class LogAgent : public MatahariAgent
+{
+ private:
+ ManagementAgent* _agent;
+ _qmf::Logging* _management_object;
+
+ public:
+ int setup(ManagementAgent* agent);
+ ManagementObject* GetManagementObject() const { return _management_object; }
+ status_t ManagementMethod(uint32_t method, Args& arguments, string& text);
+};
+
+extern "C" {
+#include <stdlib.h>
+#include <string.h>
+};
+
+int
+main(int argc, char **argv)
+{
+ LogAgent agent;
+ int rc = agent.init(argc, argv);
+ while (rc == 0) {
+ qpid::sys::sleep(1);
+ }
+ return rc;
+}
+
+int
+LogAgent::setup(ManagementAgent* agent)
+{
+ this->_agent = agent;
+ this->_management_object = new _qmf::Logging(agent, this);
+ this->_management_object->set_hostname(get_hostname());
+
+ agent->addObject(this->_management_object);
+
+ return 0;
+}
+
+Manageable::status_t
+LogAgent::ManagementMethod(uint32_t method, Args& arguments, string& text)
+{
+ switch(method)
+ {
+ case _qmf::Logging::METHOD_EXTRACT_DATE_RANGE:
+
+ return Manageable::STATUS_OK;
+
+ case _qmf::Logging::METHOD_EXTRACT_PATTERN:
+
+ return Manageable::STATUS_OK;
+
+ case _qmf::Logging::METHOD_SYSTEM_LOGFILE:
+
+ return Manageable::STATUS_OK;
+
+ case _qmf::Logging::METHOD_TRUNCATE_LOGFILE:
+
+ return Manageable::STATUS_OK;
+
+ }
+ return Manageable::STATUS_NOT_IMPLEMENTED;
+}
diff --git a/src/schema.xml b/src/schema.xml
index ece5d0d..17b4110 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -239,4 +239,42 @@
</method-->
</class>
+ <class name="Logging">
+ <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
+
+ <method name="extract_date_range">
+ <arg name="filename" dir="I" type="lstr" />
+ <arg name="start" dir="I" type="absTime" />
+ <arg name="end" dir="I" type="absTime" />
+ <arg name="lines" dir="O" type="list" />
+ </method>
+ <method name="extract_pattern">
+ <arg name="filename" dir="I" type="lstr" />
+ <arg name="regex_list" dir="I" type="list" />
+ <arg name="lines" dir="O" type="list" />
+ </method>
+ <!-- What is the point of search_* methods?
+ output is list of tupples:
+ { filename (String), last_modified (Integer) }
+ https://fedorahosted.org/matahari/wiki/LoggingAPIs
+ It's not part of Ricci API which is used as justification
+ http://sources.redhat.com/cluster/conga/ricci_api/logging_api.html
+ method name="search_content">
+ <arg name="paths" dir="I" type="list" />
+ <arg name="regex" dir="I" type="sstr" />
+ <arg name="filenames" dir="O" type="list" />
+ </method>
+ method name="search_name">
+ <arg name="paths" dir="I" type="list" />
+ <arg name="regex_list" dir="I" type="list" />
+ <arg name="filenames" dir="O" type="list" />
+ </method -->
+ <method name="system_logfile">
+ <arg name="filename" dir="O" type="lstr" />
+ </method>
+ <method name="truncate_logfile">
+ <arg name="rc" dir="O" type="uint32" />
+ </method>
+ </class>
+
</schema>
--
1.7.2.3
13 years, 5 months
[PATCH] illegal null ptr dereference
by Adam Stokes
Something was happening where we were trying to dereference a null ptr. This mainly happened when libvirt-devel was available but libvirt daemon was not running to receive the running hypervisor.
I just set this to return None in order to please the c++ compiler :)
---
src/CMakeLists.txt | 10 ++++++----
src/lib/host_linux.c | 10 ++++------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1089410..d026c9c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -83,16 +83,18 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/matahari.h.in ${CMAKE_CURREN
## Modules
pkg_check_modules(glib REQUIRED glib-2.0)
pkg_check_modules(pcre REQUIRED libpcre)
+pkg_check_modules(libvirt libvirt)
pkg_check_modules(netcf REQUIRED netcf)
if(NOT PKG_CONFIG_FOUND)
message("pkg-config not found")
endif(NOT PKG_CONFIG_FOUND)
-find_library(VIRT virt)
-if(VIRT_FOUND)
- target_link_libraries(${M_HOST} ${VIRT})
-endif(VIRT_FOUND)
+if(libvirt_FOUND)
+ target_link_libraries(${M_HOST} ${libvirt_LIBRARIES})
+ include_directories(mhost ${libvirt_INCLUDE_DIRS})
+ add_definitions(-DHAVE_LIBVIRT1)
+endif(libvirt_FOUND)
if(NOT pcre_FOUND)
IF(MSVC)
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 726e1a2..d0d8dfe 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -111,19 +111,17 @@ const char *
host_os_get_hypervisor(void)
{
static char * hypervisor;
-
- if(hypervisor == NULL) {
-
#ifdef HAVE_LIBVIRT1
+ if(hypervisor == NULL) {
virConnectPtr lvconn = virConnectOpenReadOnly(NULL);
-
if(lvconn) {
hypervisor = strdup(virConnectGetType(lvconn));
virConnectClose(lvconn);
}
-#endif
-
}
+#else
+ hypervisor = strdup("None");
+#endif
return hypervisor;
}
--
1.7.2.3
13 years, 5 months
CMake patch
by Radek Novacek
Hi, I've checked CMakeLists.txt in next branch and prepared patch that brings
some improvements:
* Shared libraries instead of static
* .so versioning for shared libraries
* compiling with -Wall (can help to find some problems)
* added missing linking of libraries
Radek Novacek
Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
src/CMakeLists.txt | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9664781..08c4859 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,13 @@ else(WIN32)
set(VARIANT "linux")
endif(WIN32)
+set(CMAKE_C_FLAGS "-Wall")
+set(CMAKE_CXX_FLAGS "-Wall")
+
+set(MCOMMON_VERSION 0.0.1)
+set(MHOST_VERSION 0.0.1)
+set(MSRV_VERSION 0.0.1)
+
include(FindPkgConfig)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
@@ -39,12 +46,15 @@ set(SCHEMA_SOURCES
## Libraries and Common code
set(COMMON_SOURCES lib/mh_agent.cpp)
-add_library (mcommon lib/utilities.c lib/mainloop.c)
+add_library (mcommon SHARED lib/utilities.c lib/mainloop.c)
+set_target_properties(mcommon PROPERTIES SOVERSION ${MCOMMON_VERSION})
-add_library (mhost lib/host.c lib/host_${VARIANT}.c)
+add_library (mhost SHARED lib/host.c lib/host_${VARIANT}.c)
+set_target_properties(mhost PROPERTIES SOVERSION ${MHOST_VERSION})
target_link_libraries(mhost mcommon)
-add_library (msrv lib/services.c lib/services_${VARIANT}.c)
+add_library (msrv SHARED lib/services.c lib/services_${VARIANT}.c)
+set_target_properties(msrv PROPERTIES SOVERSION ${MSRV_VERSION})
target_link_libraries(msrv mcommon)
if(WIN32)
@@ -80,15 +90,17 @@ configure_file
(${CMAKE_CURRENT_SOURCE_DIR}/include/matahari.h.in ${CMAKE_CURREN
pkg_check_modules(glib REQUIRED glib-2.0)
pkg_check_modules(pcre REQUIRED libpcre)
pkg_check_modules(netcf REQUIRED netcf)
+pkg_check_modules(libvirt libvirt)
if(NOT PKG_CONFIG_FOUND)
message("pkg-config not found")
endif(NOT PKG_CONFIG_FOUND)
-find_library(VIRT virt)
-if(VIRT_FOUND)
- target_link_libraries(${M_HOST} ${VIRT})
-endif(VIRT_FOUND)
+if(libvirt_FOUND)
+ target_link_libraries(mhost ${libvirt_LIBRARIES})
+ include_directories(mhost ${libvirt_INCLUDE_DIRS})
+ add_definitions(-DHAVE_LIBVIRT1)
+endif(libvirt_FOUND)
if(NOT pcre_FOUND)
IF(MSVC)
@@ -103,7 +115,7 @@ if(NOT pcre_FOUND)
endif(NOT pcre_FOUND)
if(pcre_FOUND)
- target_link_libraries(${M_HOST} ${pcre_LIBRARIES})
+ target_link_libraries(mhost ${pcre_LIBRARIES})
include_directories(${pcre_INCLUDE_DIRS})
else(pcre_FOUND)
message(FATAL_ERROR "PCRE header/library not found.")
@@ -121,20 +133,11 @@ if(glib_FOUND)
foreach(daemon ${DAEMONS})
target_link_libraries(${daemon} ${glib_LIBRARIES})
endforeach(daemon ${DAEMONS})
+ target_link_libraries(mcommon ${glib_LIBRARIES})
else(glib_FOUND)
message(FATAL_ERROR "Glib2 header/library not found.")
endif(glib_FOUND)
-set(simple_libs check libvirt udev_new)
-foreach(lib ${simple_libs})
- find_library(${lib}_LIBRARIES ${lib})
- if(${lib}_LIBRARIES)
- target_link_libraries(${M_HOST} ${${lib}_LIBRARIES})
- else(${lib}_LIBRARIES)
- message("Library ${lib} not found")
- endif(${lib}_LIBRARIES)
-endforeach(lib ${simple_libs})
-
## qpid
if(MSVC)
--
1.7.3.2
13 years, 5 months
[PATCH] Network Agent routines:
by Adam Stokes
- Including support for starting/stopping interface devices
- Obtaining a couple of properties for device (mac, ip)
---
src/CMakeLists.txt | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9bd1c8..1089410 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -47,6 +47,9 @@ target_link_libraries(mhost mcommon)
add_library (msrv lib/services.c lib/services_${VARIANT}.c)
target_link_libraries(msrv mcommon)
+add_library (mnet lib/network.c lib/network_${VARIANT}.c)
+target_link_libraries(mnet mcommon)
+
if(WIN32)
target_link_libraries(mhost wsock32)
target_link_libraries(mcommon wsock32)
@@ -57,6 +60,7 @@ add_executable(${M_HOST} host/matahari-host.cpp ${SCHEMA_SOURCES} ${COMMON_SOURC
target_link_libraries(${M_HOST} mhost)
add_executable(${M_NET} net/matahari-net.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
+target_link_libraries(${M_NET} mnet)
add_executable(${M_SRV} service/matahari-srv.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
target_link_libraries(${M_SRV} msrv)
@@ -192,6 +196,13 @@ if(NOT QPIDTYPES)
set(QPIDTYPES "")
endif(NOT QPIDTYPES)
+# sigar
+find_library(SIGAR sigar)
+if(NOT SIGAR)
+ message("SIGAR library not found.")
+ set(SIGAR "")
+endif(NOT SIGAR)
+
find_program(QMFGEN qmf-gen)
if(QMFGEN-NOTFOUND)
message(FATAL_ERROR Missing QMF schema processor.)
@@ -228,7 +239,7 @@ endif (regen_schema)
# Add QF libraries
foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} ${QPIDCOMMON} ${QPIDCLIENT} ${QPIDTYPES} ${QMF})
+ target_link_libraries(${daemon} ${QPIDCOMMON} ${QPIDCLIENT} ${QPIDTYPES} ${QMF} ${SIGAR})
endforeach(daemon ${DAEMONS})
# Install targets
--
1.7.2.3
13 years, 5 months