diff --git a/helper/testtask/testtask.go b/helper/testtask/testtask.go index 0152e3be2..fa8bc0cd0 100644 --- a/helper/testtask/testtask.go +++ b/helper/testtask/testtask.go @@ -7,8 +7,6 @@ import ( "io/ioutil" "os" "os/exec" - "strconv" - "syscall" "time" "github.com/hashicorp/nomad/nomad/structs" @@ -115,21 +113,11 @@ func execute() { ioutil.WriteFile(file, []byte(msg), 0666) case "pgrp": - // pgrp puts the pid in a new process group if len(args) < 1 { fmt.Fprintln(os.Stderr, "expected process group number for pgrp") os.Exit(1) } - num := popArg() - grp, err := strconv.Atoi(num) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to convert process group number %q: %v\n", num, err) - os.Exit(1) - } - if err := syscall.Setpgid(0, grp); err != nil { - fmt.Fprintf(os.Stderr, "failed to set process group: %v\n", err) - os.Exit(1) - } + executeProcessGroup(popArg()) case "fork/exec": // fork/exec forks execs the helper process diff --git a/helper/testtask/testtask_unix.go b/helper/testtask/testtask_unix.go new file mode 100644 index 000000000..6b17a7a43 --- /dev/null +++ b/helper/testtask/testtask_unix.go @@ -0,0 +1,23 @@ +// +build unix + +package testtask + +import ( + "fmt" + "os" + "strconv" + "syscall" +) + +func executeProcessGroup(gid string) { + // pgrp puts the pid in a new process group + grp, err := strconv.Atoi(gid) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to convert process group number %q: %v\n", gid, err) + os.Exit(1) + } + if err := syscall.Setpgid(0, grp); err != nil { + fmt.Fprintf(os.Stderr, "failed to set process group: %v\n", err) + os.Exit(1) + } +} diff --git a/helper/testtask/testtask_windows.go b/helper/testtask/testtask_windows.go new file mode 100644 index 000000000..64717665f --- /dev/null +++ b/helper/testtask/testtask_windows.go @@ -0,0 +1,13 @@ +// +build windows + +package testtask + +import ( + "fmt" + "os" +) + +func executeProcessGroup(gid string) { + fmt.Fprintf(os.Stderr, "process groups are not supported on windows\n") + os.Exit(1) +}