From: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx> This is cleaner and also fixes issues in Android where /tmp does not exist. With this, host-guest tracing works on Android VM running on ChromeOS Linux. Link: https://lore.kernel.org/linux-trace-devel/20220405192204.1551283-1-joel@xxxxxxxxxxxxxxxxx Signed-off-by: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- lib/trace-cmd/include/private/trace-cmd-private.h | 2 -- lib/trace-cmd/trace-msg.c | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 766e0a762c2b..0efc2a1c4850 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -381,7 +381,6 @@ enum tracecmd_msg_flags { }; /* for both client and server */ -#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX" struct tracecmd_msg_handle { int fd; short cpu_count; @@ -390,7 +389,6 @@ struct tracecmd_msg_handle { bool done; bool cache; int cfd; - char cfile[sizeof(MSG_CACHE_FILE)]; }; struct tracecmd_tsync_protos { diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index 39465ade8ab3..5ba2eeb2d183 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -19,6 +19,7 @@ #include <string.h> #include <unistd.h> #include <arpa/inet.h> +#include <sys/mman.h> #include <sys/types.h> #include <linux/types.h> @@ -590,11 +591,9 @@ 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) { - strcpy(msg_handle->cfile, MSG_CACHE_FILE); - msg_handle->cfd = mkstemp(msg_handle->cfile); + msg_handle->cfd = memfd_create("trace_msg_cache", 0); if (msg_handle->cfd < 0) return -1; - unlink(msg_handle->cfile); } msg_handle->cache = true; return 0; -- 2.35.1