Subject: RE: What to do when setup fails?
From: "Dave Korn" <[email-masked]>
To: <[email-masked]>
Cc: "'Max Bowsher'" <[email-masked]>
Date: Wed, 10 Nov 2004 17:03:18 -0000

> -----Original Message-----
> From: Igor Pechtchanski [mailto:[email-masked]] 
> Sent: 10 November 2004 16:10

> Quoting the patch:
> 
> -    fatal ("mount");
> +  {
> +  char errbuffer[40];
> +    _snprintf (errbuffer, 40, "mount %d", GetLastError ());
> +    fatal (errbuffer);
> +  }
> 
> Umm, isn't this exactly what fatal() does already?
> 
> Quoting dialog.cc:
> 
> void
> fatal (const char *msg)
> {
>   DWORD e = GetLastError ();
>   char *buf;
>   FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | 
> FORMAT_MESSAGE_FROM_SYSTEM,
>                  0, e, 0, (CHAR *) & buf, 0, 0);
>   MessageBox (0, buf, msg, 0);
>   LogSingleton::GetInstance().exit (1);
>   // Keep gcc happy - some sort of bug!
>   exit (1);
> }

  Ah, didn't look closely at that.

  Ok, then according to Luke's original post....

>It fails due to mount, apparently.  A panel titled "Mount" pops up
>after the download stage, saying: "The operation completed
>successfully", and then setup exits.

..which must imply that RegCreateKeyEx returns some value other than
ERROR_SUCCESS, but at the same time GetLastError is returning zero.  Time to
check MSDN:

--------------------<quote usage="fair">--------------------
If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in
Winerror.h. You can use the FormatMessage function with the
FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
--------------------<quote usage="fair">--------------------

...which *implies* that the error code is being returns, not SetLastError'd, and
so we're discarding it early.  Perhaps the following patch would be more like
it:

Index: mount.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/mount.cc,v
retrieving revision 2.16
diff -p -u -r2.16 mount.cc
--- mount.cc	11 Jul 2003 22:48:14 -0000	2.16
+++ mount.cc	10 Nov 2004 17:02:32 -0000
@@ -151,9 +151,14 @@ create_mount (String const posix, String
 	   CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, posix.cstr_oneuse ());
 
   HKEY kr = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
-  if (RegCreateKeyEx (kr, buf, 0, (char *)"Cygwin", 0, KEY_ALL_ACCESS,
-		      0, &key, &disposition) != ERROR_SUCCESS)
-    fatal ("mount");
+  LONG retval = RegCreateKeyEx (kr, buf, 0, (char *)"Cygwin", 0, 
+	   KEY_ALL_ACCESS, 0, &key, &disposition);
+  if (retval != ERROR_SUCCESS)
+  {
+  char errbuffer[40];
+    _snprintf (errbuffer, 40, "Mount error %d", retval);
+    fatal (errbuffer);
+  }
 
   RegSetValueEx (key, "native", 0, REG_SZ, (BYTE *) win32.cstr_oneuse (),
 		 win32.size () + 1);

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/