mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
improve IOException message in the case of a Runtime.exec() failure
We now properly forward the errno value from the child when execvp() fails, which the parent then uses to for the errno message as well as including the failed command's name in the message.
This commit is contained in:
parent
1c59aa51d8
commit
16aa5c3d59
@ -411,8 +411,8 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
|
||||
execvp(argv[0], argv);
|
||||
|
||||
// Error if here
|
||||
char c = errno;
|
||||
ssize_t rv UNUSED = write(msg[1], &c, 1);
|
||||
int val = errno;
|
||||
ssize_t rv UNUSED = write(msg[1], &val, sizeof(val));
|
||||
exit(127);
|
||||
} break;
|
||||
|
||||
@ -425,12 +425,13 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
|
||||
safeClose(err[1]);
|
||||
safeClose(msg[1]);
|
||||
|
||||
char c;
|
||||
int r = read(msg[0], &c, 1);
|
||||
int val;
|
||||
int r = read(msg[0], &val, sizeof(val));
|
||||
if(r == -1) {
|
||||
throwNewErrno(e, "java/io/IOException");
|
||||
return;
|
||||
} else if(r) {
|
||||
errno = val;
|
||||
throwNewErrno(e, "java/io/IOException");
|
||||
return;
|
||||
}
|
||||
|
@ -103,7 +103,8 @@ public class Runtime {
|
||||
|
||||
if (exception[0] != null) {
|
||||
if (exception[0] instanceof IOException) {
|
||||
throw new IOException(exception[0]);
|
||||
String message = "Failed to run \"" + command[0] + "\": " + exception[0].getMessage();
|
||||
throw new IOException(message);
|
||||
} else {
|
||||
throw new RuntimeException(exception[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user