mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
install a global panic handler that exec's /bin/sh
This commit is contained in:
parent
f3b701b76e
commit
0b19995a02
17
main.go
17
main.go
|
@ -7,6 +7,8 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/elves/elvish/edit"
|
||||
"github.com/elves/elvish/errutil"
|
||||
|
@ -128,7 +130,22 @@ var usage = `Usage:
|
|||
elvish <script>
|
||||
`
|
||||
|
||||
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))
|
||||
println("execing recovery shell /bin/sh")
|
||||
syscall.Exec("/bin/sh", []string{}, os.Environ())
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer rescue()
|
||||
|
||||
switch len(os.Args) {
|
||||
case 1:
|
||||
interact()
|
||||
|
|
Loading…
Reference in New Issue
Block a user