Merge pull request #8 from jesseduffield/nil-pointer

Fix bug with hanging app on startup
This commit is contained in:
Jesse Duffield 2019-06-30 18:34:25 +10:00 committed by GitHub
commit 9c8c88e939
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 9 deletions

4
Gopkg.lock generated
View file

@ -155,11 +155,11 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e0306e92cef41d02af05a9f88395ec49c94f0255d54ca88ee3c02ae8f5806ee3" digest = "1:7c71e4035e802da25ad590ae5f1cb0e931b2b4806aa0b5539d53c02a1cf6a64d"
name = "github.com/jesseduffield/termbox-go" name = "github.com/jesseduffield/termbox-go"
packages = ["."] packages = ["."]
pruneopts = "NUT" pruneopts = "NUT"
revision = "a9796224c07f5d757b399082bfee60de9574a2d9" revision = "9dd53af7214ead48bbe380cdf8a3229ec43eeb58"
[[projects]] [[projects]]
branch = "v2" branch = "v2"

View file

@ -48,7 +48,3 @@
[[constraint]] [[constraint]]
branch = "v2" branch = "v2"
name = "github.com/jesseduffield/yaml" name = "github.com/jesseduffield/yaml"
[[constraint]]
branch = "master"
name = "github.com/jesseduffield/roll"

View file

@ -370,6 +370,10 @@ func (c *OSCommand) PipeCommands(commandStrings ...string) error {
// Kill kills a process. If the process has Setpgid == true, then we have anticipated that it might spawn its own child processes, so we've given it a process group ID (PGID) equal to its process id (PID) and given its child processes will inherit the PGID, we can kill that group, rather than killing the process itself. // Kill kills a process. If the process has Setpgid == true, then we have anticipated that it might spawn its own child processes, so we've given it a process group ID (PGID) equal to its process id (PID) and given its child processes will inherit the PGID, we can kill that group, rather than killing the process itself.
func (c *OSCommand) Kill(cmd *exec.Cmd) error { func (c *OSCommand) Kill(cmd *exec.Cmd) error {
if cmd.Process == nil {
// somebody got to it before we were able to, poor bastard
return nil
}
if cmd.SysProcAttr != nil && cmd.SysProcAttr.Setpgid == true { if cmd.SysProcAttr != nil && cmd.SysProcAttr.Setpgid == true {
// minus sign means we're talking about a PGID as opposed to a PID // minus sign means we're talking about a PGID as opposed to a PID
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)

View file

@ -193,7 +193,9 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error {
go func() { go func() {
<-stop <-stop
cmd.Process.Kill() if err := gui.OSCommand.Kill(cmd); err != nil {
gui.Log.Warn(err)
}
gui.Log.Info("killed container logs process") gui.Log.Info("killed container logs process")
return return
}() }()

View file

@ -22,6 +22,8 @@ import "time"
// } // }
// defer termbox.Close() // defer termbox.Close()
func Init() error { func Init() error {
quitPolling = make(chan int)
var err error var err error
out, err = os.OpenFile("/dev/tty", syscall.O_WRONLY, 0) out, err = os.OpenFile("/dev/tty", syscall.O_WRONLY, 0)
@ -120,7 +122,7 @@ func Interrupt() {
// when termbox's functionality isn't required anymore. // when termbox's functionality isn't required anymore.
func Close() { func Close() {
quit <- 1 quit <- 1
quitPolling <- 1 close(quitPolling)
out.WriteString(funcs[t_show_cursor]) out.WriteString(funcs[t_show_cursor])
out.WriteString(funcs[t_sgr0]) out.WriteString(funcs[t_sgr0])
out.WriteString(funcs[t_clear_screen]) out.WriteString(funcs[t_clear_screen])

View file

@ -77,7 +77,7 @@ var (
sigwinch = make(chan os.Signal, 1) sigwinch = make(chan os.Signal, 1)
sigio = make(chan os.Signal, 1) sigio = make(chan os.Signal, 1)
quit = make(chan int) quit = make(chan int)
quitPolling = make(chan int) quitPolling chan int // get set on each initialize
input_comm = make(chan input_event) input_comm = make(chan input_event)
interrupt_comm = make(chan struct{}) interrupt_comm = make(chan struct{})
intbuf = make([]byte, 0, 16) intbuf = make([]byte, 0, 16)