SIGKILL will also kill waveshell. clear PendingStateCmds and WaitingCmds on disconnect (remote.go)

This commit is contained in:
sawka 2023-11-09 18:29:11 -08:00
parent f4ac642afa
commit d61c8c05a6
4 changed files with 16 additions and 3 deletions

View File

@ -84,7 +84,7 @@ CGO_ENABLED=1 go build -ldflags "-X main.BuildTime=$(date +'%Y%m%d%H%M')" -o ../
# @scripthaus command build-waveshell
cd waveshell
GO_LDFLAGS="-s -w -X main.BuildTime=$(date +'%Y%m%d%H%M')"
go build -ldflags="$GO_LDFLAGS" -o ../bin/mshell-v0.3-darwin.amd64 main-waveshell.go
go build -ldflags="$GO_LDFLAGS" -o ../bin/mshell/mshell-v0.3-darwin.amd64 main-waveshell.go
```
```bash

View File

@ -152,7 +152,6 @@ func (ckey CommandKey) Validate(typeStr string) error {
func HasDebugFlag(envMap map[string]string, flagName string) bool {
msDebug := envMap[MShellDebugVarName]
flags := strings.Split(msDebug, ",")
Logf("hasdebugflag[%s]: %s [%#v]\n", flagName, msDebug, flags)
for _, flag := range flags {
if strings.TrimSpace(flag) == flagName {
return true

View File

@ -47,6 +47,7 @@ const MaxMaxPtySize = 100 * 1024 * 1024
const MaxRunDataSize = 1024 * 1024
const MaxTotalRunDataSize = 10 * MaxRunDataSize
const ShellVarName = "SHELL"
const SigKillWaitTime = 2 * time.Second
const GetStateTimeout = 5 * time.Second
@ -1040,8 +1041,19 @@ trap _mshell_exittrap EXIT
}
func (s *ShExecType) SendSignal(sig syscall.Signal) {
base.Logf("signal start\n")
base.Logf("signal start %v\n", sig)
if sig == syscall.SIGKILL {
// SIGKILL is special, it also needs to kill waveshell if it's hanging
go func() {
wsPid := syscall.Getpid()
base.Logf("special sigkill handling waveshell-pid:%d\n", wsPid)
time.Sleep(SigKillWaitTime)
base.Logf("running self-sigkill %d\n", wsPid)
syscall.Kill(wsPid, syscall.SIGKILL)
}()
}
if s.Cmd == nil || s.Cmd.Process == nil || s.IsExited() {
base.Logf("signal, no cmd or exited (exited:%v)\n", s.IsExited())
return
}
pgroup := false

View File

@ -1673,6 +1673,8 @@ func (msh *MShellProc) notifyHangups_nolock() {
sstore.MainBus.SendScreenUpdate(ck.GetGroupId(), update)
}
msh.RunningCmds = make(map[base.CommandKey]RunCmdType)
msh.PendingStateCmds = make(map[pendingStateKey]base.CommandKey)
msh.WaitingCmds = nil
}
func (msh *MShellProc) handleCmdDonePacket(donePk *packet.CmdDonePacketType) {