From 62844d840dc26bf79c1471f824789622ba940668 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 2 May 2000 05:00:22 +0000 Subject: [PATCH] * setup.c (cleanup): Inverse order of deletion stands a better chance of deleting cygpath.exe. Still seems to suffer from occasional races, though. (cleanup_on_signal): Perform convoluted dance to accomodate win95 and w2k. (output_file): Defend against an unlikely handle leak. (main): Don't set up signal handling until we have something special to do. --- ChangeLog | 11 +++++++++++ setup.c | 35 ++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2163d0d8..a447b3b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue May 2 00:56:41 2000 Christopher Faylor + + * setup.c (cleanup): Inverse order of deletion stands a better chance + of deleting cygpath.exe. Still seems to suffer from occasional races, + though. + (cleanup_on_signal): Perform convoluted dance to accomodate win95 and + w2k. + (output_file): Defend against an unlikely handle leak. + (main): Don't set up signal handling until we have something special to + do. + Mon May 1 17:56:32 2000 Christopher Faylor * path.c (kill_cygpath): Delete function. diff --git a/setup.c b/setup.c index 19c12f48..d8ea765e 100644 --- a/setup.c +++ b/setup.c @@ -71,8 +71,8 @@ cleanup (void) int i, j; extern void exit_cygpath (void); exit_cygpath (); - for (i = 0; i < deleteme.count; i++) - for (j = 0; _unlink (deleteme.array[i]) && j < 20; j++) + for (i = deleteme.count; --i >= 0; ) + for (j = 0; !DeleteFile (deleteme.array[i]) && j < 20; j++) Sleep (100); sa_cleanup (&deleteme); } @@ -80,11 +80,13 @@ cleanup (void) static void cleanup_on_signal (int sig) { - /* I have no idea why this is necessary but without this code - seems to continue executing in the main thread even after - the ExitProcess. */ + fprintf (stderr, "\n*Exit*\r\n"); SuspendThread (hMainThread); - _cexit (); + cleanup (); + /* I have no idea why this is necessary but, without this, code + seems to continue executing in the main thread even after + the ExitProcess??? */ + TerminateThread (hMainThread, 1); ExitProcess (1); } @@ -175,7 +177,7 @@ output_file (HMODULE h, LPCTSTR type, LPTSTR name, LONG lparam) HRSRC rsrc; HGLOBAL res; char *data; - FILE *out; + FILE *out = NULL; BOOL retval = FALSE; size_t bytes_needed; @@ -187,8 +189,6 @@ output_file (HMODULE h, LPCTSTR type, LPTSTR name, LONG lparam) char *buffer; size_t bytes = SizeofResource (NULL, rsrc); - sa_add (&deleteme, name); - if (bytes != fwrite (data, 1, bytes, out)) warning ("Unable to write %s: %s", name, _strerror ("")); @@ -199,7 +199,6 @@ output_file (HMODULE h, LPCTSTR type, LPTSTR name, LONG lparam) gzf = gzdopen (_dup (fileno (out)), "rb"); if (gzf && (size_t) gzread (gzf, buffer, bytes_needed) == bytes_needed) { - gzclose (gzf); if (fseek (out, 0, SEEK_SET) || fwrite (buffer, 1, bytes_needed, out) != bytes_needed) { @@ -218,7 +217,10 @@ output_file (HMODULE h, LPCTSTR type, LPTSTR name, LONG lparam) errnum, msg); } xfree (buffer); + if (gzf) + gzclose (gzf); fclose (out); + sa_add (&deleteme, name); } else { @@ -1429,11 +1431,6 @@ those as the basis for your installation.\n\n" start = clock (); sa_init (&deleteme); - DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), - GetCurrentProcess (), &hMainThread, 0, 0, - DUPLICATE_SAME_ACCESS); - atexit (cleanup); - signal (SIGINT, cleanup_on_signal); if (!EnumResourceNames (NULL, "FILE", output_file, 0)) { @@ -1485,6 +1482,12 @@ those as the basis for your installation.\n\n" else defroot = xstrdup (DEF_ROOT); + DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), + GetCurrentProcess (), &hMainThread, 0, 0, + DUPLICATE_SAME_ACCESS); + atexit (cleanup); + signal (SIGINT, cleanup_on_signal); + /* Get the root directory and warn the user if there are any spaces in the path. */ for (done = 0; !done;) @@ -1512,6 +1515,8 @@ those as the basis for your installation.\n\n" } xfree (defroot); + Sleep (0); + /* Create the root directory. */ mkdirp (root); /* Ignore any return value since it may already exist. */ -- 2.43.5