Skip to content

Commit

Permalink
Fix: Created a unique file under tmp dir
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <[email protected]>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 5, 2024
1 parent 6d91778 commit 17bacf7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions events/syscall/container_drift_detected_open_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 17bacf7

Please sign in to comment.