Skip to content

Commit f4ebc5a

Browse files
committed
fix forbidden
1 parent 7e38ff7 commit f4ebc5a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.core.AbstractRefCounted;
3333
import org.elasticsearch.core.CheckedConsumer;
3434
import org.elasticsearch.core.IOUtils;
35-
import org.elasticsearch.core.PathUtils;
3635
import org.elasticsearch.core.SuppressForbidden;
3736
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
3837
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
@@ -483,16 +482,7 @@ static void initializeNatives(final Path tmpFile, final boolean mlockAll, final
483482
}
484483

485484
if (IOUtils.LINUX) {
486-
// The coredump filter determines which types of memory are added to core dumps. By default, Java
487-
// includes memory mapped files, bits 2 and 3. Here we disable those bits. Note that the VM
488-
// has special options to disable these, but the filter is then inherited from the parent process
489-
// which is the server CLI, which is also a JVM so it has these bits set. Thus, we set it explicitly.
490-
// See https://man7.org/linux/man-pages/man5/core.5.html for more info on the relevant bits of the filter
491-
try {
492-
Files.writeString(PathUtils.get("/proc/self/coredump_filter"), "0x23");
493-
} catch (IOException e) {
494-
throw new RuntimeException("Could not set coredump filter", e);
495-
}
485+
setCoredumpFilter();
496486
}
497487

498488
// init lucene random seed. it will use /dev/urandom where available:
@@ -609,6 +599,20 @@ static Map<String, Set<String>> findPluginsWithNativeAccess(Map<String, Policy>
609599
return pluginsWithNativeAccess;
610600
}
611601

602+
@SuppressForbidden(reason = "access proc filesystem")
603+
private static void setCoredumpFilter() {
604+
// The coredump filter determines which types of memory are added to core dumps. By default, Java
605+
// includes memory mapped files, bits 2 and 3. Here we disable those bits. Note that the VM
606+
// has special options to disable these, but the filter is then inherited from the parent process
607+
// which is the server CLI, which is also a JVM so it has these bits set. Thus, we set it explicitly.
608+
// See https://man7.org/linux/man-pages/man5/core.5.html for more info on the relevant bits of the filter
609+
try {
610+
Files.writeString(Path.of("/proc/self/coredump_filter"), "0x23");
611+
} catch (IOException e) {
612+
throw new RuntimeException("Could not set coredump filter", e);
613+
}
614+
}
615+
612616
// -- instance
613617

614618
private static volatile Elasticsearch INSTANCE;

0 commit comments

Comments
 (0)