This is the mail archive of the cygwin-patches 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] Prevent restart of crashing non-Cygwin exe


If a non-Cygwin .exe started from a Cygwin shell window segfaults, Cygwin restarts the .exe 5 times.

Testcase:

$ cat crash.c
#include <stdio.h>

int main()
{
  printf("Hello, "); fflush(stdout);
  *(char *)0 = 42;
  printf("World\n");
  return 0;
}

$ gcc -o crash-c crash.c

$ ./crash-c
Hello, Segmentation fault (core dumped)

$ i686-w64-mingw32-gcc -o crash-w crash.c

$ ./crash-w
Hello, Hello, Hello, Hello, Hello, Hello,

(The repeated outputs are not be visible on 1.7.9-1 when shell runs in a Windows console without CYGWIN=tty)

The problem is that Cygwin retries CreateProcess() if process aborts with an unknown 0xc0000XXXX exit code also for non-Cygwin programs. The attached patch fixes this.

Christian

2011-06-23  Christian Franke  <franke@computer.org>

	* sigproc.cc (child_info::sync): Add exit_code to debug
	message.
	(child_info::proc_retry): Don't retry on unknown exit_code
	from non-cygwin programs.

diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 2f42db2..1e57876 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -883,7 +883,8 @@ child_info::sync (pid_t pid, HANDLE& hProcess, DWORD howlong)
 	      hProcess = NULL;
 	    }
 	}
-      sigproc_printf ("pid %u, WFMO returned %d, res %d", pid, x, res);
+      sigproc_printf ("pid %u, WFMO returned %d, exit_code 0x%x, res %d",
+		      pid, x, exit_code, res);
     }
   return res;
 }
@@ -915,11 +916,11 @@ child_info::proc_retry (HANDLE h)
     case EXITCODE_FORK_FAILED: /* windows prevented us from forking */
       break;
 
-    /* Count down non-recognized exit codes more quickly since they aren't
-       due to known conditions.  */
     default:
-      if (!iscygwin () && (exit_code & 0xffff0000) != 0xc0000000)
+      if (!iscygwin ())
 	break;
+      /* Count down non-recognized exit codes more quickly since they aren't
+         due to known conditions.  */
       if ((retry -= 2) < 0)
 	retry = 0;
       else

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