mirror of
https://github.com/j3ssie/osmedeus.git
synced 2026-09-26 11:34:55 +02:00
- Track tmux sessions in ActiveRun and kill them on run cancel via new TmuxHooks indirection; expose killed_tmux_sessions in CLI and API responses - Add ExecuteSSHCommand with remote pidfile + process-group kill watcher so cancelling a run actually terminates remote scans (not just the local session) - Route ssh_exec/ssh_rsync/sync_* through the run's cancellable context via new RunContextHooks - Switch docker-publish to sequential per-arch buildx builds + imagetools manifest to avoid OOM on multi-arch builds; add docker-buildx-setup target - Cross-compile Dockerfile via BUILDPLATFORM/TARGETOS/TARGETARCH and retry SAST binary installs to survive QEMU-flaky downloads - Bump version to v5.0.3
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package functions
|
|
|
|
import "sync"
|
|
|
|
// TmuxHooks provides callbacks for tracking tmux sessions created via
|
|
// tmux_run/tmux_kill against an active run. This indirection mirrors
|
|
// ExecuteHooks and avoids an import cycle between functions and executor.
|
|
type TmuxHooks struct {
|
|
// OnSessionCreated fires after tmux_run successfully creates a session.
|
|
// runUUID will be empty when invoked outside a tracked run (e.g. ad-hoc
|
|
// `osmedeus func e`); implementations must tolerate that.
|
|
OnSessionCreated func(runUUID, sessionName string)
|
|
|
|
// OnSessionDestroyed fires after tmux_kill successfully destroys a session,
|
|
// so the tracker can drop it before run cancellation tries to kill it again.
|
|
OnSessionDestroyed func(runUUID, sessionName string)
|
|
}
|
|
|
|
var (
|
|
tmuxHooks *TmuxHooks
|
|
tmuxHookMu sync.RWMutex
|
|
)
|
|
|
|
// RegisterTmuxHooks installs callbacks for tmux session lifecycle events.
|
|
// Called by the executor package at init.
|
|
func RegisterTmuxHooks(hooks *TmuxHooks) {
|
|
tmuxHookMu.Lock()
|
|
defer tmuxHookMu.Unlock()
|
|
tmuxHooks = hooks
|
|
}
|
|
|
|
// UnregisterTmuxHooks clears the registered tmux hooks (used in tests).
|
|
func UnregisterTmuxHooks() {
|
|
tmuxHookMu.Lock()
|
|
defer tmuxHookMu.Unlock()
|
|
tmuxHooks = nil
|
|
}
|
|
|
|
func notifyTmuxSessionCreated(runUUID, sessionName string) {
|
|
tmuxHookMu.RLock()
|
|
h := tmuxHooks
|
|
tmuxHookMu.RUnlock()
|
|
if h != nil && h.OnSessionCreated != nil {
|
|
h.OnSessionCreated(runUUID, sessionName)
|
|
}
|
|
}
|
|
|
|
func notifyTmuxSessionDestroyed(runUUID, sessionName string) {
|
|
tmuxHookMu.RLock()
|
|
h := tmuxHooks
|
|
tmuxHookMu.RUnlock()
|
|
if h != nil && h.OnSessionDestroyed != nil {
|
|
h.OnSessionDestroyed(runUUID, sessionName)
|
|
}
|
|
}
|