testtask: Build on windows

This commit is contained in:
Danielle Tomlinson 2019-01-09 00:34:02 +01:00
parent 2656f28f08
commit 96b1d5d20c
3 changed files with 37 additions and 13 deletions

View file

@ -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 <group_int> 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 <pid_file> <args> forks execs the helper process

View file

@ -0,0 +1,23 @@
// +build unix
package testtask
import (
"fmt"
"os"
"strconv"
"syscall"
)
func executeProcessGroup(gid string) {
// pgrp <group_int> 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)
}
}

View file

@ -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)
}