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

Sending SIGINT to app so app can invoke any registered signal handlers #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion refresh/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"
)

func (m *Manager) runner() {
Expand All @@ -17,7 +18,10 @@ func (m *Manager) runner() {
// kill the previous command
pid := cmd.Process.Pid
m.Logger.Success("Stopping: PID %d", pid)
cmd.Process.Kill()
if err := cmd.Process.Signal(syscall.SIGINT); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to work on Windows? From the docs:

func (*Process) Signal: Signal sends a signal to the Process. Sending Interrupt on Windows is not implemented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On windows, it should return an error. On error, this defaults to Process.Kill(). Unfortunately i do not have a windows box to test.

from exec_windows.go

func (p *Process) signal(sig Signal) error {
handle := atomic.LoadUintptr(&p.handle)
if handle == uintptr(syscall.InvalidHandle) {
return syscall.EINVAL
}
if p.done() {
return errors.New("os: process already finished")
}
if sig == Kill {
return terminateProcess(p.Pid, 1)
}
// TODO(rsc): Handle Interrupt too?
return syscall.Errno(syscall.EWINDOWS)
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bketelsen do you still have a windows box? If so, could you try this PR on it to make sure it works?

// If SIGINT fails, default to force Kill
cmd.Process.Kill()
}
}
if m.Debug {
bp := m.FullBuildPath()
Expand Down