[PATCH] - review of win32 netcf port
by Adam Stokes
I know this is the matahari list but I was asked to post patch here for technical review.
Any suggestions highly appreciated
Thanks,
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 8 months
[PATCH] autoconf updates for win32 conditionals
by Adam Stokes
Does some simple checks for build host and includes libraries accordingly
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 8 months
[PATCH] Matahari am conditional checks for win32 moved some includes around due to platform specifics host.cpp had a bug where attempting to operator overload an integer was failing
by Adam Stokes
---
configure.ac | 29 +++++++++++++++++++++++++----
src/host.cpp | 25 ++++++++++++-------------
2 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/configure.ac b/configure.ac
index 1dfdd80..451d0b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,17 +32,38 @@ if test x"$HASQMFGEN" = "x"; then
fi
dnl ---------------------------------------------------------------------
+dnl Test for WIN32
+dnl ---------------------------------------------------------------------
+WIN32="no"
+case "$host" in
+ *-*-mingw*)
+ WIN32="yes"
+ MINGW_EXTRA_LDFLAGS="-no-undefined"
+ ;;
+ *)
+ ;;
+esac
+AM_CONDITIONAL(WIN32, test "${WIN32}" = "yes")
+AC_SUBST([WIN32])
+AC_SUBST([MINGW_EXTRA_LDFLAGS])
+
+dnl ---------------------------------------------------------------------
dnl Checks for libraries.
dnl ---------------------------------------------------------------------
-AC_CHECK_LIB([check], [suite_create], ,
- AC_MSG_ERROR([Missing check libraries.]))
AC_CHECK_LIB([virt], [virConnectOpen], ,
AC_MSG_ERROR([Missing libvirt libraries.]))
AC_CHECK_LIB([pcre], [pcre_compile], ,
AC_MSG_ERROR([Missing PCRE libraries.]))
-AC_CHECK_LIB([udev], [udev_new], ,
- AC_MSG_ERROR([Missing udev libraries.]))
+dnl ---------------------------------------------------------------------
+dnl These libraries are not provided
+dnl ---------------------------------------------------------------------
+if test "${WIN32}" = "no"; then
+ AC_CHECK_LIB([check], [suite_create], ,
+ AC_MSG_ERROR([Missing check libraries.]))
+ AC_CHECK_LIB([udev], [udev_new], ,
+ AC_MSG_ERROR([Missing udev libraries.]))
+fi
dnl ---------------------------------------------------------------------
dnl Checks for header files.
diff --git a/src/host.cpp b/src/host.cpp
index 492424a..f84ee7d 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -26,23 +26,21 @@
#include "processor.h"
#include <set>
#include <string>
-#include <sys/sysinfo.h>
+#include <sstream>
#ifdef __linux__
-
+#include <sys/sysinfo.h>
#include <sys/utsname.h>
-
+// TODO remove this wrapper once rhbz#583747 is fixed
+extern "C" {
+#include <libudev.h>
+}
#elif defined WIN32
#include <winsock.h>
#endif
-// TODO remove this wrapper once rhbz#583747 is fixed
-extern "C" {
-#include <libudev.h>
-}
-
using namespace std;
#ifdef WIN32
@@ -199,6 +197,7 @@ string
host_get_operating_system()
{
static string operating_system;
+ stringstream ss;
if(operating_system.empty())
{
@@ -208,8 +207,8 @@ host_get_operating_system()
if(!uname(&details))
{
- operating_system = string(details.sysname) +
- " (" + details.release + ")";
+ ss << string(details.sysname) << " (" << details.release << ")" << endl;
+ operating_system = ss.str();
}
#elif defined WIN32
@@ -236,8 +235,8 @@ host_get_operating_system()
minor = (DWORD)(HIBYTE(LOWORD(version)));
build = (DWORD)(HIWORD(version));
- operating_system = string("Windows ") +
- "(" + major + "." + minor + "." + build + ")";
+ ss << "Windows " << "(" << major << "." << minor << "." << build << ")" << endl;
+ operating_system = ss.str();
}
}
@@ -301,7 +300,7 @@ host_get_architecture()
#elif defined WIN32
- LPSYSTEM_INFO system_info;
+ SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
--
1.7.2.1
13 years, 8 months
[PATCH] matahari autoconf win32 conditionals
by Adam Stokes
AC_PREREQ([2.65])
AC_INIT([Matahari], [0.1.0], [matahari(a)lists.fedorahosted.org])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4])
dnl Make automake keep quiet about wildcards & other GNUmake-isms
AM_INIT_AUTOMAKE([-Wno-portability])
dnl ---------------------------------------------------------------------
dnl check for necessary programs
dnl ---------------------------------------------------------------------
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
CFLAGS="$cflags_save"
gl_EARLY
AC_PROG_CC_C_O
gl_INIT
AC_CHECK_PROG(HASQMFGEN, qmf-gen, "yes")
if test x"$HASQMFGEN" = "x"; then
AC_MSG_ERROR([Missing QMF schema processor.])
fi
dnl ---------------------------------------------------------------------
dnl Test for WIN32
dnl ---------------------------------------------------------------------
WIN32="no"
case "$host" in
*-*-mingw*)
WIN32="yes"
MINGW_EXTRA_LDFLAGS="-no-undefined"
;;
*)
;;
esac
AM_CONDITIONAL(WIN32, test "${WIN32}" = "yes")
AC_SUBST([WIN32])
AC_SUBST([MINGW_EXTRA_LDFLAGS])
dnl ---------------------------------------------------------------------
dnl Checks for libraries.
dnl ---------------------------------------------------------------------
AC_CHECK_LIB([virt], [virConnectOpen], ,
AC_MSG_ERROR([Missing libvirt libraries.]))
AC_CHECK_LIB([pcre], [pcre_compile], ,
AC_MSG_ERROR([Missing PCRE libraries.]))
dnl ---------------------------------------------------------------------
dnl These libraries are not provided
dnl ---------------------------------------------------------------------
if test "${WIN32}" = "no"; then
AC_CHECK_LIB([check], [suite_create], ,
AC_MSG_ERROR([Missing check libraries.]))
AC_CHECK_LIB([udev], [udev_new], ,
AC_MSG_ERROR([Missing udev libraries.]))
fi
dnl ---------------------------------------------------------------------
dnl Checks for header files.
dnl ---------------------------------------------------------------------
AC_CHECK_HEADERS([string.h sys/ioctl.h])
dnl ---------------------------------------------------------------------
dnl Checks for typedefs, structures, and compiler characteristics.
dnl ---------------------------------------------------------------------
AC_HEADER_STDBOOL
AC_TYPE_UINT32_T
dnl ---------------------------------------------------------------------
dnl Checks for library functions.
dnl ---------------------------------------------------------------------
AC_CHECK_FUNCS([strdup strerror sysinfo uname])
AC_CONFIG_FILES([Makefile
lib/Makefile
src/Makefile
src/tests/Makefile])
AC_OUTPUT
13 years, 8 months
[PATCH] Gets the CPU model on a Windows machine.
by Darryl L. Pierce
Also introduces a new system for interacting with WMI via external
scripts. A new source module, util.c, contains the method
exec_and_capture_output(char*, char**). It takes as input a command line
to execute and a pointer to a buffer to be allocated and filled with the
output from the command.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/Makefile.am | 7 ++-
src/processor.cpp | 12 ++++++
src/util.c | 76 +++++++++++++++++++++++++++++++++++++
src/util.h | 37 ++++++++++++++++++
src/windows/win_get_cpu_model.vbs | 30 ++++++++++++++
5 files changed, 160 insertions(+), 2 deletions(-)
create mode 100644 src/util.c
create mode 100644 src/util.h
create mode 100644 src/windows/win_get_cpu_model.vbs
diff --git a/src/Makefile.am b/src/Makefile.am
index c56a900..0910d86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,10 +28,13 @@ matahari_SOURCES = \
main.cpp \
processor.cpp \
processor.h \
+ util.c \
+ util.h \
qmf/hostagent.cpp \
qmf/hostagent.h \
qmf/processoragent.cpp \
- qmf/processoragent.h
+ qmf/processoragent.h \
+ windows/win_get_cpu_model.vbs
SCHEMAS = \
schema-host.xml
@@ -39,7 +42,7 @@ SCHEMAS = \
$(generated_file_list): $(SCHEMAS)
qmf-gen -o ./qmf $(SCHEMAS)
-BUILT_SOURCES = $(generated_file_list)
+BUILT_SOURCES = $(generated_file_list) $(windows_scripts)
CLEANFILES = $(generated_file_list)
matahari_CPPFLAGS = -fno-strict-aliasing
diff --git a/src/processor.cpp b/src/processor.cpp
index 65de27e..9a3c25e 100644
--- a/src/processor.cpp
+++ b/src/processor.cpp
@@ -25,6 +25,7 @@
#include "processor.h"
#include <stdexcept>
#include <string>
+#include "util.h"
using namespace std;
@@ -162,6 +163,17 @@ cpu_get_details()
free(buffer);
buffer = NULL;
}
+
+ // get the processor model
+ char* model = NULL;
+
+ if(!exec_and_capture_text("cscript.exe /nologo win_get_cpu_model.vbs",
+ model)
+ {
+ cpuinfo.model = string(model);
+ }
+
+ free(model);
}
#endif
}
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..6be88de
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,76 @@
+/* util.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 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.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+
+#ifdef __linux__
+
+#include <string.h>
+
+#define POPEN_MODE "r"
+
+#elif defined WIN32
+
+#include <memory.h>
+
+#define popen(fname, mode) _popen(fname, mode)
+#define pclose(x) _pclose(x)
+
+#define POPEN_MODE "rt"
+
+#endif
+
+int
+exec_and_capture_text(char* cmdline, char** output)
+{
+ int result = 1;
+
+ // initial the output
+ *output = NULL;
+
+ if(cmdline != NULL)
+ {
+ FILE* input;
+ int offset = 0;
+
+ if((input = popen(cmdline, POPEN_MODE)) != NULL)
+ {
+ while(!feof(input))
+ {
+ char buffer[256];
+ int bytesread;
+
+ memset(buffer, 256, 0);
+ bytesread = fread(buffer, 1, 256, input);
+ *output = (char*)realloc(*output, offset + bytesread + 1);
+ memcpy((*output) + offset, buffer, bytesread);
+ offset += bytesread;
+ ((char*)(*output))[offset] = '\0';
+ }
+
+ pclose(input);
+ result = 0;
+ }
+ }
+
+ return result;
+}
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..df21bc7
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL_H
+#define __UTIL_H
+
+/* util.h - 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 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.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /* Executes an external program and captures the output,
+ returning the captured text. The output buffer is allocated
+ by this function and the caller is responsible for releasing
+ the memory. */
+ int exec_and_capture_text(char* cmdline, char** output);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/windows/win_get_cpu_model.vbs b/src/windows/win_get_cpu_model.vbs
new file mode 100644
index 0000000..5fe1030
--- /dev/null
+++ b/src/windows/win_get_cpu_model.vbs
@@ -0,0 +1,30 @@
+' ---------------------------------------------------------------------
+' win_get_cpu_model.vbs - Copyright (C) 2010, Red Hat.
+' Written by Darryl L. Pierce <dpierce(a)redhat.com>
+'
+' This program is free software: you can redistribute it and/or modify
+' it under the terms of the GNU General Public License as published by
+' the Free Software Foundation, either version 3 of the License, or
+' (at your option) any later version.
+'
+' This program is distributed in the hope that it will be useful,
+' but WITHOUT ANY WARRANTY; without even the implied warranty of
+' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+' GNU General Public License for more details.
+'
+' You should have received a copy of the GNU General Public License
+' along with this program. If not, see <http://www.gnu.org/licenses/>.
+' ---------------------------------------------------------------------
+
+strComputer = "."
+Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
+Set processors = objWMIService.ExecQuery("select * from Win32_Processor")
+
+displayed = false
+
+For Each processor in processors
+ if Not displayed Then
+ Wscript.echo "NAME=" & processor.Name
+ displayed = true
+ end if
+Next
--
1.7.2.1
13 years, 8 months
[PATCH] Retrieves the architecture on Win32 systems.
by Darryl L. Pierce
This code determines if the processor is an AMD 64 bit system, an ia64
system or an Intel 32 bit system.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index 730529c..396818d 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -249,10 +249,25 @@ host_get_architecture()
#elif defined WIN32
- // TODO this should be more explicit and determine if
- // the compiler is using a 64-bit target in future.
- architecture = string("Win32");
+ LPSYSTEM_INFO system_info;
+ 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;
+ }
#endif
}
--
1.7.2
13 years, 8 months
netcf/mingw documentation
by Adam Stokes
A wiki page dedicated to the progress of porting netcf to windows
https://fedorahosted.org/netcf/wiki/windows
--
__ __
.-----.| |_.-----.| |--.-----.-----.
|__ --|| _| _ || <| -__|__ --|
|_____||____|_____||__|__|_____|_____|
.----------------------------------.
( ajs(a)redhat.com || 919.754.4187 )
`----------------------------------'
13 years, 8 months
MinGW and WMI
by Darryl L. Pierce
I've spent the past week or so trying to get WMI implemented and
available via MinGW so that we could take advantage of it for our
Windows builds of Matahari.
After some frustration at finding that it's been requested, but nobody's
implemented it, since 2005, I think for our use it might not be the
right path to follow.
I have found a lot of Win32 APIs that directly give us some of the
information that we need, such as CPU type, archetecture and similar.
But it's been a little more elusive to get information like the UUID of
the mother board and CPU model.
In the short term, it would probably be easier to do our Windows
development on Windows using WMI. Then we can look toward getting WMI
into MinGW afterward and moving our builds back to Linux at that point.
Thoughts?
--
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/
13 years, 8 months
[PATCH] Sets the operating system name and version.
by Darryl L. Pierce
For Linux, it uses the uname() function.
For Windows, it uses the GetVersion() API.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
src/host.h | 2 +
src/qmf/hostagent.cpp | 1 +
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index 730529c..4792557 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -196,6 +196,58 @@ host_get_hostname()
}
string
+host_get_operating_system()
+{
+ static string operating_system;
+
+ if(operating_system.empty())
+ {
+#ifdef __linux__
+
+ struct utsname details;
+
+ if(!uname(&details))
+ {
+ operating_system = string(details.sysname) +
+ " (" + details.release + ")";
+ }
+
+#elif defined WIN32
+
+ HINSTANCE dll;
+
+ dll = LoadLibrary("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 = string("Windows ") +
+ "(" + major + "." + minor + "." + build + ")";
+ }
+ }
+
+#endif
+ }
+
+ return operating_system;
+}
+
+string
host_get_hypervisor()
{
static string hypervisor;
diff --git a/src/host.h b/src/host.h
index a680861..f83e3fd 100644
--- a/src/host.h
+++ b/src/host.h
@@ -37,6 +37,8 @@ string host_get_uuid();
string host_get_hostname();
+string host_get_operating_system();
+
string host_get_hypervisor();
unsigned int host_get_platform();
diff --git a/src/qmf/hostagent.cpp b/src/qmf/hostagent.cpp
index 49bb40b..b67a1d6 100644
--- a/src/qmf/hostagent.cpp
+++ b/src/qmf/hostagent.cpp
@@ -42,6 +42,7 @@ HostAgent::setup(ManagementAgent* agent)
_management_object->set_uuid(host_get_uuid());
_management_object->set_hostname(host_get_hostname());
+ _management_object->set_operating_system(host_get_operating_system());
_management_object->set_hypervisor(host_get_hypervisor());
_management_object->set_platform(host_get_platform());
_management_object->set_arch(host_get_architecture());
--
1.7.2
13 years, 8 months
[PATCH] Retrieves the architecture on Win32 systems.
by Darryl L. Pierce
This code determines if the processor is an AMD 64 bit system, an ia64
system or an Intel 32 bit system.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index 730529c..396818d 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -249,10 +249,25 @@ host_get_architecture()
#elif defined WIN32
- // TODO this should be more explicit and determine if
- // the compiler is using a 64-bit target in future.
- architecture = string("Win32");
+ LPSYSTEM_INFO system_info;
+ 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;
+ }
#endif
}
--
1.7.2
13 years, 8 months