update for runningcmdtype to be a pointer in the map (for updates)

This commit is contained in:
sawka 2024-03-12 15:43:08 -07:00
parent 42656ecd71
commit fde141fce3

View File

@ -160,17 +160,19 @@ type MShellProc struct {
InstallCancelFn context.CancelFunc InstallCancelFn context.CancelFunc
InstallErr error InstallErr error
RunningCmds map[base.CommandKey]RunCmdType RunningCmds map[base.CommandKey]*RunCmdType
PendingStateCmds map[pendingStateKey]base.CommandKey // key=[remoteinstance name] PendingStateCmds map[pendingStateKey]base.CommandKey // key=[remoteinstance name]
launcher Launcher // for conditional launch method based on ssh library in use. remove once ssh library is stabilized launcher Launcher // for conditional launch method based on ssh library in use. remove once ssh library is stabilized
Client *ssh.Client Client *ssh.Client
} }
type RunCmdType struct { type RunCmdType struct {
CK base.CommandKey
SessionId string SessionId string
ScreenId string ScreenId string
RemotePtr sstore.RemotePtrType RemotePtr sstore.RemotePtrType
RunPacket *packet.RunPacketType RunPacket *packet.RunPacketType
Ephemeral bool
} }
type RemoteRuntimeState = sstore.RemoteRuntimeState type RemoteRuntimeState = sstore.RemoteRuntimeState
@ -704,7 +706,7 @@ func MakeMShell(r *sstore.RemoteType) *MShellProc {
Status: StatusDisconnected, Status: StatusDisconnected,
PtyBuffer: buf, PtyBuffer: buf,
InstallStatus: StatusDisconnected, InstallStatus: StatusDisconnected,
RunningCmds: make(map[base.CommandKey]RunCmdType), RunningCmds: make(map[base.CommandKey]*RunCmdType),
PendingStateCmds: make(map[pendingStateKey]base.CommandKey), PendingStateCmds: make(map[pendingStateKey]base.CommandKey),
StateMap: server.MakeShellStateMap(), StateMap: server.MakeShellStateMap(),
launcher: LegacyLauncher{}, // for conditional launch method based on ssh library in use. remove once ssh library is stabilized launcher: LegacyLauncher{}, // for conditional launch method based on ssh library in use. remove once ssh library is stabilized
@ -1986,6 +1988,10 @@ type RunCommandOpts struct {
// set to true to skip creating the pty file (for restarted commands) // set to true to skip creating the pty file (for restarted commands)
NoCreateCmdPtyFile bool NoCreateCmdPtyFile bool
// this command will not go into the DB, and will not have a ptyout file created
// forces special packet handling (sets RunCommandType.Ephemeral)
Ephemeral bool
} }
// returns (CmdType, allow-updates-callback, err) // returns (CmdType, allow-updates-callback, err)
@ -2128,17 +2134,19 @@ func RunCommand(ctx context.Context, rcOpts RunCommandOpts, runPacket *packet.Ru
return nil, nil, fmt.Errorf("cannot create local ptyout file for running command: %v", err) return nil, nil, fmt.Errorf("cannot create local ptyout file for running command: %v", err)
} }
} }
msh.AddRunningCmd(RunCmdType{ msh.AddRunningCmd(&RunCmdType{
CK: runPacket.CK,
SessionId: sessionId, SessionId: sessionId,
ScreenId: screenId, ScreenId: screenId,
RemotePtr: remotePtr, RemotePtr: remotePtr,
RunPacket: runPacket, RunPacket: runPacket,
Ephemeral: true,
}) })
return cmd, func() { removeCmdWait(runPacket.CK) }, nil return cmd, func() { removeCmdWait(runPacket.CK) }, nil
} }
func (msh *MShellProc) AddRunningCmd(rct RunCmdType) { func (msh *MShellProc) AddRunningCmd(rct *RunCmdType) {
msh.Lock.Lock() msh.Lock.Lock()
defer msh.Lock.Unlock() defer msh.Lock.Unlock()
msh.RunningCmds[rct.RunPacket.CK] = rct msh.RunningCmds[rct.RunPacket.CK] = rct
@ -2147,11 +2155,7 @@ func (msh *MShellProc) AddRunningCmd(rct RunCmdType) {
func (msh *MShellProc) GetRunningCmd(ck base.CommandKey) *RunCmdType { func (msh *MShellProc) GetRunningCmd(ck base.CommandKey) *RunCmdType {
msh.Lock.Lock() msh.Lock.Lock()
defer msh.Lock.Unlock() defer msh.Lock.Unlock()
rct, found := msh.RunningCmds[ck] return msh.RunningCmds[ck]
if !found {
return nil
}
return &rct
} }
func (msh *MShellProc) RemoveRunningCmd(ck base.CommandKey) { func (msh *MShellProc) RemoveRunningCmd(ck base.CommandKey) {
@ -2241,7 +2245,7 @@ func (msh *MShellProc) notifyHangups_nolock() {
scbus.MainUpdateBus.DoScreenUpdate(ck.GetGroupId(), update) scbus.MainUpdateBus.DoScreenUpdate(ck.GetGroupId(), update)
go pushNumRunningCmdsUpdate(&ck, -1) go pushNumRunningCmdsUpdate(&ck, -1)
} }
msh.RunningCmds = make(map[base.CommandKey]RunCmdType) msh.RunningCmds = make(map[base.CommandKey]*RunCmdType)
msh.PendingStateCmds = make(map[pendingStateKey]base.CommandKey) msh.PendingStateCmds = make(map[pendingStateKey]base.CommandKey)
} }