mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
Only use stub when it is alive.
This commit is contained in:
parent
c67ad408ee
commit
6a80c3dcef
|
@ -180,7 +180,7 @@ func (ev *Evaler) EvalInteractive(text string, n *parse.Chunk) error {
|
|||
signal.Ignore(syscall.SIGTTIN)
|
||||
signal.Ignore(syscall.SIGTTOU)
|
||||
// XXX Should use fd of /dev/terminal instead of 0.
|
||||
if ev.Stub != nil && sys.IsATTY(0) {
|
||||
if ev.Stub != nil && ev.Stub.Alive() && sys.IsATTY(0) {
|
||||
ev.Stub.SetTitle(summarize(text))
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
|
|
@ -59,7 +59,7 @@ func (e ExternalCmd) Call(ec *EvalCtx, argVals []Value) {
|
|||
}
|
||||
|
||||
sys := syscall.SysProcAttr{}
|
||||
if ec.Stub != nil {
|
||||
if ec.Stub != nil && ec.Stub.Alive() {
|
||||
sys.Setpgid = true
|
||||
sys.Pgid = ec.Stub.Process().Pid
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ func Main() {
|
|||
fmt.Println("failed to spawn stub:", err)
|
||||
} else {
|
||||
ev.Stub = stub
|
||||
go func() {
|
||||
<-stub.State()
|
||||
fmt.Println("stub has died")
|
||||
}()
|
||||
}
|
||||
|
||||
if len(args) == 1 {
|
||||
|
|
10
stub/stub.go
10
stub/stub.go
|
@ -114,6 +114,16 @@ func (stub *Stub) State() <-chan struct{} {
|
|||
return stub.statech
|
||||
}
|
||||
|
||||
// Alive reports whether the stub is alive.
|
||||
func (stub *Stub) Alive() bool {
|
||||
select {
|
||||
case <-stub.statech:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// relaySignals relays output of the stub to sigch, assuming that outputs
|
||||
// represent signal numbers.
|
||||
func relaySignals(reader io.Reader, sigch chan<- os.Signal) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user