@@ -184,6 +184,15 @@ endef
# have flush/fua block layer instead of barriers?
blk-flags := $(call test-build,$(BLK_TC_FLUSH_SOURCE),-DHAVE_BLK_TC_FLUSH)
+define MEMFD_CREATE_SOURCE
+#define _GNU_SOURCE
+#include <sys/mman.h>
+int main(void) { return memfd_create(\"test\", 0); }
+endef
+
+# have memfd_create available
+memfd-flags := $(call test-build,$(MEMFD_CREATE_SOURCE),-DHAVE_MEMFD_CREATE)
+
ifeq ("$(origin O)", "command line")
saved-output := $(O)
@@ -363,7 +372,7 @@ endif
# Append required CFLAGS
override CFLAGS += $(INCLUDES) $(VAR_DIR)
override CFLAGS += $(PLUGIN_DIR_TRACECMD_SQ)
-override CFLAGS += $(udis86-flags) $(blk-flags)
+override CFLAGS += $(udis86-flags) $(blk-flags) $(memfd-flags)
override LDFLAGS += $(udis86-ldflags)
CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
@@ -380,6 +380,8 @@ enum tracecmd_msg_flags {
TRACECMD_MSG_FL_USE_VSOCK = 1 << 1,
};
+#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX"
+
/* for both client and server */
struct tracecmd_msg_handle {
int fd;
@@ -389,6 +391,9 @@ struct tracecmd_msg_handle {
bool done;
bool cache;
int cfd;
+#ifndef HAVE_MEMFD_CREATE
+ char cfile[sizeof(MSG_CACHE_FILE)];
+#endif
};
struct tracecmd_tsync_protos {
@@ -591,9 +591,17 @@ tracecmd_msg_handle_alloc(int fd, unsigned long flags)
int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle)
{
if (msg_handle->cfd < 0) {
+#ifdef HAVE_MEMFD_CREATE
msg_handle->cfd = memfd_create("trace_msg_cache", 0);
if (msg_handle->cfd < 0)
return -1;
+#else
+ strcpy(msg_handle->cfile, MSG_CACHE_FILE);
+ msg_handle->cfd = mkstemp(msg_handle->cfile);
+ if (msg_handle->cfd < 0)
+ return -1;
+ unlink(msg_handle->cfile);
+#endif
}
msg_handle->cache = true;
return 0;