8226242: Diagnostic output for posix_spawn failure
Reviewed-by: bpb, stuefe, dholmes, martin
--- a/src/java.base/unix/native/libjava/ProcessImpl_md.c Tue Jun 18 14:52:36 2019 +0100
+++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c Tue Jun 18 10:37:28 2019 -0400
@@ -354,6 +354,27 @@
free(errmsg);
}
+/**
+ * Throws an IOException with a message composed from the result of waitpid status.
+ */
+static void throwExitCause(JNIEnv *env, int pid, int status) {
+ char ebuf[128];
+ if (WIFEXITED(status)) {
+ snprintf(ebuf, sizeof ebuf,
+ "Failed to exec spawn helper: pid: %d, exit value: %d",
+ pid, WEXITSTATUS(status));
+ } else if (WIFSIGNALED(status)) {
+ snprintf(ebuf, sizeof ebuf,
+ "Failed to exec spawn helper: pid: %d, signal: %d",
+ pid, WTERMSIG(status));
+ } else {
+ snprintf(ebuf, sizeof ebuf,
+ "Failed to exec spawn helper: pid: %d, status: 0x%08x",
+ pid, status);
+ }
+ throwIOException(env, 0, ebuf);
+}
+
#ifdef DEBUG_PROCESS
/* Debugging process code is difficult; where to write debug output? */
static void
@@ -690,9 +711,12 @@
if (c->sendAlivePing) {
switch(readFully(fail[0], &errnum, sizeof(errnum))) {
case 0: /* First exec failed; */
- waitpid(resultPid, NULL, 0);
- throwIOException(env, 0, "Failed to exec spawn helper.");
- goto Catch;
+ {
+ int tmpStatus = 0;
+ int p = waitpid(resultPid, &tmpStatus, 0);
+ throwExitCause(env, p, tmpStatus);
+ goto Catch;
+ }
case sizeof(errnum):
assert(errnum == CHILD_IS_ALIVE);
if (errnum != CHILD_IS_ALIVE) {
@@ -700,7 +724,7 @@
* helper should do is to send an alive ping to the parent,
* before doing any subsequent work. */
throwIOException(env, 0, "Bad code from spawn helper "
- "(Failed to exec spawn helper.");
+ "(Failed to exec spawn helper)");
goto Catch;
}
break;