-
Notifications
You must be signed in to change notification settings - Fork 316
Service discovery - remove dependency on memfd_create #9913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
54623c4
353ebe0
1bd59c4
d763cd0
f784c67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package datadog.trace.agent.tooling.servicediscovery; | ||
|
|
||
| import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY; | ||
|
|
||
| import com.sun.jna.Library; | ||
| import com.sun.jna.Memory; | ||
| import com.sun.jna.Native; | ||
|
|
@@ -13,7 +15,7 @@ public class MemFDUnixWriter implements ForeignMemoryWriter { | |
| private static final Logger log = LoggerFactory.getLogger(MemFDUnixWriter.class); | ||
|
|
||
| private interface LibC extends Library { | ||
| int memfd_create(String name, int flags); | ||
| int syscall(int number, Object... args); | ||
|
|
||
| NativeLong write(int fd, Pointer buf, NativeLong count); | ||
|
|
||
|
|
@@ -36,7 +38,13 @@ private interface LibC extends Library { | |
| public void write(String fileName, byte[] payload) { | ||
| final LibC libc = Native.load("c", LibC.class); | ||
|
|
||
| int memFd = libc.memfd_create(fileName, MFD_CLOEXEC | MFD_ALLOW_SEALING); | ||
| String arch = System.getProperty("os.arch"); | ||
| int memfdSyscall = getMemfdSyscall(arch); | ||
| if (memfdSyscall <= 0) { | ||
| log.debug(SEND_TELEMETRY, "service discovery not supported for arch={}", arch); | ||
| return; | ||
| } | ||
| int memFd = libc.syscall(memfdSyscall, fileName, MFD_CLOEXEC | MFD_ALLOW_SEALING); | ||
| if (memFd < 0) { | ||
| log.warn("{} memfd create failed, errno={}", fileName, Native.getLastError()); | ||
| return; | ||
|
|
@@ -60,4 +68,30 @@ public void write(String fileName, byte[] payload) { | |
| } | ||
| // memfd is not closed to keep it readable for the lifetime of the process. | ||
| } | ||
|
|
||
| private static int getMemfdSyscall(String arch) { | ||
| switch (arch.toLowerCase()) { | ||
| case "x86_64": | ||
|
||
| case "x64": | ||
| case "amd64": | ||
| // https://elixir.bootlin.com/musl/v1.2.5/source/arch/x86_64/bits/syscall.h.in#L320 | ||
raphaelgavache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return 319; | ||
| case "x386": | ||
| // https://elixir.bootlin.com/musl/v1.2.5/source/arch/i386/bits/syscall.h.in#L356 | ||
|
||
| return 356; | ||
| case "aarch64": | ||
| case "arm64": | ||
| // https://elixir.bootlin.com/musl/v1.2.5/source/arch/aarch64/bits/syscall.h.in#L264 | ||
| return 279; | ||
| case "arm": | ||
| case "arm32": | ||
| // https://elixir.bootlin.com/musl/v1.2.5/source/arch/arm/bits/syscall.h.in#L343 | ||
| return 385; | ||
| case "ppc64": | ||
| // https://elixir.bootlin.com/musl/v1.2.5/source/arch/powerpc64/bits/syscall.h.in#L350 | ||
| return 360; | ||
raphaelgavache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| default: | ||
| return -1; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.