This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] setup.exe: add autoload and version check for AttachConsole


    Hi gang,

  AttachConsole (added recently for stdout/stderr handling) doesn't exist on
win2k, having been introduced in xp/2k3, so setup HEAD currently doesn't run
there.

  The attached patch fixes the load-time problem by adding an autoload.  That
won't prevent the run-time crash if the function gets called, of course; so it
also adds a version check before the call.

  Unless anyone shouts, I'll commit it later today; I think this is basically
obvious.  Tested by verifying under GDB that it avoids the SEGV and by seeing
that with the patch the setup.log and setup.log.full files are successfully
generated.

	* autoload.c (kernel32):  Add autoload entry for AttachConsole.
	* main.cc (set_cout):  Check IsXpOrBetter before trying to use it.
	* win32.h (IsXpOrBetter):  New version check macro.

    cheers,
      DaveK

Index: autoload.c
===================================================================
RCS file: /cvs/cygwin-apps/setup/autoload.c,v
retrieving revision 2.7
diff -p -u -r2.7 autoload.c
--- autoload.c	8 Apr 2008 23:50:54 -0000	2.7
+++ autoload.c	1 Apr 2009 11:38:26 -0000
@@ -61,6 +61,8 @@ Auto (advapi32, OpenServiceA, 16);
 Auto (advapi32, QueryServiceStatus, 8);
 Auto (advapi32, StartServiceA, 16);
 
+DLL (kernel32);
+Auto (kernel32, AttachConsole, 4);
 
 typedef struct {
   DllInfo *dll;
Index: main.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/main.cc,v
retrieving revision 2.48
diff -p -u -r2.48 main.cc
--- main.cc	21 Mar 2009 21:00:25 -0000	2.48
+++ main.cc	1 Apr 2009 11:38:26 -0000
@@ -85,7 +85,7 @@ set_cout ()
 {
   HANDLE hstdout = GetStdHandle (STD_OUTPUT_HANDLE);
   if (GetFileType (hstdout) == FILE_TYPE_UNKNOWN && GetLastError () != NO_ERROR
-      && AttachConsole ((DWORD) -1))
+      && IsXpOrBetter () && AttachConsole ((DWORD) -1))
       {
 	ofstream *conout = new ofstream ("conout$");
 	cout.rdbuf (conout->rdbuf ());
Index: win32.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/win32.h,v
retrieving revision 2.17
diff -p -u -r2.17 win32.h
--- win32.h	20 Aug 2008 10:33:25 -0000	2.17
+++ win32.h	1 Apr 2009 11:38:27 -0000
@@ -162,5 +162,8 @@ VersionInfo& GetVer ();
 #define IsWindowsNT() (GetVer ().isNT ())
 #define OSMajorVersion() (GetVer ().major ())
 #define OSMinorVersion() (GetVer ().minor ())
+#define IsXpOrBetter()   ((OSMajorVersion () > 5) \
+			   || (OSMajorVersion () == 5 && OSMinorVersion () >= 1))
+
 
 #endif /* SETUP_WIN32_H */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]