Skip to content

Commit

Permalink
Create /dev/shm if not exists and Remove debris at end
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 5, 2024
1 parent 13276c2 commit 4489ba0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion events/syscall/execution_from_dev_shm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ func ExecutionFromDevShm(h events.Helper) error {
scriptPath := "/dev/shm/example_script-created-by-falco-event-generator.sh"
scriptContent := "#!/bin/bash\n echo 'hello world'"

// Check if /dev exists
if _, err := os.Stat("/dev"); os.IsNotExist(err) {
if err := os.Mkdir("/dev/shm", 0755); err != nil {
return err
}
defer os.RemoveAll("/dev") // Remove dev directory
}

// Given /dev exists check if /shm exists
if _, err := os.Stat("/dev/shm"); os.IsNotExist(err) {
if err := os.Mkdir("/dev/shm", 0755); err != nil {
return err
}
defer os.RemoveAll("/dev/shm") // Remove /shm directory only
}

if err := os.WriteFile(scriptPath, []byte(scriptContent), 0755); err != nil {
return err
}
Expand All @@ -37,6 +53,6 @@ func ExecutionFromDevShm(h events.Helper) error {
}

cmd := exec.Command("sh", "-c", "cd /dev/shm/ && ./example_script-created-by-falco-event-generator.sh")
defer os.Remove(scriptPath)
defer os.Remove(scriptPath) // Remove script file
return cmd.Run()
}

0 comments on commit 4489ba0

Please sign in to comment.