Skip to content
This repository was archived by the owner on Sep 29, 2018. It is now read-only.

Commit c3c34c8

Browse files
committed
Fix Restart
1 parent 66a71f0 commit c3c34c8

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

attach.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func attach(socket string, prompt *fasttemplate.Template) {
6161
cache--
6262
}
6363
}
64+
rl.Close()
6465
}()
6566
go func() {
6667
for {

daemon.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func runDaemon(base, datapath, logfile, socket string) {
8080
publishes <- text
8181
}
8282
for func() bool {
83-
proc := make(chan struct{}, 1)
83+
proc := make(chan bool, 1)
8484
f, quit := runImpl(base, datapath, proc)
8585
defer f.Close()
8686
defer quit()
@@ -115,8 +115,8 @@ func runDaemon(base, datapath, logfile, socket string) {
115115
return x
116116
case <-sigs:
117117
return false
118-
case <-proc:
119-
return true
118+
case x := <-proc:
119+
return x
120120
case line, ok := <-exec:
121121
if ok {
122122
cache++

run.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func packOutput(input io.Reader, output func(string)) {
5757
}
5858
}
5959

60-
func runImpl(base string, datapath string, done chan struct{}) (*os.File, func()) {
60+
func runImpl(base string, datapath string, done chan bool) (*os.File, func()) {
6161
abs, err := filepath.Abs(base)
6262
if err != nil {
6363
panic(err)
@@ -69,13 +69,17 @@ func runImpl(base string, datapath string, done chan struct{}) (*os.File, func()
6969
if err != nil {
7070
panic(err)
7171
}
72+
status := true
73+
selfLock := make(chan struct{}, 1)
7274
go func() {
7375
cmd.Wait()
74-
done <- struct{}{}
76+
selfLock <- struct{}{}
77+
done <- status
7578
}()
7679
return f, func() {
80+
status = false
7781
cmd.Process.Signal(os.Interrupt)
78-
cmd.Wait()
82+
<-selfLock
7983
}
8084
}
8185

@@ -86,7 +90,7 @@ func run(base, datapath, logfile string, prompt *fasttemplate.Template) bool {
8690
return false
8791
}
8892
defer log.Close()
89-
proc := make(chan struct{}, 1)
93+
proc := make(chan bool, 1)
9094
f, stop := runImpl(base, datapath, proc)
9195
defer f.Close()
9296
defer stop()
@@ -149,38 +153,29 @@ func run(base, datapath, logfile string, prompt *fasttemplate.Template) bool {
149153
}
150154
}
151155
})
152-
rlock := make(chan struct{}, 1)
153-
go func() {
154-
for {
155-
line, err := rl.Readline()
156-
if err == readline.ErrInterrupt {
157-
if len(line) == 0 {
158-
break
159-
} else {
160-
continue
161-
}
162-
} else if err == io.EOF {
156+
for {
157+
line, err := rl.Readline()
158+
if err == readline.ErrInterrupt {
159+
if len(line) == 0 {
163160
break
161+
} else {
162+
continue
164163
}
165-
line = strings.TrimSpace(line)
166-
switch {
167-
case strings.HasPrefix(line, ":restart"):
168-
status = true
169-
fallthrough
170-
case strings.HasPrefix(line, ":quit"):
171-
rlock <- struct{}{}
172-
return
173-
default:
174-
cache++
175-
execFn("console", line)
176-
}
164+
} else if err == io.EOF {
165+
break
166+
}
167+
line = strings.TrimSpace(line)
168+
switch {
169+
case strings.HasPrefix(line, ":restart"):
170+
return true
171+
case strings.HasPrefix(line, ":quit"):
172+
return status
173+
default:
174+
cache++
175+
execFn("console", line)
177176
}
178-
}()
179-
select {
180-
case <-proc:
181-
case <-rlock:
182177
}
183-
return status
178+
return false
184179
}
185180

186181
func prepare(data, link string) {

0 commit comments

Comments
 (0)