Skip to content

Commit

Permalink
Small improvements (pass tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-ismailaj committed Jun 12, 2022
1 parent a01d1da commit 271137d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions cmd/serf/command/agent/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,35 @@ func invokeEventScript(logger *log.Logger, script string, self serf.Member, even
output, _ := circbuf.NewBuffer(maxBufSize)

// Determine the shell invocation based on OS
var bin, flag, args string
var bin string
var args []string

if runtime.GOOS == windows {
bin = "cmd"
flag = "/C"
args = script
args = []string{"/C", script}
} else {
// If the script has a shebang, honor it.
// Otherwise, run with /bin/sh
bin = script

if f, err := os.Open(script); err == nil {
r := bufio.NewReader(bufio.NewReader(f))
r := bufio.NewReader(f)
for _, i := range []rune{'#', '!'} {
if r, _, _ := r.ReadRune(); r != i {
bin = "/bin/sh"
flag = "-c"
args = script
args = []string{"-c", script}
}
}
_ = f.Close()
} else {
logger.Printf("[DEBUG] agent: Event '%s' script could not be read. Assuming no shebang present.",
event.EventType().String())
bin = "/bin/sh"
flag = "-c"
args = script
args = []string{"-c", script}
}
}

cmd := exec.Command(bin, flag, args)
cmd := exec.Command(bin, args...)
cmd.Env = append(os.Environ(),
"SERF_EVENT="+event.EventType().String(),
"SERF_SELF_NAME="+self.Name,
Expand Down

0 comments on commit 271137d

Please sign in to comment.