OpenJDK / amber / amber
changeset 56823:8d50ff464ae5
8226242: Diagnostic output for posix_spawn failure
Reviewed-by: bpb, stuefe, dholmes, martin
author | rriggs |
---|---|
date | Tue, 18 Jun 2019 10:37:28 -0400 |
parents | b78af6d8a252 |
children | 8259c22be42c |
files | src/java.base/unix/native/libjava/ProcessImpl_md.c |
diffstat | 1 files changed, 28 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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;