Bug 23763 - Runtime.getRuntime().exec() signalling
Summary: Runtime.getRuntime().exec() signalling
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: 4.0.3
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks: 23758
  Show dependency treegraph
 
Reported: 2005-09-07 13:13 UTC by aeby
Modified: 2005-11-08 21:01 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.3
Known to fail: 4.0.0 4.0.1 4.0.2
Last reconfirmed: 2005-11-08 19:44:20


Attachments
Execs "exectest" and demonstrates how it hangs (191 bytes, text/plain)
2005-09-07 13:17 UTC, aeby
Details
Sample program that hangs when executed via Runtime.exec() (489 bytes, text/plain)
2005-09-07 13:18 UTC, aeby
Details
workaround: patch against GCC 4.0.1 unblocking SIGCHLD before execvp() (430 bytes, patch)
2005-09-15 14:27 UTC, aeby
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description aeby 2005-09-07 13:13:32 UTC
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.
Comment 1 aeby 2005-09-07 13:17:14 UTC
Created attachment 9686 [details]
Execs "exectest" and demonstrates how it hangs
Comment 2 aeby 2005-09-07 13:18:21 UTC
Created attachment 9687 [details]
Sample program that hangs when executed via Runtime.exec()
Comment 3 Andrew Pinski 2005-09-10 02:20:57 UTC
This is might be the same problem as described in PR 23758.
Comment 4 aeby 2005-09-15 14:24:59 UTC
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? :-))
Comment 5 aeby 2005-09-15 14:27:02 UTC
Created attachment 9734 [details]
workaround: patch against GCC 4.0.1 unblocking SIGCHLD before execvp()
Comment 6 aeby 2005-10-26 08:48:22 UTC
I have just tested against 4.0.2 and the bug is still there (no surprise, of course).
Comment 7 Tom Tromey 2005-10-26 09:01:05 UTC
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.
Comment 8 aeby 2005-10-26 18:04:58 UTC
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 :-)
Comment 9 Tom Tromey 2005-11-08 19:44:20 UTC
I'm handling this.
Comment 10 Tom Tromey 2005-11-08 20:59:28 UTC
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

Comment 11 Tom Tromey 2005-11-08 21:00:20 UTC
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

Comment 12 Tom Tromey 2005-11-08 21:01:45 UTC
Fix checked in.