SleepyCat.java revision 0
844N/A * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A @bug 4843136 4763384 0N/A @summary Various race conditions caused exec'ed processes to have 0N/A extra unused file descriptors, which caused hard-to-reproduce hangs. 0N/A @author Martin Buchholz 0N/A // Time out was reproducible on Solaris 50% of the time; 0N/A // on Linux 80% of the time. 0N/A // Scenario: After fork(), parent executes and closes write end of child's stdin. 0N/A // This causes child to retain a write end of the same pipe. 0N/A // Thus the child will never see an EOF on its stdin, and will hang. 0N/A // Increasing the iteration count makes the bug more 0N/A // reproducible not only for the obvious reason, but also for 0N/A // slower, making the child more likely to win the race! 0N/A // Inspired by the imaginative test case for 0N/A // 4850368 (process) getInputStream() attaches to forked background processes (Linux) 0N/A // Time out was reproducible on Linux 80% of the time; 0N/A // never on Solaris because of explicit close in Solaris-specific code. 0N/A // Scenario: After fork(), the parent naturally closes the 0N/A // child's stdout write end. The child dup2's the write end 0N/A // of its stdout onto fd 1. On Linux, it fails to explicitly 0N/A // close the original fd, and because of the parent's close() 0N/A // of the fd, the child retains it. The child thus ends up 0N/A // with two copies of its stdout. Thus closing one of those 0N/A // write fds does not have the desired effect of causing an 0N/A // EOF on the parent's read end of that pipe. 0N/A // should get immediate EOF, but might hang 0N/A // Stream closed by sleeperExecutioner 0N/A // We will get here on non-Posix systems, 0N/A // which don't have cat and sleep and sh.