---
src/host/matahari-host.cpp | 1 +
src/include/matahari/host.h | 1 +
src/lib/host.c | 7 ++++
src/lib/host_linux.c | 84 +++++++++++++++++++++++++++++++++++++++++-
src/lib/host_private.h | 1 +
src/lib/host_windows.c | 6 +++
6 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/src/host/matahari-host.cpp b/src/host/matahari-host.cpp
index 7df30ca..3ebb8de 100644
--- a/src/host/matahari-host.cpp
+++ b/src/host/matahari-host.cpp
@@ -83,6 +83,7 @@ HostAgent::setup(ManagementAgent* agent)
_management_object->set_cpu_count(host_get_cpu_count());
_management_object->set_cpu_cores(host_get_cpu_number_of_cores());
_management_object->set_cpu_model(host_get_cpu_model());
+ _management_object->set_cpu_flags(host_get_cpu_flags());
return 1;
}
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index 18c4681..174770e 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -29,6 +29,7 @@ extern const char *host_get_operating_system(void);
extern const char *host_get_architecture(void);
extern const char *host_get_cpu_model(void);
+extern const char *host_get_cpu_flags(void);
extern uint64_t host_get_memory(void);
extern uint64_t host_get_mem_free(void);
diff --git a/src/lib/host.c b/src/lib/host.c
index eb92d02..8b1aa0d 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -32,6 +32,7 @@
#include <glib.h>
#include <glib/gprintf.h>
#include "matahari/host.h"
+#include "matahari/logging.h"
#include "host_private.h"
#include <sigar.h>
@@ -124,6 +125,12 @@ host_get_cpu_model(void)
return cpuinfo.model;
}
+const char *
+host_get_cpu_flags(void)
+{
+ return host_os_get_cpu_flags();
+}
+
int
host_get_cpu_count(void)
{
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 274ef3f..9bb76ac 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -36,7 +36,7 @@
#include "host_private.h"
const char *
-host_os_get_uuid()
+host_os_get_uuid(void)
{
static char * uuid = NULL;
@@ -70,6 +70,86 @@ host_os_get_uuid()
return uuid;
}
+const char *
+host_os_get_cpu_flags(void)
+{
+ static char *flags = NULL;
+
+ size_t chunk = 512;
+ size_t read_chars = 0;
+ size_t data_length = 0;
+
+ char *buffer = NULL;
+ FILE *input = NULL;
+
+ if(flags) {
+ return flags;
+ }
+
+ 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);
+
+ if(data_length == 0) {
+ mh_warn("Could not read from /proc/cpuinfo");
+
+ } else {
+ const char *regexstr = "(.*\\S)\\s*:\\s*(\\S.*)";
+ int expected = 3;
+ int found[9];
+ const char* pcre_error;
+ int pcre_error_offset;
+ pcre* regex;
+ int offset = 0, lpc = 0, match = 0;
+
+ buffer[data_length] = '\0';
+ regex = pcre_compile(regexstr, 0, &pcre_error, &pcre_error_offset, NULL);
+ if(!regex) {
+ mh_err("Unable to compile regular expression '%s' at offset %d:
%s",
+ regexstr, pcre_error_offset, pcre_error);
+ goto done;
+ }
+
+ for(lpc = 0; lpc < data_length; lpc++) {
+
+ switch(buffer[lpc]) {
+ case '\n':
+ case '\0':
+ match = pcre_exec(regex, NULL, buffer+offset, lpc-offset,
+ 0, PCRE_NOTEMPTY, found, 9);
+
+ if(match == expected) {
+ char *name = malloc(2 + found[3] - found[2]);
+ snprintf(name, 1 + found[3] - found[2], "%s", buffer + offset + found[2]);
+
+ if (strcmp(name, "flags") == 0) {
+ flags = malloc(2 + found[5] - found[4]);
+ snprintf(flags, 1 + found[5] - found[4], "%s", buffer + offset +
found[4]);
+ free(name);
+ goto done;
+ }
+ free(name);
+ }
+ offset = lpc+1;
+ }
+ }
+ }
+
+ done:
+ fclose(input);
+ free(buffer);
+
+ if(flags == NULL) {
+ flags = strdup("unknown");
+ }
+
+ return flags;
+}
+
void
host_os_reboot(void)
{
@@ -82,4 +162,4 @@ host_os_shutdown(void)
reboot(LINUX_REBOOT_CMD_HALT);
}
-
\ No newline at end of file
+
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index 01c3bb5..f8ecc0c 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -39,6 +39,7 @@ extern const char *host_os_get_uuid(void);
extern const char *host_os_get_hostname(void);
extern const char *host_os_get_operating_system(void);
extern const char *host_os_get_architecture(void);
+extern const char *host_os_get_cpu_flags(void);
extern unsigned int host_os_get_memory(void);
extern unsigned int host_os_get_platform(void);
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index 22494bd..0be9f68 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -36,6 +36,12 @@ host_os_get_uuid(void)
return host_get_hostname();
}
+const char *
+host_os_get_cpu_flags(void)
+{
+ return "unknown";
+}
+
static void
get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp)
{
--
1.7.2.3