Another patch set - logging, host API, services API
by Andrew Beekhof
A new set of patches:
[PATCH 1/7] Services: Use a consistant naming scheme for the services API
[PATCH 2/7] Host: Simplify host_get_cpu_details() and fix the cpu count and total cores calculation
[PATCH 3/7] Host: Sanitize the host API
[PATCH 4/7] Core: Refactor the Agent base class to process QMF requests on the mainloop thread
[PATCH 5/7] Services: Recurring operations are out of scope for the next release
[PATCH 6/7] Services: API for OCF-style services is now functional
[PATCH 7/7] Core: Clean up the logging framwork
Please see individual patches for further details
-- Andrew
13 years, 4 months
Status of the Packaging API
by Andrew Beekhof
After a number of conversations, we have decided not to proceed with
the Packaging API/Agent at this time.
The primary reason for this is that there is no stable API for us to
use and implementing one is well outside the scope of this project.
We will re-evaluate the status of this agent at the point that the
PackageKit API becomes stable[1] and/or a C API is written for yum.
-- Andrew
[1] For over a year now, PackageKit has required
I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE to be defined in
order to use its API.
This sends very clear signals to developers and makes PackageKit
unacceptable for use in Matahari.
13 years, 4 months
Representing load
by Andrew Beekhof
Does anyone have any opinions on the difference between the following
two output formats?
load_average_1 0.020000
load_average_5 0.060000
load_average_15 0.020000
and
load {u'1': 0.02, u'5': 0.059999999999999998, u'15': 0.02}
I'm inclined to prefer the latter.
13 years, 5 months
Submitting patches/commits to matahari
by Ted Ross
What is the proper protocol for submitting patches to matahari? If I or
someone on my team has proposed fixes/enhancements, should we push a git
branch for review and cherry-picking by the matahari team? Email patches?
Thanks,
-Ted
13 years, 5 months
mingw host build error
by Adam Stokes
cd /home/akimbo/workspace/matahari/build-win/src && /usr/bin/i686-pc-mingw32-g++ -DMATAHARI_PORT=49000 -DMATAHARI_BROKER=\"127.0.0.1\" -DQPID_VERSION=" qpid-0" -Wall -I/home/akimbo/workspace/matahari/build-win/src -I/home/akimbo/workspace/matahari/src -I/home/akimbo/workspace/matahari/src/include -I/usr/i686-pc-mingw32/sys-root/mingw/include -I/usr/i686-pc-mingw32/sys-root/mingw/include/glib-2.0 -I/usr/i686-pc-mingw32/sys-root/mingw/lib/glib-2.0/include -o CMakeFiles/matahari-hostd.dir/host/matahari-host.cpp.obj -c /home/akimbo/workspace/matahari/src/host/matahari-host.cpp
/home/akimbo/workspace/matahari/src/host/matahari-host.cpp: In member function 'virtual int HostAgent::setup(qpid::management::ManagementAgent*)':
/home/akimbo/workspace/matahari/src/host/matahari-host.cpp:65: error: cannot allocate an object of abstract type 'qmf::org::matahariproject::Host'
/home/akimbo/workspace/matahari/build-win/src/qmf/org/matahariproject/Host.h:41: note: because the following virtual functions are pure within 'qmf::org::matahariproject::Host':
/usr/i686-pc-mingw32/sys-root/mingw/include/qpid/management/ManagementObject.h:176: note: virtual void qpid::management::ManagementObject::doMethod(std::string&, const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, qpid::types::Variant, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, qpid::types::Variant> > >&, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, qpid::types::Variant, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, qpid::types::Variant> > >&)
make[2]: *** [src/CMakeFiles/matahari-hostd.dir/host/matahari-host.cpp.obj] Error 1
make[2]: Leaving directory `/home/akimbo/workspace/matahari/build-win'
make[1]: *** [src/CMakeFiles/matahari-hostd.dir/all] Error 2
make[1]: Leaving directory `/home/akimbo/workspace/matahari/build-win'
make: *** [all] Error 2
There are override methods for things like doMethod that aren't pure but when compiling with mingw it fails. Compiling for linux works as expected. This is using qpid 0.8 and matahari trunk
to reproduce:
matahari> make setup-win
matahari/build-win>make
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 5 months
[PATCH] Update host agent
by Adam Stokes
- Include sigar into the agent to simply routines and have a cross platform library for capturing data
- Trimmed a lot of OS specific method calls that are now replaced by a global routine for sigar supported platforms.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 10cb956..480e4d7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -224,7 +224,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/host/matahari-host.cpp b/src/host/matahari-host.cpp
index 5214c2a..147fb25 100644
--- a/src/host/matahari-host.cpp
+++ b/src/host/matahari-host.cpp
@@ -1,4 +1,4 @@
-/* hostagent.cpp - Copyright (C) 2009 Red Hat, Inc.
+/* matahari-host.cpp - Copyright (C) 2009 Red Hat, Inc.
* Written by Arjun Roy <arroy(a)redhat.com>
*
*
@@ -25,6 +25,7 @@
#include "matahari/mh_agent.h"
#include "qmf/org/matahariproject/Host.h"
#include "qmf/org/matahariproject/EventHeartbeat.h"
+#include <sigar.h>
extern "C" {
#include "matahari/host.h"
@@ -95,8 +96,9 @@ HostAgent::ManagementMethod(uint32_t method, Args& arguments, string& text)
void
HostAgent::heartbeat()
{
- double one, five, fifteen;
uint64_t timestamp = 0L, now = 0L;
+ sigar_loadavg_t avg;
+ sigar_proc_stat_t procs;
_heartbeat_sequence++;
@@ -110,8 +112,17 @@ HostAgent::heartbeat()
_management_object->set_last_updated_seq(_heartbeat_sequence);
// update the load averages
- host_get_load_averages(&one, &five, &fifteen);
- _management_object->set_load_average_1(one);
- _management_object->set_load_average_5(five);
- _management_object->set_load_average_15(fifteen);
+ host_get_load_averages(&avg);
+ host_get_processes(&procs);
+ _management_object->set_load_average_1(avg.loadavg[0]);
+ _management_object->set_load_average_5(avg.loadavg[1]);
+ _management_object->set_load_average_15(avg.loadavg[2]);
+ _management_object->set_proc_total(procs.total);
+ _management_object->set_proc_sleeping(procs.sleeping);
+ _management_object->set_proc_running(procs.running);
+ _management_object->set_proc_zombie(procs.zombie);
+ _management_object->set_proc_stopped(procs.stopped);
+ _management_object->set_proc_idle(procs.idle);
+ _management_object->set_swap_free(host_get_swap_free());
+ _management_object->set_mem_free(host_get_mem_free());
}
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index d0ad98c..6098e15 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -19,6 +19,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <stdint.h>
+#include <stdlib.h>
+#include <sigar.h>
+
extern const char *host_get_uuid(void);
extern const char *host_get_hostname(void);
extern const char *host_get_operating_system(void);
@@ -26,17 +30,22 @@ extern const char *host_get_operating_system(void);
extern const char *host_get_architecture(void);
extern const char *host_get_cpu_model(void);
-extern unsigned int host_get_memory(void);
-extern unsigned int host_get_cpu_count(void);
-extern unsigned int host_get_cpu_number_of_cores(void);
+extern uint64_t host_get_memory(void);
+extern uint64_t host_get_mem_free(void);
+extern uint64_t host_get_swap(void);
+extern uint64_t host_get_swap_free(void);
+
+extern int host_get_cpu_count(void);
+extern int host_get_cpu_number_of_cores(void);
-extern unsigned int host_get_platform(void);
-extern unsigned int host_get_cpu_wordsize(void);
+extern uint32_t host_get_platform(void);
+extern int host_get_cpu_wordsize(void);
extern void host_identify(const unsigned int iterations);
extern void host_reboot(void);
extern void host_shutdown(void);
-extern void host_get_load_averages(double *one, double *five, double *fifteen);
+extern void host_get_load_averages(sigar_loadavg_t *avg);
+extern void host_get_processes(sigar_proc_stat_t *procs);
#endif // __HOST_H
diff --git a/src/lib/host.c b/src/lib/host.c
index f4d1bb6..b42c6a6 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -26,10 +26,24 @@
#endif
#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <glib.h>
+#include <glib/gprintf.h>
#include "matahari/host.h"
#include "host_private.h"
-cpuinfo_t cpuinfo = { 0, 0, 0, 0, 0 };
+#include <sigar.h>
+#include <sigar_private.h>
+#include <sigar_format.h>
+
+#define SIGAR \
+ sigar_t *sigar; \
+ sigar_open(&sigar)
+
+#define SIGAR_CLOSE \
+ sigar_close(sigar)
const char *
host_get_uuid(void)
@@ -40,31 +54,56 @@ host_get_uuid(void)
const char *
host_get_hostname(void)
{
- return host_os_get_hostname();
+ SIGAR;
+ sigar_net_info_t netinfo;
+ static gchar *host_name;
+
+ if(host_name == NULL) {
+ sigar_net_info_get(sigar, &netinfo);
+ host_name = g_strdup(netinfo.host_name);
+ }
+ SIGAR_CLOSE;
+ return host_name;
}
const char *
host_get_operating_system(void)
{
- return host_os_get_operating_system();
+ SIGAR;
+ sigar_sys_info_t sysinfo;
+ static gchar *operating_system;
+
+ if(operating_system == NULL) {
+ sigar_sys_info_get(sigar, &sysinfo);
+ operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name, sysinfo.version);
+ }
+ SIGAR_CLOSE;
+ return operating_system;
}
-unsigned int
+guint32
host_get_platform(void)
{
- static unsigned int wordsize = 0;
+ static guint32 platform;
- if(wordsize == 0) {
- wordsize = sizeof(void *) * CHAR_BIT;
- }
+ platform = CHAR_BIT * sizeof(size_t);
- return wordsize;
+ return platform;
}
const char *
host_get_architecture(void)
{
- return host_os_get_architecture();
+ SIGAR;
+ sigar_sys_info_t sysinfo;
+ static gchar *arch;
+
+ if(arch == NULL) {
+ sigar_sys_info_get(sigar, &sysinfo);
+ arch = g_strdup(sysinfo.arch);
+ }
+ SIGAR_CLOSE;
+ return arch;
}
void
@@ -80,49 +119,123 @@ host_shutdown(void)
}
-unsigned int
-host_get_cpu_wordsize()
+int
+host_get_cpu_wordsize(void)
{
- static unsigned int wordsize = 0;
-
- if(wordsize == 0) {
- host_os_get_cpu_details();
- return cpuinfo.wordsize;
- }
-
+ gint wordsize = 0;
return wordsize;
}
const char*
-host_get_cpu_model()
+host_get_cpu_model(void)
{
- host_os_get_cpu_details();
- return cpuinfo.model;
+ SIGAR;
+ sigar_cpu_info_list_t cpus;
+ sigar_cpu_info_t *cpu;
+ static gchar *model;
+
+ if(model == NULL) {
+ sigar_cpu_info_list_get(sigar, &cpus);
+ cpu = (sigar_cpu_info_t *) cpus.data;
+ model = g_strdup(cpu->model);
+ sigar_cpu_info_list_destroy(sigar, &cpus);
+ }
+ SIGAR_CLOSE;
+ return model;
}
-unsigned int
-host_get_cpu_count()
+int
+host_get_cpu_count(void)
{
- host_os_get_cpu_details();
- return cpuinfo.cpus;
+ SIGAR;
+ sigar_cpu_info_list_t cpus;
+ sigar_cpu_info_t *cpu;
+
+ sigar_cpu_info_list_get(sigar, &cpus);
+ cpu = (sigar_cpu_info_t *) cpus.data;
+ sigar_cpu_info_list_destroy(sigar, &cpus);
+ SIGAR_CLOSE;
+ return cpu->total_cores;
}
-unsigned int
-host_get_cpu_number_of_cores()
+int
+host_get_cpu_number_of_cores(void)
+{
+ SIGAR;
+ sigar_cpu_info_list_t cpus;
+ sigar_cpu_info_t *cpu;
+
+ sigar_cpu_info_list_get(sigar, &cpus);
+ cpu = (sigar_cpu_info_t *) cpus.data;
+ sigar_cpu_info_list_destroy(sigar, &cpus);
+ SIGAR_CLOSE;
+ return cpu->cores_per_socket;
+}
+
+void
+host_get_load_averages(sigar_loadavg_t *avg)
{
- host_os_get_cpu_details();
- return cpuinfo.cores;
+ SIGAR;
+ sigar_loadavg_get(sigar, avg);
+ SIGAR_CLOSE;
}
void
-host_get_load_averages(double *one, double *five, double *fifteen)
+host_get_processes(sigar_proc_stat_t *procs)
{
- host_os_get_load_averages(one, five, fifteen);
+ SIGAR;
+ sigar_proc_stat_get(sigar, procs);
+ SIGAR_CLOSE;
}
-unsigned int
+uint64_t
host_get_memory(void)
{
- return host_os_get_memory();
+ sigar_mem_t mem;
+ uint64_t total;
+ SIGAR;
+
+ sigar_mem_get(sigar, &mem);
+ total = mem.total / 1024;
+ SIGAR_CLOSE;
+ return total;
}
+uint64_t
+host_get_mem_free(void)
+{
+ SIGAR;
+ sigar_mem_t mem;
+ uint64_t free;
+
+ sigar_mem_get(sigar, &mem);
+ free = mem.free / 1024;
+ SIGAR_CLOSE;
+ return free;
+}
+
+uint64_t
+host_get_swap(void)
+{
+ SIGAR;
+ sigar_swap_t swap;
+ uint64_t total;
+
+ sigar_swap_get(sigar, &swap);
+ total = swap.total / 1024;
+ SIGAR_CLOSE;
+ return total;
+}
+
+uint64_t
+host_get_swap_free(void)
+{
+ SIGAR;
+ sigar_swap_t swap;
+ uint64_t free;
+
+ sigar_swap_get(sigar, &swap);
+ free = swap.free / 1024;
+ SIGAR_CLOSE;
+ return free;
+}
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 42e4270..0d3dd80 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -36,11 +36,11 @@
#include "host_private.h"
const char *
-host_os_get_uuid()
+host_os_get_uuid(void)
{
- static char * uuid = NULL;
+ static char *uuid;
- 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;
@@ -66,106 +66,9 @@ host_os_get_uuid()
fclose(input);
free(buffer);
}
-
return uuid;
}
-const char *
-host_os_get_hostname(void)
-{
- static char *hostname = NULL;
- if(hostname == NULL) {
- struct utsname details;
-
- if(!uname(&details)) {
- hostname = strdup(details.nodename);
- }
- }
-
- return hostname;
-}
-
-const char *
-host_os_get_operating_system(void)
-{
- static char *operating_system = NULL;
-
- if(operating_system == NULL) {
- struct utsname details;
- if(!uname(&details)) {
- int len = 4 + strlen(details.sysname) + strlen(details.release);
- operating_system = malloc(len);
- sprintf(operating_system, "%s (%s)", details.sysname, details.release);
- }
- }
-
- return operating_system;
-}
-
-const char *
-host_os_get_architecture(void)
-{
- static char *architecture;
-
- if(architecture == NULL) {
- struct utsname details;
-
- if(!uname(&details)) {
- architecture = strdup(details.machine);
- }
- }
-
- return architecture;
-}
-
-/* TODO: Replace with sigar calls */
-
-unsigned int
-host_os_get_memory(void)
-{
- static unsigned int memory = 0;
-
- if(!memory) {
- struct sysinfo sysinf;
- if(!sysinfo(&sysinf)) {
- memory = sysinf.totalram / 1024L;
- }
- }
-
- return memory;
-}
-
-/* TODO: Replace with sigar calls */
-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;
- FILE *input = NULL;
-
- *one = 0.0;
- *five = 0.0;
- *fifteen = 0.0;
-
- 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);
-
- if(data_length != 0) {
- sscanf(buffer, "%f %f %f", one, five, fifteen);
- }
- fclose(input);
- free(buffer);
-}
-
-
void
host_os_reboot(void)
{
@@ -177,91 +80,3 @@ host_os_shutdown(void)
{
reboot(LINUX_REBOOT_CMD_HALT);
}
-
-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);
-
- 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.");
- goto done;
- }
-
- for(lpc = 0; lpc < data_length; lpc++) {
- switch(offset) {
- case '\n':
- case '\0':
- match = pcre_exec(regex, NULL, buffer+offset, lpc-offset,
- 0, PCRE_NOTEMPTY, found, 9);
-
- if(match == expected) {
- char *name = NULL;
- char *value = NULL;
-
- name = malloc(1 + found[3] - found[2]);
- snprintf(name, found[3] - found[2], "%s", buffer + offset + found[2]);
-
- value = malloc(1 + found[5] - found[4]);
- snprintf(value, found[5] - found[4], "%s", buffer + offset + found[4]);
-
- if (name == "processor") {
- cpuinfo.cpus++;
-
- } else if (name == "cpu cores") {
- cpuinfo.cores += atoi(value);
-
- } else if (name == "model name") {
- cpuinfo.model = strdup(value);
-
- } else if (name == "flags") {
- /* if the cpuflags contain "lm" then it's a 64 bit CPU
- * http://www.brandonhutchinson.com/Understanding_proc_cpuinfo.html
- */
- if(strstr(value, " lm ")) {
- cpuinfo.wordsize = 64;
- } else {
- cpuinfo.wordsize = 32;
- }
- }
- free(value);
- free(name);
- }
- offset = lpc+1;
- }
- }
- }
- done:
- fclose(input);
- free(buffer);
-}
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index ad28963..c8ce9f1 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -16,17 +16,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-typedef struct cpuinfo_
-{
- int initialized;
- char *model;
- unsigned int cpus;
- unsigned int cores;
- unsigned int wordsize;
-} cpuinfo_t;
-
-extern cpuinfo_t cpuinfo;
-
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);
@@ -37,6 +26,3 @@ extern unsigned int host_os_get_platform(void);
extern void host_os_reboot(void);
extern void host_os_shutdown(void);
-extern void host_os_get_load_averages(double *one, double *five, double *fifteen);
-
-extern void host_os_get_cpu_details(void);
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index 7720eec..ca1373d 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -1,4 +1,4 @@
-/* host.cpp - Copyright (C) 2010 Red Hat, Inc.
+/* host_windows.c - Copyright (C) 2010 Red Hat, Inc.
* Written by Darryl L. Pierce <dpierce(a)redhat.com>
*
* This program is free software; you can redistribute it and/or
@@ -30,222 +30,45 @@
#include "matahari/host.h"
#include "host_private.h"
-#ifndef MSVC
-
-// Items missing from winnt.h from mingw32
-// http://msdn.microsoft.com/en-us/library/ms683194(VS.85).aspx
-
-typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
- RelationProcessorCore,
- RelationNumaNode,
- RelationCache,
- RelationProcessorPackage,
- RelationGroup,
- RelationAll = 0xffff
-} LOGICAL_PROCESSOR_RELATIONSHIP;
-
-typedef enum _PROCESSOR_CACHE_TYPE {
- CacheUnified,
- CacheInstruction,
- CacheData,
- CacheTrace
-} PROCESSOR_CACHE_TYPE;
-
-typedef struct _CACHE_DESCRIPTOR {
- BYTE Level;
- BYTE Associativity;
- WORD LineSize;
- DWORD Size;
- PROCESSOR_CACHE_TYPE Type;
-} CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
-
-typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
- ULONG_PTR ProcessorMask;
- LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
- union {
- struct {
- BYTE Flags;
- } ProcessorCore;
- struct {
- DWORD NodeNumber;
- } NumaNode;
- CACHE_DESCRIPTOR Cache;
- ULONGLONG Reserved[2];
- } ;
-} SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
-
-#endif
-typedef BOOL (WINAPI* LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
-
const char *
host_os_get_uuid(void)
{
- return host_os_get_hostname();
-}
-
-const char *
-host_os_get_hostname(void)
-{
- static char *hostname = NULL;
-
- if(hostname == NULL) {
- WORD verreq;
- WSADATA wsadata;
- hostname = malloc(512);
-
- verreq = MAKEWORD(2, 2);
- if(!WSAStartup(verreq, &wsadata)) {
- gethostname(hostname, 511);
- WSACleanup();
- }
- }
-
- return hostname;
-}
-
-const char *
-host_os_get_operating_system(void)
-{
- static char *operating_system = NULL;
-
- if(operating_system == NULL) {
- HINSTANCE dll = LoadLibrary(TEXT("kernel32"));
-
- if(dll != NULL) {
- typedef DWORD(WINAPI *version_function)(void);
- version_function proc;
- DWORD version;
-
- proc = (version_function)GetProcAddress(dll,"GetVersion");
- if(proc) {
- version = (*proc)();
-
- DWORD major, minor, build;
-
- major = (DWORD)(LOBYTE(LOWORD(version)));
- minor = (DWORD)(HIBYTE(LOWORD(version)));
- build = (DWORD)(HIWORD(version));
-
- operating_system = malloc(512);
- snprintf(operating_system, 511, "Windows (%lu.%lu.%lu)",
- (unsigned long)major, (unsigned long)minor, (unsigned long)build);
- }
- }
- }
-
- return operating_system;
-}
-
-const char *
-host_os_get_architecture()
-{
- static char *architecture = NULL;
-
- if(architecture == NULL) {
- SYSTEM_INFO system_info;
- system_info.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;
- GetSystemInfo(&system_info);
-
- switch(system_info.wProcessorArchitecture) {
- case PROCESSOR_ARCHITECTURE_AMD64:
- architecture = "x86 (AMD)";
- break;
- case PROCESSOR_ARCHITECTURE_IA64:
- architecture = "ia64";
- break;
- case PROCESSOR_ARCHITECTURE_INTEL:
- architecture = "x86 (Intel)";
- break;
- case PROCESSOR_ARCHITECTURE_UNKNOWN:
- architecture = "Unknown";
- break;
- }
- }
-
- return architecture;
+ return host_get_hostname();
}
-/* TODO: Replace with sigar calls */
-unsigned int
-host_os_get_memory()
+static void
+get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp)
{
- static unsigned int memory = 0;
+ OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
+ LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
+ &tkp.Privileges[0].Luid);
- if(!memory) {
- MEMORYSTATUS status;
+ tkp.PrivilegeCount = 1;
+ tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- GlobalMemoryStatus(&status);
- memory = status.dwTotalPhys / 1024L;
- }
- return memory;
+ AdjustTokenPrivileges(token, FALSE, &tkp, 0,
+ (PTOKEN_PRIVILEGES)NULL, 0);
}
-/* TODO: Replace with sigar calls */
void
-host_os_get_load_averages(double *one, double *five, double *fifteen)
+host_os_reboot(void)
{
- *one = 0.0;
- *five = 0.0;
- *fifteen = 0.0;
-}
-
-void
-host_os_reboot()
-{
-}
+ HANDLE token;
+ TOKEN_PRIVILEGES tkp;
-void
-host_os_shutdown()
-{
+ get_token_priv(token, tkp);
+ ExitWindowsEx(EWX_REBOOT | EWX_FORCE,
+ SHTDN_REASON_FLAG_PLANNED);
}
void
-host_os_get_cpu_details(void)
+host_os_shutdown(void)
{
- LPFN_GLPI proc;
- DWORD ret_length;
- PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer, ptr;
-
- if(cpuinfo.initialized) return;
- cpuinfo.initialized = 1;
-
- ptr = NULL;
- buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(256);
- proc = (LPFN_GLPI) GetProcAddress(GetModuleHandle(TEXT("kernel32")),
- "GetLogicalProcessorInformation");
- if(proc) {
- DWORD rc;
- retry:
- rc = proc(buffer, &ret_length);
- if(rc == FALSE) {
- if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
- buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)realloc(buffer, ret_length + 1);
- goto retry;
- }
-
- mh_err("Call to 'GetLogicalProcessorInformation' failed (%lu, %lu, %lu)",
- rc, GetLastError(), ret_length);
+ HANDLE token;
+ TOKEN_PRIVILEGES tkp;
- } else {
- ptr = buffer;
- DWORD offset = 0;
-
- while(offset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= ret_length) {
- switch(ptr->Relationship) {
- case RelationProcessorCore: cpuinfo.cores++; break;
- case RelationProcessorPackage: cpuinfo.cpus++; break;
- default:
- break;
- }
- offset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
- ptr++;
- }
- }
-
- // get the processor model
- cpuinfo.model = strdup("unknown");
- }
-
- free(buffer);
- buffer = NULL;
-}
+ get_token_priv(token, tkp);
+ ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
+ SHTDN_REASON_FLAG_PLANNED);
+}
\ No newline at end of file
--
1.7.2.3
13 years, 5 months
[PATCH] Fixed typo in CMakeLists.txt
by Roman Rakus
Signed-off-by: Roman Rakus <rrakus(a)redhat.com>
---
src/CMakeLists.txt | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2bb0d75..5200abc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -140,7 +140,7 @@ find_library(SIGAR sigar)
if(NOT_SIGAR)
message("SIGAR library not found.")
set(SIGAR "")
-endif(NOT SIGAR)
+endif(NOT_SIGAR)
string(REGEX REPLACE "\\." "" QPID_VERSION ${QPID_VERSION})
--
1.7.2.3
13 years, 5 months
[PATCH] separate finding qpid stuff to FindQPID cmake module
by Jaroslav Reznik
---
src/CMakeLists.txt | 66 ++-------------------
src/cmake/modules/FindQPID.cmake | 122 ++++++++++++++++++++++++++++++++++++++
2 files changed, 128 insertions(+), 60 deletions(-)
create mode 100644 src/cmake/modules/FindQPID.cmake
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9664781..0c2a60c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,6 +13,8 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} )
+
# set service name var's
set(M_HOST "matahari-hostd")
set(M_NET "matahari-netd")
@@ -137,65 +141,7 @@ endforeach(lib ${simple_libs})
## qpid
-if(MSVC)
- find_file(QPIDD qpidd.exe "${QPID_PATH}")
- find_path(QPID_INCLUDE Address.h "${QPID_PATH}")
- find_library(QMFCONSOLE qmfconsole.lib "${QPID_PATH}")
- find_library(QPIDCLIENT qpidclient.lib "${QPID_PATH}")
- find_library(QPIDCOMMON qpidcommon.lib "${QPID_PATH}")
- find_library(QPIDCOMMON qpidtypes.lib "${QPID_PATH}")
-
- # Figure out some way to do this automatically on windows
- # Perhaps with the strings command
- set(QPID_VERSION_LONG "qpidd (qpidc) version 0.6")
-
-else(MSVC)
- find_library(QMF qmf)
- find_library(QPIDCLIENT qpidclient)
- find_library(QPIDCOMMON qpidcommon)
- find_library(QPIDTYPES qpidtypes)
-
- # Figure out the qpid version
- if(WIN32)
- find_file(QPIDD qpidd.exe)
- execute_process(COMMAND strings ${QPIDD} OUTPUT_VARIABLE QPID_VERSION_LONG)
- string(REGEX REPLACE ".*BUILD/qpid" " qpid" QPID_VERSION_LONG ${QPID_VERSION_LONG})
- string(REGEX REPLACE "/cpp.*" "" QPID_VERSION_LONG ${QPID_VERSION_LONG})
-
- #version: qpid-cpp-0.6.895736
- string(REGEX REPLACE "qpid-cpp-" "" QPID_VERSION ${QPID_VERSION_LONG})
- string(REGEX REPLACE ".[0-9]*$" "" QPID_VERSION ${QPID_VERSION})
-
- else(WIN32)
- find_file(QPIDD qpidd)
- execute_process(COMMAND ${QPIDD} --version OUTPUT_VARIABLE QPID_VERSION_LONG)
- string(STRIP QPID_VERSION_LONG ${QPID_VERSION_LONG})
- string(REGEX REPLACE "d \\(.*\\)" "" QPID_VERSION_LONG ${QPID_VERSION_LONG})
- string(REGEX REPLACE ".* " "" QPID_VERSION ${QPID_VERSION_LONG})
- endif(WIN32)
-endif(MSVC)
-
-if(NOT QMF)
- message(FATAL_ERROR "QMF library not found.")
-endif(NOT QMF)
-
-if(NOT QPIDCLIENT)
- message(FATAL_ERROR "QPIDCLIENT library not found.")
-endif(NOT QPIDCLIENT)
-
-if(NOT QPIDCOMMON)
- message(FATAL_ERROR "QPIDCOMMON library not found.")
-endif(NOT QPIDCOMMON)
-
-if(NOT QPIDTYPES)
- message("QPIDTYPES library not found.")
- set(QPIDTYPES "")
-endif(NOT QPIDTYPES)
-
-find_program(QMFGEN qmf-gen)
-if(QMFGEN-NOTFOUND)
- message(FATAL_ERROR Missing QMF schema processor.)
-endif(QMFGEN-NOTFOUND)
+find_package(QPID REQUIRED)
string(REGEX REPLACE "\\." "" QPID_VERSION ${QPID_VERSION})
@@ -228,7 +174,7 @@ endif (regen_schema)
# Add QF libraries
foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} ${QPIDCOMMON} ${QPIDCLIENT} ${QPIDTYPES} ${QMF})
+ target_link_libraries(${daemon} ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY} ${QMF_LIBRARY})
endforeach(daemon ${DAEMONS})
# Install targets
diff --git a/src/cmake/modules/FindQPID.cmake b/src/cmake/modules/FindQPID.cmake
new file mode 100644
index 0000000..86b6906
--- /dev/null
+++ b/src/cmake/modules/FindQPID.cmake
@@ -0,0 +1,122 @@
+# FindQpid.cmake
+
+if(MSVC)
+ find_file(QPIDD qpidd.exe "${QPID_PATH}")
+ find_path(QPID_INCLUDE Address.h "${QPID_PATH}")
+ find_library(QMFCONSOLE_LIBRARY qmfconsole.lib "${QPID_PATH}")
+ find_library(QPIDCLIENT_LIBRARY qpidclient.lib "${QPID_PATH}")
+ find_library(QPIDCOMMON_LIBRARY qpidcommon.lib "${QPID_PATH}")
+ find_library(QPIDCOMMON_LIBRARY qpidtypes.lib "${QPID_PATH}")
+
+ # Figure out some way to do this automatically on windows
+ # Perhaps with the strings command
+ set(QPID_VERSION_LONG "qpidd (qpidc) version 0.6")
+
+else(MSVC)
+ find_library(QMF_LIBRARY qmf)
+ find_library(QPIDCLIENT_LIBRARY qpidclient)
+ find_library(QPIDCOMMON_LIBRARY qpidcommon)
+
+# is qpidtypes library still available?
+# find_library(QPIDTYPES_LIBRARY qpidtypes)
+
+ # Check if we found all libraries
+ if(QMF_LIBRARY)
+ set(QMF_FOUND true)
+ endif(QMF_LIBRARY)
+
+ if(QPIDCLIENT_LIBRARY)
+ set(QPIDCLIENT_FOUND true)
+ endif(QPIDCLIENT_LIBRARY)
+
+ if(QPIDCOMMON_LIBRARY)
+ set(QPIDCOMMON_FOUND true)
+ endif(QPIDCOMMON_LIBRARY)
+
+# if(QPIDTYPES_LIBRARY)
+# set(QPIDTYPES_FOUND true)
+# endif(QPIDTYPES_LIBRARY)
+
+ # Handle found/not found libraries
+ if(QMF_FOUND)
+ if(NOT QPID_FIND_QUIETLY)
+ message(STATUS "Found QMF: ${QMF_LIBRARY}")
+ endif(NOT QPID_FIND_QUIETLY)
+ else(QMF_FOUND)
+ if(QPID_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find QMF")
+ endif(QPID_FIND_REQUIRED)
+ endif(QMF_FOUND)
+
+ if(QPIDCLIENT_FOUND)
+ if(NOT QPID_FIND_QUIETLY)
+ message(STATUS "Found QPIDCLIENT: ${QPIDCLIENT_LIBRARY}")
+ endif(NOT QPID_FIND_QUIETLY)
+ else(QPIDCLIENT_FOUND)
+ if(QPID_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find QPIDCLIENT")
+ endif(QPID_FIND_REQUIRED)
+ endif(QPIDCLIENT_FOUND)
+
+ if(QPIDCOMMON_FOUND)
+ if(NOT QPID_FIND_QUIETLY)
+ message(STATUS "Found QPIDCOMMON: ${QPIDCOMMON_LIBRARY}")
+ endif(NOT QPID_FIND_QUIETLY)
+ else(QPIDCOMMON_FOUND)
+ if(QPID_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find QPIDCOMMON")
+ endif(QPID_FIND_REQUIRED)
+ endif(QPIDCOMMON_FOUND)
+
+# if(QPIDTYPES_FOUND)
+# if(NOT QPID_FIND_QUIETLY)
+# message(STATUS "Found QPIDTYPES: ${QPIDTYPES_LIBRARY}")
+# endif(NOT QPID_FIND_QUIETLY)
+# else(QPIDTYPES_FOUND)
+# if(QPID_FIND_REQUIRED)
+# message(FATAL_ERROR "Could not find QPIDTYPES")
+# endif(QPID_FIND_REQUIRED)
+# endif(QPIDTYPES_FOUND)
+
+ # Figure out the qpid version
+ if(WIN32)
+ find_file(QPIDD qpidd.exe)
+ if(QPIDD)
+ execute_process(COMMAND strings ${QPIDD} OUTPUT_VARIABLE QPID_VERSION_LONG)
+ string(REGEX REPLACE ".*BUILD/qpid" " qpid" QPID_VERSION_LONG ${QPID_VERSION_LONG})
+ string(REGEX REPLACE "/cpp.*" "" QPID_VERSION_LONG ${QPID_VERSION_LONG})
+
+ #version: qpid-cpp-0.6.895736
+ string(REGEX REPLACE "qpid-cpp-" "" QPID_VERSION ${QPID_VERSION_LONG})
+ string(REGEX REPLACE ".[0-9]*$" "" QPID_VERSION ${QPID_VERSION})
+ else(QPIDD)
+ # guess version? uknown?
+ endif(QPIDD)
+
+ else(WIN32)
+ find_file(QPIDD qpidd)
+ if(QPIDD)
+ execute_process(COMMAND ${QPIDD} --version OUTPUT_VARIABLE QPID_VERSION_LONG)
+ string(STRIP QPID_VERSION_LONG ${QPID_VERSION_LONG})
+ string(REGEX REPLACE "d \\(.*\\)" "" QPID_VERSION_LONG ${QPID_VERSION_LONG})
+ string(REGEX REPLACE ".* " "" QPID_VERSION ${QPID_VERSION_LONG})
+ else(QPIDD)
+ # guess version? uknown?
+ endif(QPIDD)
+ endif(WIN32)
+
+ # Look for schema processor
+ find_program(QMFGEN qmf-gen)
+ if(QMFGEN)
+ set(QMFGEN_FOUND true)
+
+ if(NOT QPID_FIND_QUIETLY)
+ message(STATUS "Found QMF schema processor: ${QMFGEN}")
+ endif(NOT QPID_FIND_QUIETLY)
+ else(QMFGEN)
+ if(QPID_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find QMF schema processor")
+ endif(QPID_FIND_REQUIRED)
+ endif(QMFGEN)
+
+endif(MSVC)
--
1.7.3.2
13 years, 5 months
host schema method: identify
by Adam Stokes
Should we keep this identify method around I don't really see a benefit:
=== identify ===
Tells the host to identify itself, usually by beeping it's PC speaker.
Inputs::
The number of times to beep (integer: 1 <= beeps <= 100)
Outputs::
None.
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 5 months