diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index ca3c30bcd8..24ccb16760 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -36,6 +36,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes: * Restore compatibility with Java 7 - {pull}3657[#3657] * Avoid `ClassCastException` and issue warning when trying to use otel span links - {pull}3672[#3672] * Avoid `NullPointerException` with runtime attach API and invalid map entries - {pull}3712[#3712] +* Skips using NOFOLLOW_LINKS file open option when running on z/OS as it's unsupported there - {pull}3722[#3722] [float] ===== Features diff --git a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java index 521659f9ce..d1b905b95a 100644 --- a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java +++ b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java @@ -25,7 +25,8 @@ public class JvmRuntimeInfo { private static final JvmRuntimeInfo CURRENT_VM = new JvmRuntimeInfo(System.getProperty("java.version"), - System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version")); + System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version"), + System.getProperty("os.name")); private final String javaVersion; private final String javaVmName; @@ -37,6 +38,7 @@ public class JvmRuntimeInfo { private final boolean isJ9; private final boolean isHpUx; private final boolean isCoretto; + private final boolean isZos; public static JvmRuntimeInfo ofCurrentVM() { return CURRENT_VM; @@ -52,6 +54,10 @@ public static JvmRuntimeInfo ofCurrentVM() { * @param vmVersion jvm version, from {@code System.getProperty("java.vm.version")} */ public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion) { + this(version, vmName, vendorName, vmVersion, null); + } + + private JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion, @Nullable String osName) { javaVersion = version; javaVmName = vmName; javaVmVersion = vmVersion; @@ -61,6 +67,7 @@ public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullabl isJ9 = vmName.contains("J9"); isHpUx = version.endsWith("-hp-ux"); isCoretto = vendorName != null && vendorName.contains("Amazon"); + isZos = (osName != null) && osName.toLowerCase().contains("z/os"); if (isHpUx) { // remove extra hp-ux suffix for parsing @@ -162,6 +169,10 @@ public boolean isCoretto() { return isCoretto; } + public boolean isZos() { + return isZos; + } + @Override public String toString() { return String.format("%s %s %s", javaVersion, javaVmName, javaVmVersion); diff --git a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java index 9cfec464ab..fcb4177ad3 100644 --- a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java +++ b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.common.util; +import co.elastic.apm.agent.common.JvmRuntimeInfo; + import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; @@ -99,7 +101,9 @@ public static synchronized Path extractResourceToDirectory(String resource, Stri } } } catch (FileAlreadyExistsException e) { - try (FileChannel channel = FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) { + try (FileChannel channel = JvmRuntimeInfo.ofCurrentVM().isZos() ? + FileChannel.open(tempFile, READ) : + FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) { // wait until other JVM instances have fully written the file // multiple JVMs can read the file at the same time try (FileLock readLock = channel.lock(0, Long.MAX_VALUE, true)) {