From 634d51d94ec5b563880787ba8dddf0add5771ee9 Mon Sep 17 00:00:00 2001
From: Christopher Faylor <me@cgf.cx>
Date: Sat, 24 Jul 2004 19:18:58 +0000
Subject: [PATCH] * dcrt0.cc (dll_crt0_0): Use proper boolean arguments. *
 pinfo.cc (pinfo::init): Don't consider MapViewOfFileEx error to be fatal if
 exiting. * pinfo.h (pinfo::init): Eliminate default argument and supply the
 argument in the one case that needed it.

---
 winsup/cygwin/ChangeLog |  8 ++++++++
 winsup/cygwin/dcrt0.cc  |  6 +++---
 winsup/cygwin/pinfo.cc  | 21 +++++++++++++++++++--
 winsup/cygwin/pinfo.h   |  6 +++---
 4 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index bb6d29753..2907f16fd 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2004-07-24  Christopher Faylor  <cgf@timesys.com>
+
+	* dcrt0.cc (dll_crt0_0): Use proper boolean arguments.
+	* pinfo.cc (pinfo::init): Don't consider MapViewOfFileEx error to be
+	fatal if exiting.
+	* pinfo.h (pinfo::init): Eliminate default argument and supply the
+	argument in the one case that needed it.
+
 2004-07-24  Corinna Vinschen  <corinna@vinschen.de>
 	    Christopher Faylor  <cgf@timesys.com>
 
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 6f99403b0..93568f5fd 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -665,7 +665,7 @@ dll_crt0_0 ()
 	{
 	  case _PROC_FORK:
 	    alloc_stack (fork_info);
-	    cygheap_fixup_in_child (0);
+	    cygheap_fixup_in_child (false);
 	    memory_init ();
 	    set_myself (mypid);
 	    close_ppid_handle = !!child_proc_info->pppid_handle;
@@ -679,11 +679,11 @@ dll_crt0_0 ()
 	    hexec_proc = spawn_info->hexec_proc;
 	  around:
 	    HANDLE h;
-	    cygheap_fixup_in_child (1);
+	    cygheap_fixup_in_child (true);
 	    memory_init ();
 	    if (!spawn_info->moreinfo->myself_pinfo ||
 		!DuplicateHandle (hMainProc, spawn_info->moreinfo->myself_pinfo,
-				  hMainProc, &h, 0, 0,
+				  hMainProc, &h, 0, FALSE,
 				  DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
 	      h = NULL;
 	    set_myself (mypid, h);
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index dcbdf27ca..82ea74d32 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -193,8 +193,25 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
 	}
 
       procinfo = (_pinfo *) MapViewOfFileEx (h, access, 0, 0, 0, mapaddr);
-      if (!procinfo)
-	api_fatal ("MapViewOfFileEx(%p) failed, %E", h);
+      if (procinfo)
+	/* it worked */;
+      else if (exit_state)
+	return;		/* exiting */
+      else
+	{
+	  if (GetLastError () == ERROR_INVALID_HANDLE)
+	    api_fatal ("MapViewOfFileEx(%p, in_h %p) failed, %E", h, in_h);
+	  else
+	    {
+	      debug_printf ("MapViewOfFileEx(%p, in_h %p) failed, %E", h, in_h);
+	      CloseHandle (h);
+	    }
+	  if (i < 9)
+	    continue;
+	  else
+	    return;
+	}
+
       ProtectHandle1 (h, pinfo_shared_handle);
 
       if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 923b0bec7..5cf632f18 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -129,11 +129,11 @@ class pinfo
   _pinfo *procinfo;
   bool destroy;
 public:
-  void init (pid_t n, DWORD create = 0, HANDLE h = NULL) __attribute__ ((regparm(3)));
+  void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3)));
   pinfo () {}
   pinfo (_pinfo *x): procinfo (x) {}
-  pinfo (pid_t n) {init (n);}
-  pinfo (pid_t n, int create) {init (n, create);}
+  pinfo (pid_t n) {init (n, 0);}
+  pinfo (pid_t n, DWORD flag) {init (n, flag);}
   void release ();
   ~pinfo ()
   {