Skip to content

Commit

Permalink
Refactor: Create a unique temp directory and changed function name
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 4, 2024
1 parent a973e7a commit 179be5f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions events/syscall/clear_log_activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ package syscall

import (
"os"
"path/filepath"

"github.com/falcosecurity/event-generator/events"
)

var _ = events.Register(ClearLogActivites)
var _ = events.Register(ClearLogActivities)

func ClearLogActivites(h events.Helper) error {
filename := "/created-by-event-generator/syslog"

if err := os.Mkdir("/created-by-event-generator", 0755); err != nil {
h.Log().WithError(err).Error("Error creating directory")
func ClearLogActivities(h events.Helper) error {
// Create a unique temp directory
tempDirectoryName, err := os.MkdirTemp("/", "falco-event-generator-")
if err != nil {
return err
}
defer os.RemoveAll("/created-by-event-generator")
defer os.RemoveAll(tempDirectoryName)

filename := filepath.Join(tempDirectoryName, "syslog")

// Open or create the file with write-only access and truncate its contents if it exists
file, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
Expand Down

0 comments on commit 179be5f

Please sign in to comment.