nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.67k stars 373 forks source link

termbox-go doesn't play nice with syscall.Exec #82

Open jangler opened 9 years ago

jangler commented 9 years ago

Something termbox sets up with O_ASYNC/SIGIO leaves a bad state for an exec(3)'d process. If the following program is invoked without command-line arguments, it (correctly) loops indefinitely. If it is invoked with arguments, it will crash after a few iterations, printing "I/O possible".

package main

import (
    "os"
    "syscall"
    "github.com/nsf/termbox-go"
)

func main() {
    if len(os.Args) > 1 {
        termbox.Init()
        termbox.Close()
    }
    syscall.Exec(os.Args[0], os.Args, syscall.Environ())
}

The problem is fixed by not setting the O_ASYNC flag in Init() (which is obviously not a workable solution), but it is not fixed by unsetting the flag in Close() and/or by using signal.Stop() on the SIGIO channel.

An equivalent C program does not have this problem.

My environment is go version 1.4.2, Linux kernel version 4.0.1.

nsf commented 9 years ago

Will definitely investigate. But I'm afraid it could be a Go problem and the way Go handles signals.

gdamore commented 9 years ago

Actually, I think that my changes in PR #99 might fix this. There really isn't any reason to require O_ASYNC or SIGIO with Go & goroutines. Can you please try it out?

ashcrow commented 6 years ago

This works for me with rev 5c94acc5e6eb520f1bcd183974e01171cc4c23b3 with the following code:

termbox.Close()
syscall.Exec("/bin/sh", []string{"sh"}, os.Environ())