Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore SIGINT while running child process #58

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
test:
@go test -cover ./...

.PHONY: dist
dist:
@gox \
--osarch "!darwin/386" \
--osarch "darwin/amd64 darwin/arm64 linux/amd64 linux/arm" \
--output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
rm dist/*.gz
ls dist/* | while read i; do gzip $$i; done

clean:
rm -fr dist
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/tj/robo/config"
)

var version = "0.7.0"
var version = "0.7.0-cgamesplay"

const usage = `
Usage:
Expand Down
16 changes: 14 additions & 2 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
Expand Down Expand Up @@ -89,6 +90,17 @@ func (r *Runnable) Run(lookupPath string, args []string, env []string) error {
return fmt.Errorf("nothing to run (add script, command, or exec key)")
}

func (r *Runnable) runInternal(cmd *exec.Cmd) error {
if err := cmd.Start(); err != nil {
return err
}
// Ignore SIGINT while waiting for a child process. The child process will
// receive the signal and abort normally, then we will continue.
signal.Ignore(os.Interrupt);
defer signal.Reset(os.Interrupt);
return cmd.Wait();
}

// RunScript runs the target shell `script` file.
func (r *Runnable) RunScript(lookupPath string, args []string, env []string) error {
var path = r.Script
Expand All @@ -114,7 +126,7 @@ func (r *Runnable) RunScript(lookupPath string, args []string, env []string) err
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
return r.runInternal(cmd)
}

// RunCommand runs the `command` via the shell.
Expand All @@ -125,7 +137,7 @@ func (r *Runnable) RunCommand(args []string, env []string) error {
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
return r.runInternal(cmd)
}

// RunExec runs the `exec` command.
Expand Down