Showcase: compile exectest.c, run test.java calling 'exectest' Runtime.exec() seems to pass down some strange signal configuration to child processes in GCC >=4.0.0. When run from test.java the exectest.c parent process does never get CHLD signals - they seem to get blocked (as I've seen the rtsig-queue growing each time test.java was run). GCC 3.3.3 does not have this problem.
Created attachment 9686 [details] Execs "exectest" and demonstrates how it hangs
Created attachment 9687 [details] Sample program that hangs when executed via Runtime.exec()
This is might be the same problem as described in PR 23758.
I don't think this bug is linked with 23758. No matter if you call unsafe procedures before or after fork() SIGCHLD ist still blocked at the point where execvp() is called. It seems the posix-threads code does explicitly block SIGCHLD signals (block_sigchld() in libjava/posix-threads.cc) without unblocking them before calling execvp(). Therefore, the child process runs with SIGCHLD blocked, too. I'm attaching a dirty hack(?) fixing the problem for me (just sets signal handler for SIGCHLD to SIG_DFL and unblock SIGCHLD just before execvp()). BTW: Am I the only person in the world that is trying to exec() external programs from Java? :-))
Created attachment 9734 [details] workaround: patch against GCC 4.0.1 unblocking SIGCHLD before execvp()
I have just tested against 4.0.2 and the bug is still there (no surprise, of course).
Sorry for the delay on this. The patch looks reasonable enough to me. It needs a small amount of reformatting and a ChangeLog entry. Also I think the call to signal() is not needed, a custom handler is reset to the default on exec.
no problem ... I thought, resetting the signal handler to SIG_DFL before unblocking might be a good idea in the (not very probable) case a SIGCHLD signal is either in the signal queue or is otherwise received between sigprocmask() and exec(), just to be safe :-)
I'm handling this.
Subject: Bug 23763 Author: tromey Date: Tue Nov 8 20:59:20 2005 New Revision: 106654 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106654 Log: PR libgcj/23763. From aeby@graeff.com. * java/lang/natPosixProcess.cc (nativeSpawn): Unblock SIGCHLD before exec. Modified: branches/gcc-4_0-branch/libjava/ChangeLog branches/gcc-4_0-branch/libjava/java/lang/natPosixProcess.cc
Subject: Bug 23763 Author: tromey Date: Tue Nov 8 21:00:15 2005 New Revision: 106655 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106655 Log: PR libgcj/23763. From aeby@graeff.com. * java/lang/natPosixProcess.cc (nativeSpawn): Unblock SIGCHLD before exec. Modified: trunk/libjava/ChangeLog trunk/libjava/java/lang/natPosixProcess.cc
Fix checked in.