Skip to content

Commit

Permalink
Refactor: Just set execute permission on empty file is enough trigger…
Browse files Browse the repository at this point in the history
… the rule

Signed-off-by: GLVS Kiriti <[email protected]>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 4, 2024
1 parent a33421a commit 2925790
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions events/syscall/container_drift_detected_chmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@ var _ = events.Register(

func ContainerDriftDetcted(h events.Helper) error {
if h.InContainer() {
// Shell script content
scriptContent := `#!/bin/bash
echo "Hello World"
`

scriptFileName := "temp_script.sh"
if err := os.WriteFile(scriptFileName, []byte(scriptContent), 0755); err != nil {
h.Log().WithError(err).Error("Error writing script file")
filename := "/created-by-event-generator"
if err := os.WriteFile(filename, nil, 0755); err != nil {
h.Log().WithError(err).Error("Error creating an empty file")
return err
}
defer os.Remove(scriptFileName) // Remove file after function return
defer os.Remove(filename) // Remove file after function return

// Set execute permission on script file to make it executable
if err := os.Chmod(scriptFileName, 0755); err != nil {
if err := os.Chmod(filename, 0755); err != nil {
h.Log().WithError(err).Error("Error setting execute permission on script file")
return err
}
Expand Down

0 comments on commit 2925790

Please sign in to comment.