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:
Anonymous 2011-08-15 07:12:52 -06:00 committed by Joel Dice
parent 1c59aa51d8
commit 16aa5c3d59
2 changed files with 7 additions and 5 deletions

View File

@ -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;
}

View File

@ -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]);
}