diff --git a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c index de85d917811..071be59504d 100644 --- a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c +++ b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -145,7 +144,6 @@ int main(int argc, char *argv[]) { struct stat buf; /* argv[1] contains the fd number to read all the child info */ int r, fdinr, fdinw, fdout; - sigset_t unblock_signals; #ifdef DEBUG jtregSimulateCrash(0, 4); @@ -173,10 +171,6 @@ int main(int argc, char *argv[]) { shutItDown(); } - // Reset any mask signals from parent - sigemptyset(&unblock_signals); - sigprocmask(SIG_SETMASK, &unblock_signals, NULL); - // Close the writing end of the pipe we use for reading from the parent. // We have to do this before we start reading from the parent to avoid // blocking in the case the parent exits before we finished reading from it. diff --git a/src/java.base/unix/native/libjava/childproc.c b/src/java.base/unix/native/libjava/childproc.c index 1543e269223..7a21b86565f 100644 --- a/src/java.base/unix/native/libjava/childproc.c +++ b/src/java.base/unix/native/libjava/childproc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -405,6 +406,13 @@ childProcess(void *arg) if (p->pdir != NULL && chdir(p->pdir) < 0) goto WhyCantJohnnyExec; + // Reset any mask signals from parent, but not in VFORK mode + if (p->mode != MODE_VFORK) { + sigset_t unblock_signals; + sigemptyset(&unblock_signals); + sigprocmask(SIG_SETMASK, &unblock_signals, NULL); + } + if (fcntl(FAIL_FILENO, F_SETFD, FD_CLOEXEC) == -1) goto WhyCantJohnnyExec; diff --git a/test/jdk/java/lang/ProcessBuilder/UnblockSignals.java b/test/jdk/java/lang/ProcessBuilder/UnblockSignals.java index 3f82bed8708..d2625518b6d 100644 --- a/test/jdk/java/lang/ProcessBuilder/UnblockSignals.java +++ b/test/jdk/java/lang/ProcessBuilder/UnblockSignals.java @@ -24,15 +24,27 @@ import java.io.IOException; /* - * @test - * @summary Verify Signal mask is cleared by ProcessBuilder start + * @test id=posix_spawn + * @summary Verify Signal mask is cleared by ProcessBuilder start when using posix_spawn mode * @bug 8234262 * @requires (os.family == "linux" | os.family == "mac") * @comment Don't allow -Xcomp, it disturbs the relative timing of the sleep and kill commands * @requires (vm.compMode != "Xcomp") - * @run main/othervm UnblockSignals - * @run main/othervm -Xrs UnblockSignals + * @run main/othervm -Djdk.lang.Process.launchMechanism=POSIX_SPAWN UnblockSignals + * @run main/othervm -Djdk.lang.Process.launchMechanism=POSIX_SPAWN -Xrs UnblockSignals */ + +/* + * @test id=fork + * @summary Verify Signal mask is cleared by ProcessBuilder start when using fork mode + * @bug 8357683 + * @requires (os.family == "linux" | os.family == "mac") + * @comment Don't allow -Xcomp, it disturbs the relative timing of the sleep and kill commands + * @requires (vm.compMode != "Xcomp") + * @run main/othervm -Djdk.lang.Process.launchMechanism=FORK UnblockSignals + * @run main/othervm -Djdk.lang.Process.launchMechanism=FORK -Xrs UnblockSignals + */ + public class UnblockSignals { public static void main(String[] args) throws IOException, InterruptedException { // Check that SIGQUIT is not masked, in previous releases it was masked