Compare commits

...

2 Commits

Author SHA1 Message Date
e452de8806 Fix check shell before executing
Some checks failed
Push / CI (push) Has been cancelled
2025-07-12 18:03:48 -07:00
88cba45310 Check shell before executing
Some checks failed
Push / CI (push) Has been cancelled
2025-07-12 16:59:32 -07:00

15
ssh.go
View File

@ -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"