(logCtx context.Context, bdata *waveobj.Block, blockMeta map[string]any, rtOpts *waveobj.RuntimeOpts, force bool)
| 257 | } |
| 258 | |
| 259 | func (sc *ShellController) run(logCtx context.Context, bdata *waveobj.Block, blockMeta map[string]any, rtOpts *waveobj.RuntimeOpts, force bool) { |
| 260 | blocklogger.Debugf(logCtx, "[conndebug] ShellController.run() %q\n", sc.BlockId) |
| 261 | runningShellCommand := false |
| 262 | ok := sc.LockRunLock() |
| 263 | if !ok { |
| 264 | log.Printf("block %q is already executing run()\n", sc.BlockId) |
| 265 | return |
| 266 | } |
| 267 | defer func() { |
| 268 | if !runningShellCommand { |
| 269 | sc.UnlockRunLock() |
| 270 | } |
| 271 | }() |
| 272 | curStatus := sc.GetRuntimeStatus() |
| 273 | controllerName := bdata.Meta.GetString(waveobj.MetaKey_Controller, "") |
| 274 | if controllerName != BlockController_Shell && controllerName != BlockController_Cmd { |
| 275 | log.Printf("unknown controller %q\n", controllerName) |
| 276 | return |
| 277 | } |
| 278 | runOnce := getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdRunOnce, false) |
| 279 | runOnStart := getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdRunOnStart, true) |
| 280 | if ((runOnStart || runOnce) && curStatus.ShellProcStatus == Status_Init) || force { |
| 281 | if getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdClearOnStart, false) { |
| 282 | err := HandleTruncateBlockFile(sc.BlockId) |
| 283 | if err != nil { |
| 284 | log.Printf("error truncating term blockfile: %v\n", err) |
| 285 | } |
| 286 | } |
| 287 | if runOnce { |
| 288 | ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) |
| 289 | defer cancelFn() |
| 290 | metaUpdate := map[string]any{ |
| 291 | waveobj.MetaKey_CmdRunOnce: false, |
| 292 | waveobj.MetaKey_CmdRunOnStart: false, |
| 293 | } |
| 294 | err := wstore.UpdateObjectMeta(ctx, waveobj.MakeORef(waveobj.OType_Block, sc.BlockId), metaUpdate, false) |
| 295 | if err != nil { |
| 296 | log.Printf("error updating block meta (in blockcontroller.run): %v\n", err) |
| 297 | return |
| 298 | } |
| 299 | } |
| 300 | runningShellCommand = true |
| 301 | go func() { |
| 302 | defer func() { |
| 303 | panichandler.PanicHandler("blockcontroller:run-shell-command", recover()) |
| 304 | }() |
| 305 | defer sc.UnlockRunLock() |
| 306 | var termSize waveobj.TermSize |
| 307 | if rtOpts != nil { |
| 308 | termSize = rtOpts.TermSize |
| 309 | } else { |
| 310 | termSize = getTermSize(bdata) |
| 311 | } |
| 312 | err := sc.DoRunShellCommand(logCtx, &RunShellOpts{TermSize: termSize}, bdata.Meta) |
| 313 | if err != nil { |
| 314 | debugLog(logCtx, "error running shell: %v\n", err) |
| 315 | } |
| 316 | }() |
no test coverage detected