Skip to content
Myr

Fix reader regression (#4070)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 19495eb · Browse files · 1 file+7 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−6 removed

  • other:+7 added−6 removed

1 file+7 added−6 removed

modified:src/reader.go+7 added-6 removed
22 unmodified lines
23 delimNil bool24 event int3225 finChan chan bool26 mutex sync.Mutex27 killed bool28 termFunc func()29 command *string30 wait bool31}
7 unmodified lines
39 delimNil,40 int32(EvtReady),41 make(chan bool, 1),42 sync.Mutex{},43 false,44 func() { os.Stdin.Close() },45 nil,46 wait}47}
21 unmodified lines
69 }70 }()71}7271func (r *Reader) wasKilled() bool {72 return r.termFunc == nil73}7473func (r *Reader) fin(success bool) {74 atomic.StoreInt32(&r.event, int32(EvtReadFin))75 if r.wait {76 <-r.finChan77 }7879 r.mutex.Lock()80 ret := r.command83 if success || r.wasKilled() {81 if success || r.killed {82 ret = nil83 }84 r.mutex.Unlock()85
1 unmodified line
87}8889func (r *Reader) terminate() {90 r.mutex.Lock()91 r.killed = true92 if r.termFunc != nil {93 r.termFunc()94 r.termFunc = nil95 }
199 unmodified lines
295 }296 }297 r.mutex.Lock()298 defer r.mutex.Unlock()300 if r.wasKilled() {299 if r.killed {300 return context.Canceled301 }302 return nil303 }
2 unmodified lines
306307func (r *Reader) readFromCommand(command string, environ []string, signalReady func()) bool {308 r.mutex.Lock()309310 r.killed = false311 r.termFunc = nil312 r.command = &command313 exec := r.executor.ExecCommand(command, true)314 if environ != nil {315 exec.Env = environ316 }317 execOut, err := exec.StdoutPipe()318 if err != nil || exec.Start() != nil {319 signalReady()320 r.mutex.Unlock()321 return false322 }323
12 unmodified lines