Skip to content

Commit 9640c7f

Browse files
committed
Check for dir and put path in a variable
Tip from @mrnoname1000 that we should be checking this is a dir, since dir will also show up as executable but then fail to run as a command.
1 parent b805398 commit 9640c7f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

unixlauncher.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@ int UnixLauncher::run(int argc, char* argv[], char* envp[]) {
7171

7272
// still no jdk home, use other means to resolve it
7373
if (jdkhome.empty()) {
74-
if (access("/usr/libexec/java_home", X_OK) != -1) {
74+
char javaHomeCommand[] = "/usr/libexec/java_home";
75+
if (access(javaHomeCommand, X_OK) != -1 && !checkDirectory(javaHomeCommand)) {
7576
// try java_home command when not set (on MacOS)
7677
FILE *fp;
7778
char tmp[PATH_MAX + 1];
7879

79-
fp = popen("/usr/libexec/java_home", "r");
80+
fp = popen(javaHomeCommand, "r");
8081
if (fp != NULL) {
8182
fgets(tmp, sizeof(tmp), fp);
8283
tmp[strcspn(tmp, "\n")] = 0;
8384
jdkhome = tmp;
8485
pclose(fp);
8586
} else {
86-
logErr(true, false, "failed to run /usr/libexec/java_home");
87+
logErr(true, false, "failed to run %s", javaHomeCommand);
8788
}
8889
} else {
8990
java = resolveSymlinks(java);

0 commit comments

Comments
 (0)