Compare commits
2 Commits
67b8cd2449
...
main
Author | SHA1 | Date | |
---|---|---|---|
e452de8806 | |||
88cba45310 |
15
ssh.go
15
ssh.go
@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gokrazy/gokrazy"
|
||||
@ -220,6 +221,14 @@ type exitStatus struct {
|
||||
Status uint32
|
||||
}
|
||||
|
||||
func shellWorks(shell string) bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, shell, "-c", "exit 58")
|
||||
cmd.Run()
|
||||
return cmd.ProcessState != nil && cmd.ProcessState.ExitCode() == 58
|
||||
}
|
||||
|
||||
func findShell() string {
|
||||
if _, err := os.Stat(wellKnownBusybox); err == nil {
|
||||
// Install busybox to /bin to provide the typical userspace utilities
|
||||
@ -229,13 +238,13 @@ func findShell() string {
|
||||
// fallthrough, we don't return /bin/sh as we read /etc/passwd
|
||||
}
|
||||
}
|
||||
if _, err := exec.LookPath(shell); path.IsAbs(shell) && err == nil {
|
||||
if _, err := exec.LookPath(shell); path.IsAbs(shell) && shellWorks(shell) && err == nil {
|
||||
return shell
|
||||
}
|
||||
if path, err := exec.LookPath("bash"); err == nil {
|
||||
if path, err := exec.LookPath("bash"); shellWorks(path) && err == nil {
|
||||
return path
|
||||
}
|
||||
if path, err := exec.LookPath("sh"); err == nil {
|
||||
if path, err := exec.LookPath("sh"); shellWorks(path) && err == nil {
|
||||
return path
|
||||
}
|
||||
const wellKnownSerialShell = "/tmp/serial-busybox/ash"
|
||||
|
Reference in New Issue
Block a user