Skip to content

Commit 0a94d47

Browse files
authored
z/OS avoids using NOFOLLOW_LINKS (#3722)
* z/OS avoids using NOFOLLOW_LINKS * add changelg entry for zos-no-follow-links
1 parent a6219bd commit 0a94d47

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
3636
* Restore compatibility with Java 7 - {pull}3657[#3657]
3737
* Avoid `ClassCastException` and issue warning when trying to use otel span links - {pull}3672[#3672]
3838
* Avoid `NullPointerException` with runtime attach API and invalid map entries - {pull}3712[#3712]
39+
* Skips using NOFOLLOW_LINKS file open option when running on z/OS as it's unsupported there - {pull}3722[#3722]
3940
4041
[float]
4142
===== Features

apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
public class JvmRuntimeInfo {
2626

2727
private static final JvmRuntimeInfo CURRENT_VM = new JvmRuntimeInfo(System.getProperty("java.version"),
28-
System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version"));
28+
System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version"),
29+
System.getProperty("os.name"));
2930

3031
private final String javaVersion;
3132
private final String javaVmName;
@@ -37,6 +38,7 @@ public class JvmRuntimeInfo {
3738
private final boolean isJ9;
3839
private final boolean isHpUx;
3940
private final boolean isCoretto;
41+
private final boolean isZos;
4042

4143
public static JvmRuntimeInfo ofCurrentVM() {
4244
return CURRENT_VM;
@@ -52,6 +54,10 @@ public static JvmRuntimeInfo ofCurrentVM() {
5254
* @param vmVersion jvm version, from {@code System.getProperty("java.vm.version")}
5355
*/
5456
public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion) {
57+
this(version, vmName, vendorName, vmVersion, null);
58+
}
59+
60+
private JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion, @Nullable String osName) {
5561
javaVersion = version;
5662
javaVmName = vmName;
5763
javaVmVersion = vmVersion;
@@ -61,6 +67,7 @@ public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullabl
6167
isJ9 = vmName.contains("J9");
6268
isHpUx = version.endsWith("-hp-ux");
6369
isCoretto = vendorName != null && vendorName.contains("Amazon");
70+
isZos = (osName != null) && osName.toLowerCase().contains("z/os");
6471

6572
if (isHpUx) {
6673
// remove extra hp-ux suffix for parsing
@@ -162,6 +169,10 @@ public boolean isCoretto() {
162169
return isCoretto;
163170
}
164171

172+
public boolean isZos() {
173+
return isZos;
174+
}
175+
165176
@Override
166177
public String toString() {
167178
return String.format("%s %s %s", javaVersion, javaVmName, javaVmVersion);

apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package co.elastic.apm.agent.common.util;
2020

21+
import co.elastic.apm.agent.common.JvmRuntimeInfo;
22+
2123
import java.io.IOException;
2224
import java.io.InputStream;
2325
import java.math.BigInteger;
@@ -99,7 +101,9 @@ public static synchronized Path extractResourceToDirectory(String resource, Stri
99101
}
100102
}
101103
} catch (FileAlreadyExistsException e) {
102-
try (FileChannel channel = FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) {
104+
try (FileChannel channel = JvmRuntimeInfo.ofCurrentVM().isZos() ?
105+
FileChannel.open(tempFile, READ) :
106+
FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) {
103107
// wait until other JVM instances have fully written the file
104108
// multiple JVMs can read the file at the same time
105109
try (FileLock readLock = channel.lock(0, Long.MAX_VALUE, true)) {

0 commit comments

Comments
 (0)