[PATCH] Core: Don't use insert() on maps
by Zane Bitter
Using insert is prone to errors if the content of the map is also set in
other parts of the code, since in the event of a key collision the map is
not updated by insert().
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/lib/mh_agent.cpp | 7 +++----
src/service/service-qmf-console.cpp | 5 ++---
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 1cad1ed..63352df 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -154,15 +154,14 @@ connection_option(int code, const char *name, const char *arg, void *userdata)
qpid::types::Variant::Map *options = static_cast<qpid::types::Variant::Map*>(userdata);
if(strcmp(name, "service") == 0) {
- options->insert(std::pair<std::string, qpid::types::Variant>("sasl-service", arg));
- options->insert(std::pair<std::string, qpid::types::Variant>("sasl-mechanism", "GSSAPI"));
-
+ (*options)["sasl-service"] = arg;
+ (*options)["sasl-mechanism"] = "GSSAPI";
} else if(strcmp(name, "reconnect") == 0) {
bool reconnect = !arg || (strcasecmp(arg, "no") != 0 &&
strcasecmp(arg, "false") != 0);
(*options)["reconnect"] = reconnect;
} else {
- options->insert(std::pair<std::string, qpid::types::Variant>(name, arg));
+ (*options)[name] = arg;
}
return 0;
}
diff --git a/src/service/service-qmf-console.cpp b/src/service/service-qmf-console.cpp
index 9398746..31ad417 100644
--- a/src/service/service-qmf-console.cpp
+++ b/src/service/service-qmf-console.cpp
@@ -54,10 +54,9 @@ resource_arg(int code, const char *name, const char *arg, void *userdata)
cout << name << "=" << arg << endl;
if(strcmp(name, "timeout") == 0 || strcmp(name, "interval") == 0) {
uint32_t number = 1000 * atoi(arg);
- options->insert(std::pair<std::string, qpid::types::Variant>(name, number));
-
+ (*options)[name] = number;
} else {
- options->insert(std::pair<std::string, qpid::types::Variant>(name, arg));
+ (*options)[name] = arg;
}
return 0;
12 years, 9 months
[sigar PATCH] Correct reporting of number of CPU cores on Linux
by Zane Bitter
There are a number of problems with the implementation of
sigar_cpu_info_list_get() on Linux:
* The call sysconf(_SC_NPROCESSORS_CONF) returns the number of processors
in the system, not the number of cores (i.e. in a hyperthreaded
system, sigar_cpu_total_count() gives the number of threads, not cores).
* It turns out that the CPUINFO instruction on x86 is not a reliable way of
getting the number of cores, or even the number of threads (which is what
sigar_cpu_core_count() is actually trying to read).
* core_rollup ignores all but one processor per socket, on the assumption
that entries in /proc/cpuinfo appear grouped by socket. This assumption
is not correct.
* The get_cpuinfo_max_freq() function retrieves data corresponding to the
wrong processor in the presence of the core_rollup option (although the
practical effect is cancelled out by the previous issue, purely by
coincidence).
The solution is to obtain all information required about the processors
from the kernel via the /proc/cpuinfo file. This allows us to return the
actual number of cores, rather than threads, in the cores_per_socket and
total_cores variables. It also allows us to return the correct number of
sockets in the system, which was broken by a combination of the first two
issues above. Theoretically, all of this would work even in an asymmetric
system with different numbers of cores in each socket. It should work even
if the processors listed in /proc/cpuinfo are in arbitrary order, even in
the presence of the core_rollup option.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/os/linux/linux_sigar.c | 92 +++++++++++++++++++++++++++++++++++++++-----
1 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c
index 0a44623..8f268ad 100644
--- a/src/os/linux/linux_sigar.c
+++ b/src/os/linux/linux_sigar.c
@@ -45,6 +45,13 @@
#define PROC_PARTITIONS PROC_FS_ROOT "partitions"
#define PROC_DISKSTATS PROC_FS_ROOT "diskstats"
+typedef struct {
+ sigar_cpu_info_t cpu;
+ int socket;
+ int core;
+ int processor;
+} processor_info_t;
+
/*
* /proc/self/stat fields:
* 1 - pid
@@ -1498,16 +1505,15 @@ static SIGAR_INLINE void cpu_info_strcpy(char *ptr, char *buf, int len)
}
}
-static int get_cpu_info(sigar_t *sigar, sigar_cpu_info_t *info,
+static int get_cpu_info(sigar_t *sigar, processor_info_t *proc,
FILE *fp)
{
char buffer[BUFSIZ], *ptr;
+ sigar_cpu_info_t *info = &proc->cpu;
int found = 0;
- /* UML vm wont have "cpu MHz" or "cache size" fields */
- info->mhz = 0;
- info->cache_size = 0;
+ memset(proc, 0, sizeof(*proc));
#ifdef __powerpc64__
SIGAR_SSTRCPY(info->vendor, "IBM");
@@ -1519,6 +1525,10 @@ static int get_cpu_info(sigar_t *sigar, sigar_cpu_info_t *info,
if (strnEQ(ptr, "processor", 9)) {
found = 1;
}
+ else if (strnEQ(ptr, "physical id", 11)) {
+ ptr = cpu_info_strval(ptr);
+ proc->socket = sigar_strtoul(ptr);
+ }
break;
case 'v':
/* "vendor_id" or "vendor" */
@@ -1554,6 +1564,14 @@ static int get_cpu_info(sigar_t *sigar, sigar_cpu_info_t *info,
ptr = cpu_info_strval(ptr);
info->cache_size = sigar_strtoul(ptr);
}
+ else if (strnEQ(ptr, "core id", 7)) {
+ ptr = cpu_info_strval(ptr);
+ proc->core = sigar_strtoul(ptr);
+ }
+ else if (strnEQ(ptr, "cpu cores", 9)) {
+ ptr = cpu_info_strval(ptr);
+ info->cores_per_socket = sigar_strtoul(ptr);
+ }
#ifdef __powerpc64__
/* each /proc/cpuinfo entry looks like so:
* processor : 0
@@ -1601,11 +1619,55 @@ static void get_cpuinfo_max_freq(sigar_cpu_info_t *cpu_info, int num)
}
}
+typedef struct {
+ size_t size;
+ sigar_uint32_t *data;
+} bitmap_t;
+
+static int bitmap_check(sigar_t *sigar, bitmap_t *bitmap, unsigned int index)
+{
+ int ret = 0;
+ size_t i = index / 32;
+ if (i >= bitmap->size) {
+ void *new_data;
+ size_t old_size = bitmap->size;
+
+ bitmap->size *= 2;
+ if (i >= bitmap->size) {
+ bitmap->size = i + 1;
+ }
+
+ new_data = realloc(bitmap->data,
+ bitmap->size * sizeof(sigar_uint32_t));
+
+ if (new_data) {
+ bitmap->data = new_data;
+ memset(&bitmap->data[old_size], 0,
+ (bitmap->size - old_size) * sizeof(sigar_uint32_t));
+ } else {
+ // Out of memory. This could result in counting a single socket
+ // multiple times if the physical id is huge.
+ sigar_log_printf(sigar, SIGAR_LOG_WARN,
+ "Cannot allocate CPU socket bitmap");
+ return 0;
+ }
+ } else {
+ ret = (bitmap->data[i] & (1 << (index % 32))) != 0;
+ }
+
+ bitmap->data[i] |= 1 << (index % 32);
+
+ return ret;
+}
+
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
FILE *fp;
int core_rollup = sigar_cpu_core_rollup(sigar), i=0;
+ processor_info_t processor;
+ int total_sockets = 0, total_cores = 0;
+ bitmap_t sockets_found = {};
if (!(fp = fopen(PROC_FS_ROOT "cpuinfo", "r"))) {
return errno;
@@ -1614,25 +1676,33 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
(void)sigar_cpu_total_count(sigar);
sigar_cpu_info_list_create(cpu_infos);
- while (get_cpu_info(sigar, &cpu_infos->data[cpu_infos->number], fp)) {
+ while (get_cpu_info(sigar, &processor, fp)) {
sigar_cpu_info_t *info;
- if (core_rollup && (i++ % sigar->lcpu)) {
- continue; /* fold logical processors */
+ if (!bitmap_check(sigar, &sockets_found, processor.socket)) {
+ total_sockets++;
+ total_cores += processor.cpu.cores_per_socket;
+ } else if (core_rollup) {
+ continue;
}
info = &cpu_infos->data[cpu_infos->number];
- get_cpuinfo_max_freq(info, cpu_infos->number);
- info->total_cores = sigar->ncpu;
- info->cores_per_socket = sigar->lcpu;
- info->total_sockets = sigar_cpu_socket_count(sigar);
+ memcpy(info, &processor.cpu, sizeof(*info));
+ get_cpuinfo_max_freq(info, processor.processor);
+ get_cpuinfo_min_freq(info, processor.processor);
++cpu_infos->number;
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
}
fclose(fp);
+ free(sockets_found.data);
+
+ for (i = 0; i < cpu_infos->number; i++) {
+ cpu_infos->data[i].total_cores = total_cores;
+ cpu_infos->data[i].total_sockets = total_sockets;
+ }
return SIGAR_OK;
}
12 years, 9 months
[PATCH 1/2] - Add selinux subpackage
by Adam Stokes
- Gives necessary file context permissions to
@localstatedir@/lib/matahari
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari.spec.in | 27 +++++++++++++++++++++++++--
1 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index aae23c0..9973a75 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -93,6 +93,7 @@ Summary: C++ library used by Matahari agents
Group: Applications/System
Requires: %{name}-lib = %{version}-%{release}
Requires: qpid-cpp-client-ssl > 0.7
+Requires: %{name}-selinux
%description agent-lib
C++ library containing the base class for Matahari agents
@@ -162,6 +163,16 @@ Requires: %{name}-agent-lib = %{version}-%{release}
%description consoles
QMF console for monitoring various agents
+%package selinux
+Summary: SElinux support for Matahari
+Requires: %{name} = %{version}-%{release}
+Requires: policycoreutils
+Requires: selinux-policy-targeted
+BuildRequires: selinux-policy-devel
+
+%description selinux
+Configures Matahari to run in SELinux enabled environments.
+
%prep
%setup -q -n matahari-matahari-%{upstream_version}
@@ -183,8 +194,8 @@ make DESTDIR=%{buildroot} install
%{__install} matahari-broker.sysconf $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/matahari-broker
%{__ln_s} qpidd $RPM_BUILD_ROOT/%{_sbindir}/matahari-brokerd
-%{__install} -d -m0755 %{buildroot}%{_localstatedir}/lib/%{name}
-%{__install} -d -m0755 %{buildroot}%{_localstatedir}/run/%{name}
+%{__install} -d -m0755 $RPM_BUILD_ROOT/%{_localstatedir}/lib/%{name}
+%{__install} -d -m0755 $RPM_BUILD_ROOT/%{_localstatedir}/run/%{name}
%endif
%post -n matahari-lib -p /sbin/ldconfig
@@ -195,6 +206,15 @@ make DESTDIR=%{buildroot} install
# Can't use -p, gives: '/sbin/ldconfig: relative path `0' used to build cache' error
/sbin/ldconfig
+%post selinux
+semanage fcontext -a -t qpidd_var_lib_t '%{_localstatedir}/lib/%{name}(/.*)?' >/dev/null 2>&1 || :
+restorecon -R '%{_localstatedir}/lib/%{name}' || :
+
+%postun selinux
+if [ $1 -eq 0 ]; then
+ semanage fcontext -d -t qpidd_var_lib_t '%{_localstatedir}/lib/%{name}(/.*)?' >/dev/null 2>&1 || :
+fi
+
%if %{with qmf}
#== Host
@@ -406,6 +426,9 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%exclude %{_sysconfdir}/matahari-broker.conf
%endif
+%files selinux
+%defattr(-,root,root,-)
+
%files devel
%defattr(644, root, root, 755)
%doc AUTHORS COPYING
--
1.7.6
12 years, 9 months
[PATCH] - Make puppet a runtime dep and document in README
by Adam Stokes
- document puppet version 2.6.6 as a runtime dep.
- fix a spelling error
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
README.markdown | 5 ++++-
matahari.spec.in | 1 +
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/README.markdown b/README.markdown
index 0eb28e9..edd8ccd 100644
--- a/README.markdown
+++ b/README.markdown
@@ -15,12 +15,15 @@ Matahari has build dependencies on the following packages:
3. qmf
4. qmf-devel
5. qpid-cpp-client
-6. qpid-cpp-serer
+6. qpid-cpp-server
7. qpid-cpp-client-devel
8. qpid-cpp-server-devel
9. sigar
10. sigar-devel
+Requires : runtime dependencies
+Sysconfig Agent: puppet >= 2.6.6
+
These packages may be available in your distribution. In Fedora 14, they can
be installed via the yum command.
diff --git a/matahari.spec.in b/matahari.spec.in
index 0e57b1b..d03e469 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -134,6 +134,7 @@ Summary: QMF agent for post boot configuration services.
Group: Applications/System
Requires: %{name}-lib = %{version}-%{release}
Requires: %{name}-agent-lib = %{version}-%{release}
+Requires: puppet >= 2.6.6
%description sysconfig
QMF agent/console for providing post boot capabilities.
--
1.7.6
12 years, 9 months
Packaging Qpid
by russell@russellbryant.net
Greetings,
I recently started working on the Matahari project [1], which uses
QMF. One of the things we would like to do is get Matahari packaged
in more Linux distributions since it's only in Fedora right now. One
of the first hurdles I hit was that Qpid was also only packaged in
Fedora so far. Is getting Qpid into other distributions on anyone's
to-do list? Perhaps we could work together to get it done.
Thanks!
[1] http://www.matahariproject.org
--
Russell Bryant
12 years, 9 months
[PATCH] Implement getting hardware UUID on Linux.
by russell@russellbryant.net
From: Russell Bryant <rbryant(a)redhat.com>
This works by just parsing the output of dmidecode. This seemed like
the most reliable way to get this information.
Signed-off-by: Russell Bryant <rbryant(a)redhat.com>
---
matahari.spec.in | 1 +
src/CMakeLists.txt | 8 +++++
src/lib/host_linux.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 80 insertions(+), 1 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index 74fa2a6..f1ad227 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -31,6 +31,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: dbus
Requires: qmf > 0.7
Requires: pcre
+Requires: dmidecode
BuildRequires: cmake
BuildRequires: libudev-devel
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d9c77c6..2291399 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -96,6 +96,14 @@ if(CURL STREQUAL "CURL-NOTFOUND")
message(FATAL_ERROR "libcurl not found.")
endif(CURL STREQUAL "CURL-NOTFOUND")
+# dmidecode
+if(NOT WIN32)
+ find_program(DMIDECODE dmidecode)
+ if(DMIDECODE STREQUAL "DMIDECODE-NOTFOUND")
+ message(FATAL_ERROR "dmidecode not found")
+ endif(DMIDECODE STREQUAL "DMIDECODE-NOTFOUND")
+endif(NOT WIN32)
+
# Include QMF and DBus generation macros
include(MatahariMacros)
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 8d1aaef..a6999a3 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -164,7 +164,77 @@ host_os_identify(void)
char *host_os_machine_uuid(void)
{
- return strdup("not-implemented");
+ gchar *output = NULL;
+ gchar **lines = NULL;
+ unsigned int i;
+ static const gint max_lines = 256;
+ pcre *regex;
+ const char *pcre_error = NULL;
+ int pcre_error_offset = 0;
+ static const char regex_str[] = "\\s+UUID:\\s+(.*)";
+ GError *error = NULL;
+ gboolean res;
+ char *uuid = NULL;
+ gchar *argv[] = { "dmidecode", "-t", "system", NULL };
+
+ /*
+ * libsmbios doesn't expose the UUID. dmidecode already does a good job
+ * of getting it, but it doesn't have a library. Executing dmidecode
+ * doesn't seem pretty, but it should at least provide reliable info.
+ */
+
+ res = g_spawn_sync(NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL, &output, NULL, NULL, &error);
+
+ if (res == FALSE) {
+ mh_err("Failed to run dmidecode to get UUID: %s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ if (!output) {
+ mh_err("Got no output from dmidecode when trying to get UUID.\n");
+ return strdup("");
+ }
+
+ lines = g_strsplit(output, "\n", max_lines);
+
+ g_free(output);
+ output = NULL;
+
+ regex = pcre_compile(regex_str, 0, &pcre_error, &pcre_error_offset, NULL);
+ if (!regex) {
+ mh_err("Unable to compile regular expression '%s' at offset %d: %s",
+ regex_str, pcre_error_offset, pcre_error);
+ uuid = strdup("");
+ goto cleanup;
+ }
+
+ for (i = 0; lines && lines[i]; i++) {
+ int match;
+ int found[8] = { 0, };
+
+ match = pcre_exec(regex, NULL, lines[i], strlen(lines[i]),
+ 0, 0, found,
+ sizeof(found) / sizeof(found[0]));
+
+ if (match == 2) {
+ uuid = strdup(lines[i] + found[2]);
+ break;
+ }
+ }
+
+cleanup:
+ if (lines) {
+ g_strfreev(lines);
+ }
+
+ if (regex) {
+ pcre_free(regex);
+ }
+
+ return uuid;
}
char *host_os_custom_uuid(void)
--
1.7.6
12 years, 9 months
[PATCH] - Provide selinux subpackage for labeling /var/lib/matahari
by Adam Stokes
- set filetype to qpidd in selinux context
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari.spec | 26 ++++++++++++++++++++++++--
1 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/matahari.spec b/matahari.spec
index 300bcb8..ff952e8 100644
--- a/matahari.spec
+++ b/matahari.spec
@@ -172,6 +172,15 @@ Requires: %{name}-agent-lib = %{version}-%{release}
%description consoles
QMF console for monitoring various agents
+%package selinux
+Summary: SElinux support for Matahari
+Requires: %{name} = %{version}-%{release}
+Requires: policycoreutils
+Requires: selinux-policy-targeted
+BuildRequires: selinux-policy-devel
+
+%description selinux
+Configures Matahari to run in SELinux enabled environments.
%prep
%setup -q -n matahari-matahari-%{upstream_version}
@@ -193,8 +202,8 @@ make DESTDIR=%{buildroot} install
%{__install} matahari-broker.sysconf $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/matahari-broker
%{__ln_s} qpidd $RPM_BUILD_ROOT/%{_sbindir}/matahari-brokerd
-%{__install} -d -m0755 %{buildroot}%{_localstatedir}/lib/%{name}
-%{__install} -d -m0755 %{buildroot}%{_localstatedir}/run/%{name}
+%{__mkdir} -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/%{name}
+%{__mkdir} -p $RPM_BUILD_ROOT/%{_localstatedir}/run/%{name}
%endif
%post -n matahari-lib -p /sbin/ldconfig
@@ -205,6 +214,15 @@ make DESTDIR=%{buildroot} install
# Can't use -p, gives: '/sbin/ldconfig: relative path `0' used to build cache' error
/sbin/ldconfig
+%post selinux
+semanage fcontext -a -t qpidd_var_lib_t '%{_localstatedir}/lib/%{name}(/.*)?' >/dev/null 2>&1 || :
+restorecon -R '%{_localstatedir}/lib/%{name}' || :
+
+%postun selinux
+if [ $1 -eq 0 ]; then
+ semanage fcontext -d -t qpidd_var_lib_t '%{_localstatedir}/lib/%{name}(/.*)?' >/dev/null 2>&1 || :
+fi
+
%if %{with qmf}
#== Host
@@ -293,6 +311,7 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%files
%defattr(644, root, root, 755)
+%attr(755,root,root) %{_localstatedir}/lib/%{name}
%doc AUTHORS COPYING
%files agent-lib
@@ -422,6 +441,9 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%{_datadir}/polkit-1/actions/org.matahariproject.Resources.policy
%endif
+%files selinux
+%defattr(-,root,root,-)
+
%files devel
%defattr(644, root, root, 755)
%doc AUTHORS COPYING
--
1.7.6
12 years, 9 months
[PATCH] Add docs, make UUID lifetimes case insensitive.
by russell@russellbryant.net
From: Russell Bryant <rbryant(a)redhat.com>
I noticed that the UUID lifetimes were case sensitive. This seemed
overly restrictive so I changed it. I also added doxygen docs so that
the valid lifetimes were documented for the API.
Signed-off-by: Russell Bryant <rbryant(a)redhat.com>
---
src/include/matahari/host.h | 31 +++++++++++++++++++++++++++++--
src/lib/host.c | 12 ++++++------
2 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index f3bab48..ba540f7 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -29,9 +29,36 @@
#include <stdlib.h>
#include <sigar.h>
+/**
+ * Get a UUID for a host.
+ *
+ * \param[in] lifetime This function can retrieve a few different UUIDs from
+ * different sources that each have different lifetimes.
+ * The valid lifetimes are:
+ * - "Hardware", unique to the host itself
+ * - "Filesystem", valid for the lifetime of the OS
+ * - "Reboot", reset on each reboot of the host
+ * - "Agent", reset on each execution of the agent serving up this information.
+ * - "Custom", set by mh_host_set_uuid()
+ *
+ * \return the UUID
+ */
+extern const char *
+mh_host_get_uuid(const char *lifetime);
+
+/**
+ * Set a custom UUID for this host.
+ *
+ * \param[in] lifetime Which lifetime to set. The only valid input for
+ * this parameter right now is "Custom".
+ * \param[in] uuid the value of the UUID to set
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+extern int
+mh_host_set_uuid(const char *lifetime, const char *uuid);
-extern const char *mh_host_get_uuid(const char *lifetime);
-extern int mh_host_set_uuid(const char *lifetime, const char *uuid);
extern const char *mh_host_get_hostname(void);
extern const char *mh_host_get_operating_system(void);
diff --git a/src/lib/host.c b/src/lib/host.c
index a46f246..8a1416d 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -265,32 +265,32 @@ mh_host_get_uuid(const char *lifetime)
static const char *agent_uuid = NULL;
static const char *custom_uuid = NULL;
- if (lifetime == NULL || strcmp("Filesystem", lifetime) == 0) {
+ if (lifetime == NULL || strcasecmp("Filesystem", lifetime) == 0) {
if (immutable_uuid == NULL) {
immutable_uuid = mh_uuid();
}
uuid = immutable_uuid;
- } else if (strcmp("Hardware", lifetime) == 0) {
+ } else if (strcasecmp("Hardware", lifetime) == 0) {
if(hardware_uuid == NULL) {
hardware_uuid = host_os_machine_uuid();
}
uuid = hardware_uuid;
- } else if (strcmp("Reboot", lifetime) == 0) {
+ } else if (strcasecmp("Reboot", lifetime) == 0) {
if(reboot_uuid == NULL) {
reboot_uuid = host_os_reboot_uuid();
}
uuid = reboot_uuid;
- } else if (strcmp("Agent", lifetime) == 0) {
+ } else if (strcasecmp("Agent", lifetime) == 0) {
if(agent_uuid == NULL) {
agent_uuid = host_os_agent_uuid();
}
uuid = agent_uuid;
- } else if (strcmp("Custom", lifetime) == 0) {
+ } else if (strcasecmp("Custom", lifetime) == 0) {
if(custom_uuid == NULL) {
custom_uuid = host_os_custom_uuid();
}
@@ -310,7 +310,7 @@ mh_host_get_uuid(const char *lifetime)
int
mh_host_set_uuid(const char *lifetime, const char *uuid)
{
- if(lifetime && strcmp("Custom", lifetime) == 0) {
+ if(lifetime && strcasecmp("Custom", lifetime) == 0) {
return host_os_set_custom_uuid(uuid);
}
return G_FILE_ERROR_NOSYS;
--
1.7.6
12 years, 9 months
[PATCH] Host: rhbz714249 - Read CPU count from sigar correctly
by Zane Bitter
This patch reads the CPU Core count from sigar correctly. Unfortunately it
does not completely resolve the issue, as sigar is counting each thread in
a HyperThreaded core as a separate core. A change to sigar will be required
to fix that.
Also modified the help for the schema to indicate that cpu_count is, in
fact, returning the logical CPU count (i.e. the number of threads), not the
number of physical CPU sockets.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/host/schema.xml | 2 +-
src/lib/host.c | 19 ++++++++-----------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/host/schema.xml b/src/host/schema.xml
index 932f3a1..0ddccc9 100644
--- a/src/host/schema.xml
+++ b/src/host/schema.xml
@@ -24,7 +24,7 @@
<property name="memory" type="uint64" access="RO" desc="Amount of primary memory for host" unit="kb" />
<property name="swap" type="uint64" access="RO" desc="Amount of swap for host" unit="kb" />
- <property name="cpu_count" type="uint8" access="RO" desc="The number of physical CPUs." />
+ <property name="cpu_count" type="uint8" access="RO" desc="The number of logical CPUs." />
<property name="cpu_cores" type="uint8" access="RO" desc="The total number of processor cores." />
<property name="cpu_model" type="lstr" access="RO" desc="The processor(s) model description." />
<property name="cpu_flags" type="lstr" access="RO" desc="The processor(s) CPU flags." />
diff --git a/src/lib/host.c b/src/lib/host.c
index a46f246..4ad28a1 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -227,26 +227,23 @@ mh_host_get_swap_free(void)
static void
host_get_cpu_details(void)
{
- int lpc = 0;
- sigar_cpu_info_list_t cpus;
+ sigar_cpu_info_list_t procs;
if (cpuinfo.cpus) {
return;
}
init();
- sigar_cpu_info_list_get(host_init.sigar, &cpus);
+ sigar_cpu_info_list_get(host_init.sigar, &procs);
- cpuinfo.cpus = cpus.number;
- for (lpc = 0; lpc < cpus.number; lpc++) {
- sigar_cpu_info_t *cpu = (sigar_cpu_info_t *) cpus.data;
- if (cpuinfo.model == NULL) {
- cpuinfo.model = g_strdup(cpu->model);
- }
- cpuinfo.cores += cpu->total_cores;
+ cpuinfo.cpus = procs.number;
+ if (procs.number) {
+ sigar_cpu_info_t *proc = (sigar_cpu_info_t *)procs.data;
+ cpuinfo.model = g_strdup(proc->model);
+ cpuinfo.cores = proc->total_cores;
}
- sigar_cpu_info_list_destroy(host_init.sigar, &cpus);
+ sigar_cpu_info_list_destroy(host_init.sigar, &procs);
}
int
12 years, 9 months
[PATCH 1/2] - Make daemonized code accessible by agents and consoles
by Adam Stokes
- moved should_daemonize out of mh_agent location and into
our agent header for easier accessibility
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/include/matahari/agent.h | 3 +++
src/lib/mh_agent.cpp | 3 ++-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/include/matahari/agent.h b/src/include/matahari/agent.h
index b9be90e..a7f7182 100644
--- a/src/include/matahari/agent.h
+++ b/src/include/matahari/agent.h
@@ -65,6 +65,9 @@ typedef struct mainloop_qmf_s {
gpointer user_data);
} mainloop_qmf_t;
+extern int
+should_daemonize(int code, const char *name, const char *arg, void *userdata);
+
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));
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index f7dd768..44396d3 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -462,7 +462,8 @@ mh_add_option(int code, int has_arg, const char *name, const char *description,
return -1;
}
-static int should_daemonize(int code, const char *name, const char *arg, void *userdata)
+int
+should_daemonize(int code, const char *name, const char *arg, void *userdata)
{
#ifndef WIN32
if (daemon(0, 0) < 0) {
--
1.7.6
12 years, 9 months