mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
more elaborate signal handling
This commit is contained in:
parent
946fa29e9a
commit
2823ffb540
|
@ -4,6 +4,7 @@ package edit
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
|
@ -57,7 +58,7 @@ type Editor struct {
|
|||
file *os.File
|
||||
writer *writer
|
||||
reader *Reader
|
||||
sigs <-chan os.Signal
|
||||
sigs chan os.Signal
|
||||
histories []string
|
||||
store *store.Store
|
||||
evaler *eval.Evaler
|
||||
|
@ -151,7 +152,7 @@ func (ed *Editor) nextHistory() bool {
|
|||
}
|
||||
|
||||
// NewEditor creates an Editor.
|
||||
func NewEditor(file *os.File, sigs <-chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
|
||||
func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
|
||||
seq := -1
|
||||
if st != nil {
|
||||
var err error
|
||||
|
@ -350,6 +351,22 @@ MainLoop:
|
|||
goto MainLoop
|
||||
case syscall.SIGWINCH:
|
||||
continue MainLoop
|
||||
case syscall.SIGQUIT:
|
||||
// Emulate default behavior
|
||||
sys.DumpStack()
|
||||
os.Exit(1)
|
||||
default:
|
||||
// Other signals: turn off signal catching, and resend
|
||||
signal.Stop(ed.sigs)
|
||||
p, err := os.FindProcess(os.Getpid())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = p.Signal(sig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
signal.Notify(ed.sigs)
|
||||
}
|
||||
case or := <-ones:
|
||||
// Alert about error
|
||||
|
|
8
main.go
8
main.go
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/elves/elvish/edit"
|
||||
|
@ -16,6 +15,7 @@ import (
|
|||
"github.com/elves/elvish/osutil"
|
||||
"github.com/elves/elvish/parse"
|
||||
"github.com/elves/elvish/store"
|
||||
"github.com/elves/elvish/sys"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -132,11 +132,7 @@ var usage = `Usage:
|
|||
func rescue() {
|
||||
r := recover()
|
||||
if r != nil {
|
||||
buf := make([]byte, 1024)
|
||||
for runtime.Stack(buf, true) == cap(buf) {
|
||||
buf = make([]byte, cap(buf)*2)
|
||||
}
|
||||
print(string(buf))
|
||||
sys.DumpStack()
|
||||
println("execing recovery shell /bin/sh")
|
||||
syscall.Exec("/bin/sh", []string{}, os.Environ())
|
||||
}
|
||||
|
|
11
sys/trace.go
Normal file
11
sys/trace.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package sys
|
||||
|
||||
import "runtime"
|
||||
|
||||
func DumpStack() {
|
||||
buf := make([]byte, 1024)
|
||||
for runtime.Stack(buf, true) == cap(buf) {
|
||||
buf = make([]byte, cap(buf)*2)
|
||||
}
|
||||
print(string(buf))
|
||||
}
|
Loading…
Reference in New Issue
Block a user