From 17bacf7073c9fbdab980ecc65c41aa82bffc172f Mon Sep 17 00:00:00 2001 From: GLVS Kiriti Date: Fri, 5 Apr 2024 16:49:27 +0530 Subject: [PATCH] Fix: Created a unique file under tmp dir Signed-off-by: GLVS Kiriti --- .../syscall/container_drift_detected_open_create.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/events/syscall/container_drift_detected_open_create.go b/events/syscall/container_drift_detected_open_create.go index 7f8789fe..a55c7da7 100644 --- a/events/syscall/container_drift_detected_open_create.go +++ b/events/syscall/container_drift_detected_open_create.go @@ -27,10 +27,15 @@ var _ = events.Register( func ContainerDriftDetectedOpenCreate(h events.Helper) error { if h.InContainer() { - const filename = "created-by-event-generator" - h.Log().Infof("writing to %s", filename) - defer os.Remove(filename) - return os.WriteFile(filename, nil, os.FileMode(0755)) // Also set execute permission + // Create a unique file under tmp dir + file, err := os.CreateTemp(os.TempDir(), "created-by-falco-event-generator-") + if err != nil { + h.Log().WithError(err).Error("Error Creating an empty file") + return err + } + defer os.Remove(file.Name()) // Remove the file after function return + h.Log().Infof("writing to %s", file.Name()) + return os.WriteFile(file.Name(), nil, os.FileMode(0755)) // Also set execute permission } return nil }