Skip to content

Commit dab1c21

Browse files
Vladimir PetkoDavid Holmes
Vladimir Petko
authored and
David Holmes
committedSep 10, 2023
8314491: Linux: jexec launched via PATH fails to find java
Reviewed-by: dholmes, rriggs
1 parent 9a83d55 commit dab1c21

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed
 

‎src/java.base/unix/native/launcher/jexec.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -168,7 +168,16 @@ int main(int argc, const char * argv[]) {
168168

169169
/* Get the path to the java binary, which is in a known position relative
170170
* to our current position, which is in argv[0]. */
171-
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
171+
int error = getJavaPath(argv[argi++], java, RELATIVE_DEPTH);
172+
#ifdef __linux__
173+
/* Try to read the symbolic link to the current binary
174+
* if the java path can not be resolved from argv[0]. */
175+
if (error != 0) {
176+
error = getJavaPath("/proc/self/exe", java, RELATIVE_DEPTH);
177+
}
178+
#endif
179+
180+
if (error != 0) {
172181
errorExit(errno, MISSING_JAVA_MSG);
173182
}
174183
alen = (argc + 2) * (sizeof (const char *));

‎test/jdk/tools/launcher/Jexec.java

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,14 +23,16 @@
2323

2424
/*
2525
* @test
26-
* @bug 8175000
26+
* @bug 8175000 8314491
2727
* @summary test jexec
28+
* @requires os.family == "linux"
2829
* @build TestHelper
2930
* @run main Jexec
3031
*/
3132

3233
import java.io.File;
3334
import java.io.IOException;
35+
import java.nio.file.Path;
3436

3537
public class Jexec extends TestHelper {
3638
private final File testJar;
@@ -54,20 +56,12 @@ public class Jexec extends TestHelper {
5456
}
5557

5658
public static void main(String... args) throws Exception {
57-
// linux is the only supported platform, give the others a pass
58-
if (!isLinux) {
59-
System.err.println("Warning: unsupported platform test passes vacuously");
60-
return;
61-
}
62-
// ok to run the test now
6359
Jexec t = new Jexec();
6460
t.run(null);
6561
}
6662

67-
@Test
68-
void jexec() throws Exception {
69-
TestResult tr = doExec(jexecCmd.getAbsolutePath(),
70-
testJar.getAbsolutePath(), message);
63+
private void runTest(String... cmds) throws Exception {
64+
TestResult tr = doExec(cmds);
7165
if (!tr.isOK()) {
7266
System.err.println(tr);
7367
throw new Exception("incorrect exit value");
@@ -77,4 +71,17 @@ void jexec() throws Exception {
7771
throw new Exception("expected message \'" + message + "\' not found");
7872
}
7973
}
74+
75+
@Test
76+
void jexec() throws Exception {
77+
runTest(jexecCmd.getAbsolutePath(),
78+
testJar.getAbsolutePath(), message);
79+
}
80+
81+
@Test
82+
void jexecInPath() throws Exception {
83+
Path jexec = Path.of(jexecCmd.getAbsolutePath());
84+
runTest("/bin/sh", "-c",
85+
String.format("PATH=%s ; jexec %s '%s'",jexec.getParent(), testJar.getAbsolutePath(), message));
86+
}
8087
}

0 commit comments

Comments
 (0)
Please sign in to comment.