The newly rebuilt RHSrvAny worked on Windows XP, Windows 2003 R2, and Windows Vista+, but segfaulted on Windows 2003. After much investigation, the issue seems to have been with inconsistent use of Unicode. This series fixes compilation on Microsoft Visual C++ 2010 (the most recent version which runs on Windows 2003), fixes all compiler warnings, and enabled warnings during the build. The resulting executable now works on Windows 2003 both when built by MSVC 2010 and mingw32 on F19. Matt
Matthew Booth
2013-Nov-18 14:17 UTC
[Libguestfs] [PATCH 1/6] Fix compile error on MSVC 2010: tchar.h must come before strsafe.h
--- RHSrvAny/RHSrvAny.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RHSrvAny/RHSrvAny.c b/RHSrvAny/RHSrvAny.c index 3639d22..12d9884 100644 --- a/RHSrvAny/RHSrvAny.c +++ b/RHSrvAny/RHSrvAny.c @@ -29,13 +29,12 @@ #include <stdio.h> #include <stdlib.h> +#include <tchar.h> #ifdef HAVE_STRSAFE #include <strsafe.h> #endif -#include <tchar.h> - #include "RHSrvAny.h" static TCHAR *svcname = TEXT("RHSrvAny"); -- 1.8.3.1
Matthew Booth
2013-Nov-18 14:17 UTC
[Libguestfs] [PATCH 2/6] Use _tmain() instead of main() when compiling on Windows
--- RHSrvAny/RHSrvAny.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/RHSrvAny/RHSrvAny.c b/RHSrvAny/RHSrvAny.c index 12d9884..0aa9470 100644 --- a/RHSrvAny/RHSrvAny.c +++ b/RHSrvAny/RHSrvAny.c @@ -61,14 +61,30 @@ argument_error (const char *msg) return EXIT_FAILURE; } +static int compat_tmain (int argc, TCHAR *argv[]); + +#ifdef __MINGW32__ int -main (int argc, char **a_argv) +main (int argc, char **argv) { - /* For compatibility with MinGW, see: - http://demosten-eng.blogspot.com/2008/08/mingw-and-unicode-support.html */ - TCHAR **argv; - argv = CommandLineToArgvW (GetCommandLineW (), &argc); +#ifdef UNICODE + TCHAR **w_argv = CommandLineToArgvW(GetCommandLineW(), &argc); + return compat_tmain(argc, w_argv); +#else + return compat_tmain(argc, argv); +#endif +} +#else +int +_tmain(int argc, TCHAR *argv[]) +{ + return compat_tmain(argc, argv); +} +#endif +static int +compat_tmain (int argc, TCHAR *argv[]) +{ size_t i; for (i = 1; i < argc; i++) { TCHAR *arg = argv[i]; -- 1.8.3.1
Visual Studio 2010 doesn't support C99(!). --- RHSrvAny/RHSrvAny.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/RHSrvAny/RHSrvAny.c b/RHSrvAny/RHSrvAny.c index 0aa9470..933de7c 100644 --- a/RHSrvAny/RHSrvAny.c +++ b/RHSrvAny/RHSrvAny.c @@ -85,7 +85,9 @@ _tmain(int argc, TCHAR *argv[]) static int compat_tmain (int argc, TCHAR *argv[]) { - size_t i; + SERVICE_TABLE_ENTRY DispatchTable[2]; + int i; + for (i = 1; i < argc; i++) { TCHAR *arg = argv[i]; @@ -115,13 +117,10 @@ compat_tmain (int argc, TCHAR *argv[]) return SvcUninstall(); } - SERVICE_TABLE_ENTRY DispatchTable[] = { - { - svcname, - (LPSERVICE_MAIN_FUNCTION) SvcMain - }, - { NULL, NULL } - }; + DispatchTable[0].lpServiceName = svcname; + DispatchTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION) SvcMain; + DispatchTable[1].lpServiceName = NULL; + DispatchTable[1].lpServiceProc = NULL; if (!StartServiceCtrlDispatcher( DispatchTable )) { -- 1.8.3.1
Matthew Booth
2013-Nov-18 14:17 UTC
[Libguestfs] [PATCH 4/6] Use StringCchPrintf/snwprintf consistently throughout
--- RHSrvAny/RHSrvAny.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/RHSrvAny/RHSrvAny.c b/RHSrvAny/RHSrvAny.c index 933de7c..2db261a 100644 --- a/RHSrvAny/RHSrvAny.c +++ b/RHSrvAny/RHSrvAny.c @@ -35,6 +35,12 @@ #include <strsafe.h> #endif +#ifdef HAVE_STRINGCCHPRINTF +#define SNPRINTF StringCchPrintf +#else +#define SNPRINTF snwprintf +#endif + #include "RHSrvAny.h" static TCHAR *svcname = TEXT("RHSrvAny"); @@ -215,7 +221,7 @@ SvcInstall() { } /* Construct ImagePath, which is actually a command line in this instance */ - if (snwprintf(imagePath, MAX_PATH, L"%s -s %s", szPath, svcname) >= MAX_PATH) + if (SNPRINTF(imagePath, MAX_PATH, TEXT("%s -s %s"), szPath, svcname) >= MAX_PATH) { printf("ImagePath exceeded %d characters\n", MAX_PATH); return EXIT_FAILURE; @@ -517,12 +523,7 @@ SvcReportEvent ( if ( NULL != hEventSource ) { -#ifdef HAVE_STRINGCCHPRINTF - StringCchPrintf -#else - snwprintf -#endif - ( + SNPRINTF( Buffer, 80, TEXT("%s failed with %d"), -- 1.8.3.1
Matthew Booth
2013-Nov-18 14:17 UTC
[Libguestfs] [PATCH 5/6] Use TCHAR consistently throughout
--- RHSrvAny/RHSrvAny.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/RHSrvAny/RHSrvAny.c b/RHSrvAny/RHSrvAny.c index 2db261a..0258031 100644 --- a/RHSrvAny/RHSrvAny.c +++ b/RHSrvAny/RHSrvAny.c @@ -97,8 +97,8 @@ compat_tmain (int argc, TCHAR *argv[]) for (i = 1; i < argc; i++) { TCHAR *arg = argv[i]; - if (arg[0] == _T('-')) { - if (lstrcmpi(arg + 1, _T("s")) == 0) { + if (arg[0] == TEXT('-')) { + if (lstrcmpi(arg + 1, TEXT("s")) == 0) { if (i == argc) { return argument_error("Option -s requires an argument"); } @@ -201,7 +201,7 @@ SvcInstall() { SC_HANDLE schSCManager; SC_HANDLE schService; TCHAR szPath[MAX_PATH]; - wchar_t imagePath[MAX_PATH]; + TCHAR imagePath[MAX_PATH]; schSCManager = OpenSCManager( NULL, @@ -301,9 +301,9 @@ SvcMain ( static BOOL RegistryRead ( HKEY hHive, - wchar_t *szKeyPath, - wchar_t *szValue, - wchar_t *szData, + TCHAR *szKeyPath, + TCHAR *szValue, + TCHAR *szData, DWORD *nSize ) { HKEY hKey; @@ -341,10 +341,10 @@ SvcInit ( DWORD nSize; BOOL fSuccess; STARTUPINFO si; - wchar_t szPWD[1024]; + TCHAR szPWD[1024]; PROCESS_INFORMATION pi; - wchar_t szCmdLine[1024]; - wchar_t szRegistryPath[1024]; + TCHAR szCmdLine[1024]; + TCHAR szRegistryPath[1024]; // TO_DO: Declare and set any required variables. // Be sure to periodically call ReportSvcStatus() with @@ -383,17 +383,17 @@ SvcInit ( ZeroMemory( &pi, sizeof(pi) ); nSize=1024; - snwprintf ( + SNPRINTF( szRegistryPath, sizeof szRegistryPath, - L"SYSTEM\\CurrentControlSet\\services\\%s\\Parameters", + TEXT("SYSTEM\\CurrentControlSet\\services\\%s\\Parameters"), svcname ); fSuccess = RegistryRead ( HKEY_LOCAL_MACHINE, szRegistryPath, - L"CommandLine", + TEXT("CommandLine"), szCmdLine, &nSize ); @@ -402,7 +402,7 @@ SvcInit ( fSuccess = RegistryRead ( HKEY_LOCAL_MACHINE, szRegistryPath, - L"PWD", + TEXT("PWD"), szPWD, &nSize ); -- 1.8.3.1
Matthew Booth
2013-Nov-18 14:17 UTC
[Libguestfs] [PATCH 6/6] Enable compiler warnings, and fail on warnings
--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e58941d..07cc982 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ dnl If the host is Windows, define _WIN32_WINNT and others. AC_CANONICAL_HOST case $host in *mingw*|*cygwin*|*win32*) - CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0500 -DUNICODE -D_UNICODE" ;; + CFLAGS="$CFLAGS -Wall -Werror -D_WIN32_WINNT=0x0500 -DUNICODE -D_UNICODE" ;; esac dnl Check for headers which are not present in some versions of MinGW. -- 1.8.3.1
Richard W.M. Jones
2013-Nov-18 15:26 UTC
Re: [Libguestfs] RHSrvAny: Fix failure on Windows 2003
On Mon, Nov 18, 2013 at 02:17:44PM +0000, Matthew Booth wrote:> The newly rebuilt RHSrvAny worked on Windows XP, Windows 2003 R2, and Windows > Vista+, but segfaulted on Windows 2003. After much investigation, the issue > seems to have been with inconsistent use of Unicode. > > This series fixes compilation on Microsoft Visual C++ 2010 (the most recent > version which runs on Windows 2003), fixes all compiler warnings, and enabled > warnings during the build. The resulting executable now works on Windows 2003 > both when built by MSVC 2010 and mingw32 on F19.Thanks, I have pushed these. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Maybe Matching Threads
- [PATCH 1/6] Rationalise whitespace to 4 space indentation with no trailing spaces
- [PATCH 1/3] Rationalise whitespace to 4 space indentation with no trailing spaces
- Re: [PATCH 1/6] tests: use fake rhsrvany.exe
- Re: [PATCH 1/6] tests: use fake rhsrvany.exe
- Fwd: win32-clipboard and Unicode zero bytes