This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] Prevent restart of crashing non-Cygwin exe
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin-patches at cygwin dot com
- Date: Thu, 23 Jun 2011 19:52:40 +0200
- Subject: [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