From 871f9a200cbc5c1f259e22dfc663679556bab545 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Mon, 6 Nov 2023 23:17:13 -0800 Subject: [PATCH] Experimental dead conn process kill logic --- xsd/xsd.go | 3 +++ xsnet/net.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/xsd/xsd.go b/xsd/xsd.go index 6c270db..428d434 100755 --- a/xsd/xsd.go +++ b/xsd/xsd.go @@ -346,6 +346,9 @@ func runShellAs(who, hname, ttype, cmd string, interactive bool, //nolint:funlen defer func() { goutmp.Unput_utmp(utmpx) }() goutmp.Put_lastlog_entry("xs", who, pts, hname) + conn.Pproc = c.Process.Pid + //fmt.Printf("[process %d started]\n", c.Process.Pid) + log.Printf("[%s]\n", cmd) if err != nil { log.Printf("Command finished with error: %v", err) diff --git a/xsnet/net.go b/xsnet/net.go index 3ac54d7..103086d 100644 --- a/xsnet/net.go +++ b/xsnet/net.go @@ -39,6 +39,7 @@ import ( "net" "strings" "sync" + "syscall" "time" hkex "blitter.com/go/herradurakex" @@ -87,6 +88,7 @@ type ( Cols uint16 keepalive uint // if this reaches zero, conn is considered dead + Pproc int // proc ID of command run on this conn chaff ChaffConfig tuns *map[uint16](*TunEndpoint) @@ -1649,7 +1651,8 @@ func (hc *Conn) keepaliveHelper() { time.Sleep(time.Duration(nextDuration) * time.Millisecond) hc.keepalive -= 1 logger.LogDebug(fmt.Sprintf("[keepAlive is now %d]\n", hc.keepalive)) - //if rand.Intn(32) == 0 { + + //if rand.Intn(8) == 0 { // hc.keepalive = 0 //} @@ -1657,6 +1660,10 @@ func (hc *Conn) keepaliveHelper() { logger.LogDebug(fmt.Sprintf("*** keepaliveHelper shutting down\n")) hc.SetStatus(CSEConnDead) hc.ShutdownKeepAlive() + if hc.Pproc != 0 { + //fmt.Printf("[pid %d needs to be killed]\n", hc.Pproc) + syscall.Kill(hc.Pproc, syscall.SIGABRT) //nolint:errcheck + } break } }